Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] fix feature tooltip remains open when zoom level change hides layer #81373

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions x-pack/plugins/maps/public/actions/layer_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,13 @@ export function removeSelectedLayer() {
) => {
const state = getState();
const layerId = getSelectedLayerId(state);
dispatch(removeLayer(layerId));
if (layerId) {
dispatch(removeLayer(layerId));
}
};
}

export function removeLayer(layerId: string | null) {
export function removeLayer(layerId: string) {
return async (
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
getState: () => MapStoreState
Expand All @@ -398,7 +400,7 @@ export function removeLayer(layerId: string | null) {
};
}

function removeLayerFromLayerList(layerId: string | null) {
function removeLayerFromLayerList(layerId: string) {
return (
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
getState: () => MapStoreState
Expand All @@ -411,7 +413,7 @@ function removeLayerFromLayerList(layerId: string | null) {
layerGettingRemoved.getInFlightRequestTokens().forEach((requestToken) => {
dispatch(cancelRequest(requestToken));
});
dispatch(cleanTooltipStateForLayer(layerId!));
dispatch(cleanTooltipStateForLayer(layerId));
layerGettingRemoved.destroy();
dispatch({
type: REMOVE_LAYER,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/maps/public/actions/map_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ describe('map_actions', () => {
require('../selectors/map_selectors').getDataFilters = () => {
return {};
};

require('../selectors/map_selectors').getLayerList = () => {
return [];
};
});

it('should add newMapConstants to dispatch action mapState', async () => {
Expand Down
14 changes: 12 additions & 2 deletions x-pack/plugins/maps/public/actions/map_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getWaitingForMapReadyLayerListRaw,
getQuery,
getTimeFilters,
getLayerList,
} from '../selectors/map_selectors';
import {
CLEAR_GOTO,
Expand Down Expand Up @@ -56,6 +57,7 @@ import {
} from '../../common/descriptor_types';
import { INITIAL_LOCATION } from '../../common/constants';
import { scaleBounds } from '../../common/elasticsearch_util';
import { cleanTooltipStateForLayer } from './tooltip_actions';

export function setMapInitError(errorMessage: string) {
return {
Expand Down Expand Up @@ -128,8 +130,7 @@ export function mapExtentChanged(newMapConstants: { zoom: number; extent: MapExt
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
getState: () => MapStoreState
) => {
const state = getState();
const dataFilters = getDataFilters(state);
const dataFilters = getDataFilters(getState());
const { extent, zoom: newZoom } = newMapConstants;
const { buffer, zoom: currentZoom } = dataFilters;

Expand Down Expand Up @@ -164,6 +165,15 @@ export function mapExtentChanged(newMapConstants: { zoom: number; extent: MapExt
...newMapConstants,
},
});

if (currentZoom !== newZoom) {
getLayerList(getState()).map((layer) => {
if (!layer.showAtZoomLevel(newZoom)) {
dispatch(cleanTooltipStateForLayer(layer.getId()));
}
});
}

await dispatch(syncDataForAllLayers());
};
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/tooltip_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function openOnHoverTooltip(tooltipState: TooltipState) {
};
}

export function cleanTooltipStateForLayer(layerId: string | null, layerFeatures: Feature[] = []) {
export function cleanTooltipStateForLayer(layerId: string, layerFeatures: Feature[] = []) {
return (dispatch: Dispatch, getState: () => MapStoreState) => {
let featuresRemoved = false;
const openTooltips = getOpenTooltips(getState())
Expand Down