From 86138f879be35737cf9140d01f02d633436e40fa Mon Sep 17 00:00:00 2001 From: Simao Rodrigues Date: Mon, 16 Sep 2024 12:50:39 +0100 Subject: [PATCH 1/5] Rename fishing widget title in the source strings --- .../panels/details/widgets/fishing-protection/index.tsx | 2 +- frontend/translations/en.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx index f2ce572c..8ed08f77 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx @@ -167,7 +167,7 @@ const FishingProtectionWidget: React.FC = ({ locat return ( Date: Mon, 16 Sep 2024 13:06:04 +0100 Subject: [PATCH 2/5] Prevent NaN display in the fishing widget when areas are 0 --- .../details/widgets/fishing-protection/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx index 8ed08f77..11197e1c 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx @@ -130,11 +130,17 @@ const FishingProtectionWidget: React.FC = ({ locat if (!protectionLevelsData.length) return []; const parsedProtectionLevel = (label: string, protectionLevel, stats) => { + const totalAreaPercentage = (stats?.area / stats?.pct) * 100; + + // There are circumstances in which pct is 0, which will cause the percentage calculation to be NaN. + // This is a safeguard so that if the data is unexpected, we don't display NaN on the screen. + if (isNaN(totalAreaPercentage)) return null; + return { title: label, slug: protectionLevel.slug, background: FISHING_PROTECTION_CHART_COLORS[protectionLevel.slug], - totalArea: (stats?.area / stats?.pct) * 100, + totalArea: totalAreaPercentage, protectedArea: stats?.area, info: metadata?.info, sources: metadata?.sources, @@ -158,11 +164,10 @@ const FishingProtectionWidget: React.FC = ({ locat return parsedProtectionLevel(t('highly-protected-from-fishing'), protectionLevel, data); }); - return parsedFishingProtectionLevelData ?? []; + return parsedFishingProtectionLevelData.filter(Boolean) ?? []; }, [t, protectionLevelsData, metadata]); const noData = !widgetChartData.length; - const loading = isFetchingProtectionLevelsData; return ( From 55b4bc2608097ed09508a4cbfff296a9a8136cb6 Mon Sep 17 00:00:00 2001 From: Simao Rodrigues Date: Mon, 16 Sep 2024 13:37:03 +0100 Subject: [PATCH 3/5] Remove info button next to the fishing widget title --- .../widgets/fishing-protection/index.tsx | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx index 11197e1c..bf1b6601 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx @@ -73,32 +73,6 @@ const FishingProtectionWidget: React.FC = ({ locat } ); - const { data: metadataWidget } = useGetDataInfos( - { - locale, - filters: { - slug: 'fishing-protection-widget', - }, - populate: 'data_sources', - }, - { - query: { - select: ({ data }) => - data[0] - ? { - info: data[0].attributes.content, - sources: data[0].attributes?.data_sources?.data?.map( - ({ attributes: { title, url } }) => ({ - title, - url, - }) - ), - } - : undefined, - }, - } - ); - const { data: metadata } = useGetDataInfos( { locale, @@ -176,8 +150,6 @@ const FishingProtectionWidget: React.FC = ({ locat lastUpdated={protectionLevelsData[0]?.attributes?.updatedAt} noData={noData} loading={loading} - info={metadataWidget?.info} - sources={metadataWidget?.sources} > {widgetChartData.map((chartData) => ( From e8ec71b65bf87964d6e9cab4372dddd7b1101877 Mon Sep 17 00:00:00 2001 From: Simao Rodrigues Date: Mon, 16 Sep 2024 13:37:29 +0100 Subject: [PATCH 4/5] Remove 30% target from the fishing widget's entries --- .../panels/details/widgets/fishing-protection/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx index bf1b6601..30bda488 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx @@ -152,7 +152,12 @@ const FishingProtectionWidget: React.FC = ({ locat loading={loading} > {widgetChartData.map((chartData) => ( - + ))} ); From 21a68fab8d64da67bad4f85aaccc50d7e8aafe7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Thu, 19 Sep 2024 11:25:23 +0200 Subject: [PATCH 5/5] Fix ABNJ crash --- .../panels/details/widgets/fishing-protection/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx index 30bda488..fc9cc76d 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/details/widgets/fishing-protection/index.tsx @@ -138,7 +138,7 @@ const FishingProtectionWidget: React.FC = ({ locat return parsedProtectionLevel(t('highly-protected-from-fishing'), protectionLevel, data); }); - return parsedFishingProtectionLevelData.filter(Boolean) ?? []; + return parsedFishingProtectionLevelData?.filter(Boolean) ?? []; }, [t, protectionLevelsData, metadata]); const noData = !widgetChartData.length;