Skip to content

Commit

Permalink
[Maps] fix feature tooltip remains open when zoom level change hides …
Browse files Browse the repository at this point in the history
…layer (elastic#81373)
  • Loading branch information
nreese committed Oct 22, 2020
1 parent 941af1c commit 7707466
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
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

0 comments on commit 7707466

Please sign in to comment.