From a788a3021370ef9eba29c0a3fde942b30e59d26d Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 17 Feb 2022 16:41:44 +0100 Subject: [PATCH] refactor: Make data loading state more obvious for maps --- app/charts/map/chart-map.tsx | 15 +++++++++++++-- app/charts/map/map.tsx | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/charts/map/chart-map.tsx b/app/charts/map/chart-map.tsx index bc533c2d1..fae4f2457 100644 --- a/app/charts/map/chart-map.tsx +++ b/app/charts/map/chart-map.tsx @@ -155,7 +155,18 @@ export const ChartMapVisualization = ({ } }, [areaLayer, dimensions, observations, symbolDimensionIri, geoCoordinates]); - if (measures && dimensions && observations) { + const areaLayerPrepared = + areaDimensionIri !== "" ? areaLayer !== undefined : true; + const symbolLayerPrepared = + symbolDimensionIri !== "" ? symbolLayer !== undefined : true; + + if ( + measures && + dimensions && + observations && + areaLayerPrepared && + symbolLayerPrepared + ) { return ( ); - } else if (fetching) { + } else if (fetching || !areaLayerPrepared || !symbolLayerPrepared) { return ; } else if (error) { return ; diff --git a/app/charts/map/map.tsx b/app/charts/map/map.tsx index 4b79bdc63..d692fe78a 100644 --- a/app/charts/map/map.tsx +++ b/app/charts/map/map.tsx @@ -192,6 +192,8 @@ export const MapComponent = () => { ); const baseLayerStyle = useMemo(() => getBaseLayerStyle({ locale }), [locale]); + const featuresLoaded = + features.areaLayer !== undefined || features.symbolLayer !== undefined; return ( @@ -208,9 +210,7 @@ export const MapComponent = () => { - {(areaLayer.data.length > 0 - ? shapes.features !== undefined - : features.symbolLayer?.points.length !== undefined) && ( + {featuresLoaded && (