Skip to content

Commit

Permalink
Hide conservation 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 696c5ec commit 5f1633c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,24 @@ const MarineConservationWidget: FCWithMessages<MarineConservationWidgetProps> =
return data;
}, [location, aggregatedData]);

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

const emptyValues = chartData.every((d) => d.percentage === 0);
if (emptyValues) {
return true;
}

return false;
}, [chartData]);

return (
<Widget
title={t('marine-conservation-coverage')}
lastUpdated={data[data.length - 1]?.attributes.updatedAt}
noData={!chartData.length}
noData={noData}
loading={isFetching}
info={metadata?.info}
sources={metadata?.sources}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,24 @@ const TerrestrialConservationWidget: FCWithMessages<TerrestrialConservationWidge
return data;
}, [location, aggregatedData]);

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

const emptyValues = chartData.every((d) => d.percentage === 0);
if (emptyValues) {
return true;
}

return false;
}, [chartData]);

return (
<Widget
title={t('terrestrial-conservation-coverage')}
lastUpdated={data[data.length - 1]?.attributes.updatedAt}
noData={!chartData.length}
noData={noData}
loading={isFetching}
info={metadata?.info}
sources={metadata?.sources}
Expand Down

0 comments on commit 5f1633c

Please sign in to comment.