From 981e90674e7f3032a637568b15f7dfb48e8bb0da Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Wed, 25 Oct 2023 16:46:57 -0500 Subject: [PATCH] fix: Added source checks --- .../components/LandscapeSharedDataVisualization.test.js | 5 +++++ src/sharedData/visualization/components/Visualization.js | 9 ++++++++- .../components/VisualizationConfigForm.test.js | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/landscape/components/LandscapeSharedDataVisualization.test.js b/src/landscape/components/LandscapeSharedDataVisualization.test.js index fd865f36f9..072d97526a 100644 --- a/src/landscape/components/LandscapeSharedDataVisualization.test.js +++ b/src/landscape/components/LandscapeSharedDataVisualization.test.js @@ -107,6 +107,11 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => { touchZoomRotate: { disableRotation: jest.fn() }, }; mapboxgl.Map.mockReturnValue(map); + map.getSource.mockReturnValueOnce(); + map.getSource.mockReturnValueOnce({ + setData: jest.fn(), + loaded: jest.fn().mockReturnValue(true), + }); useParams.mockReturnValue({ groupSlug: 'slug-1', configSlug: 'config-slug', diff --git a/src/sharedData/visualization/components/Visualization.js b/src/sharedData/visualization/components/Visualization.js index 58c1e06ff1..f30b9fda54 100644 --- a/src/sharedData/visualization/components/Visualization.js +++ b/src/sharedData/visualization/components/Visualization.js @@ -56,6 +56,10 @@ const getSourceBounds = async (map, sourceId) => { return new mapboxgl.LngLatBounds(loadedSource.bounds); } + if (!loadedSource._data) { + return; + } + const calculatedBbox = bbox(loadedSource._data); return new mapboxgl.LngLatBounds( [calculatedBbox[0], calculatedBbox[1]], @@ -203,7 +207,10 @@ const MapboxLayer = props => { if (!source) { return; } - const features = source._data.features; + const features = source?._data?.features; + if (_.isEmpty(features)) { + return; + } openPopup(features[0]); }, [ showPopup, diff --git a/src/sharedData/visualization/components/VisualizationConfigForm.test.js b/src/sharedData/visualization/components/VisualizationConfigForm.test.js index 73d02833e5..94000f32f8 100644 --- a/src/sharedData/visualization/components/VisualizationConfigForm.test.js +++ b/src/sharedData/visualization/components/VisualizationConfigForm.test.js @@ -157,6 +157,11 @@ const setup = async testParams => { dragRotate: { disable: jest.fn() }, touchZoomRotate: { disableRotation: jest.fn() }, }; + map.getSource.mockReturnValueOnce(); + map.getSource.mockReturnValue({ + setData: jest.fn(), + loaded: jest.fn().mockReturnValue(true), + }); mapboxgl.Map.mockReturnValue(map); mapboxgl.LngLat = jest.fn(); useParams.mockReturnValue({