Skip to content

Commit

Permalink
Hide fishing protection widget if empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Oct 18, 2024
1 parent 5f1633c commit 339bfe4
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,25 @@ const FishingProtectionWidget: FCWithMessages<FishingProtectionWidgetProps> = ({
return parsedFishingProtectionLevelData?.filter(Boolean) ?? [];
}, [t, protectionLevelsData, metadata]);

const noData = !widgetChartData.length;
const loading = isFetchingProtectionLevelsData;
const noData = useMemo(() => {
if (!widgetChartData.length) {
return true;
}

const emptyValues = widgetChartData.every((d) => d.totalArea === Infinity);
if (emptyValues) {
return true;
}

return false;
}, [widgetChartData]);

return (
<Widget
title={t('level-of-fishing-protection')}
lastUpdated={protectionLevelsData[0]?.attributes?.updatedAt}
noData={noData}
loading={loading}
loading={isFetchingProtectionLevelsData}
>
{widgetChartData.map((chartData) => (
<HorizontalBarChart
Expand Down

0 comments on commit 339bfe4

Please sign in to comment.