From b679ebf76af889609f5ed67c673457dcbfdd8c51 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 27 Nov 2023 12:46:58 -0700 Subject: [PATCH 1/4] [maps] fix tile errors displayed when layer is no longer using tiles --- .../tile_status_tracker/tile_error_cache.ts | 9 ++++ .../tile_status_tracker.test.tsx | 47 +++++++++++++++++++ .../tile_status_tracker.tsx | 12 +++++ 3 files changed, 68 insertions(+) diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_error_cache.ts b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_error_cache.ts index 9d54457056f77..213f883762312 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_error_cache.ts +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_error_cache.ts @@ -18,6 +18,15 @@ export function getErrorCacheTileKey(canonical: { x: number; y: number; z: numbe export class TileErrorCache { private _cache: Record> = {}; + public clearLayer(layerId: string, onClear: () => void) { + if (!(layerId in this._cache)) { + return; + } + + delete this._cache[layerId]; + onClear(); + } + public clearTileError(layerId: string | undefined, tileKey: string, onClear: () => void) { if (!layerId || !(layerId in this._cache)) { return; diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx index 546001cc23b3b..8bfe29203c9e1 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx @@ -249,6 +249,53 @@ describe('TileStatusTracker', () => { expect(tileErrorsMap.get('layer2')).toBeUndefined(); }); + test('should clear layer tile errors when layer is not tiled', async () => { + const mockMbMap = new MockMbMap(); + const layer1 = createMockLayer('layer1', 'layer1Source'); + + const wrapper = mount( + + ); + + mockMbMap.emit( + 'sourcedataloading', + createSourceDataEvent('layer1Source', IN_VIEW_CANONICAL_TILE) + ); + mockMbMap.emit('error', { + ...createSourceDataEvent('layer1Source', IN_VIEW_CANONICAL_TILE), + error: { + message: 'simulated error', + }, + }); + + // simulate delay. Cache-checking is debounced. + await sleep(300); + + expect(tileErrorsMap.get('layer1')?.length).toBe(1); + + const geojsonLayer1 = createMockLayer('layer1', 'layer1Source'); + geojsonLayer1.getSource = () => { + return { + isESSource() { + return true; + }, + isMvt() { + return false; + } + }; + } + wrapper.setProps({ layerList: [geojsonLayer1] }); + + // simulate delay. Cache-checking is debounced. + await sleep(300); + + expect(tileErrorsMap.get('layer1')).toBeUndefined(); + }); + test('should only return tile errors within map zoom', async () => { const mockMbMap = new MockMbMap(); diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx index ccb1ca6d06c5d..1828a42f36d50 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx @@ -62,6 +62,18 @@ export class TileStatusTracker extends Component { this.props.mbMap.on('moveend', this._onMoveEnd); } + componentDidUpdate() { + this.props.layerList.forEach(layer => { + const source = layer.getSource(); + if (source.isESSource() && + typeof (source as IVectorSource).isMvt === 'function' && + !(source as IVectorSource).isMvt()) { + // clear tile cache when layer is not tiled + this._tileErrorCache.clearLayer(layer.getId(), this._updateTileStatusForAllLayers); + } + }); + } + componentWillUnmount() { this._isMounted = false; this.props.mbMap.off('error', this._onError); From 017ca91fbf4c579e88531ecb29cff1b170be2fa0 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 27 Nov 2023 21:00:30 +0000 Subject: [PATCH 2/4] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../tile_status_tracker/tile_status_tracker.test.tsx | 6 +++--- .../mb_map/tile_status_tracker/tile_status_tracker.tsx | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx index 8bfe29203c9e1..0d603d2480c17 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx @@ -276,7 +276,7 @@ describe('TileStatusTracker', () => { await sleep(300); expect(tileErrorsMap.get('layer1')?.length).toBe(1); - + const geojsonLayer1 = createMockLayer('layer1', 'layer1Source'); geojsonLayer1.getSource = () => { return { @@ -285,9 +285,9 @@ describe('TileStatusTracker', () => { }, isMvt() { return false; - } + }, }; - } + }; wrapper.setProps({ layerList: [geojsonLayer1] }); // simulate delay. Cache-checking is debounced. diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx index 1828a42f36d50..beb1a1cd4409c 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx @@ -63,11 +63,13 @@ export class TileStatusTracker extends Component { } componentDidUpdate() { - this.props.layerList.forEach(layer => { + this.props.layerList.forEach((layer) => { const source = layer.getSource(); - if (source.isESSource() && + if ( + source.isESSource() && typeof (source as IVectorSource).isMvt === 'function' && - !(source as IVectorSource).isMvt()) { + !(source as IVectorSource).isMvt() + ) { // clear tile cache when layer is not tiled this._tileErrorCache.clearLayer(layer.getId(), this._updateTileStatusForAllLayers); } From c57d0b5b0648f6a4419581405eb598e3f5f95bcb Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 27 Nov 2023 14:50:14 -0700 Subject: [PATCH 3/4] tslint --- .../mb_map/tile_status_tracker/tile_status_tracker.test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx index 0d603d2480c17..c8d6395c743ba 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.test.tsx @@ -12,6 +12,7 @@ import type { Map as MbMap, MapSourceDataEvent } from '@kbn/mapbox-gl'; import type { TileError, TileMetaFeature } from '../../../../common/descriptor_types'; import { TileStatusTracker } from './tile_status_tracker'; import { ILayer } from '../../../classes/layers/layer'; +import type { IVectorSource } from '../../../classes/sources/vector_source'; class MockMbMap { public listeners: Array<{ type: string; callback: (e: unknown) => void }> = []; @@ -286,7 +287,7 @@ describe('TileStatusTracker', () => { isMvt() { return false; }, - }; + } as unknown as IVectorSource; }; wrapper.setProps({ layerList: [geojsonLayer1] }); From 3e37e92f2cbce612c14683223a37fd06c529ee38 Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 28 Nov 2023 08:00:55 -0700 Subject: [PATCH 4/4] add check for isLayerGroup --- .../mb_map/tile_status_tracker/tile_status_tracker.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx index beb1a1cd4409c..972e691f6695e 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx +++ b/x-pack/plugins/maps/public/connected_components/mb_map/tile_status_tracker/tile_status_tracker.tsx @@ -12,6 +12,7 @@ import type { AJAXError, Map as MbMap, MapSourceDataEvent } from '@kbn/mapbox-gl import type { TileError, TileMetaFeature } from '../../../../common/descriptor_types'; import { SPATIAL_FILTERS_LAYER_ID } from '../../../../common/constants'; import { ILayer } from '../../../classes/layers/layer'; +import { isLayerGroup } from '../../../classes/layers/layer_group'; import { IVectorSource } from '../../../classes/sources/vector_source'; import { getTileKey as getCenterTileKey } from '../../../classes/util/geo_tile_utils'; import { boundsToExtent } from '../../../classes/util/maplibre_utils'; @@ -64,6 +65,10 @@ export class TileStatusTracker extends Component { componentDidUpdate() { this.props.layerList.forEach((layer) => { + if (isLayerGroup(layer)) { + return; + } + const source = layer.getSource(); if ( source.isESSource() &&