From 15035a8f7c7d49dbee93267ba16bb7ca3fbef53c Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Mon, 27 Nov 2023 18:16:52 -0300 Subject: [PATCH] feat(fao-sentence): validate if primary forest is null --- .../widgets/land-cover/fao-cover/selectors.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/components/widgets/land-cover/fao-cover/selectors.js b/components/widgets/land-cover/fao-cover/selectors.js index 0e5feb5a9d..0962949690 100644 --- a/components/widgets/land-cover/fao-cover/selectors.js +++ b/components/widgets/land-cover/fao-cover/selectors.js @@ -14,11 +14,15 @@ const getSettings = (state) => state.settings; export const parseData = createSelector( [getData, getColors], (data, colors) => { - if (isEmpty(data)) return null; + if (isEmpty(data)) { + return null; + } + const { area_ha, extent, planted_forest, forest_primary } = data; const otherCover = extent - (forest_primary + planted_forest); const nonForest = area_ha - extent; - return [ + + const chartItems = [ { label: 'Primary Forest', value: forest_primary || 0, @@ -44,6 +48,12 @@ export const parseData = createSelector( color: colors.nonForest, }, ]; + + if (forest_primary === null) { + return chartItems.slice(1, chartItems.length); + } + + return chartItems; } ); @@ -51,13 +61,16 @@ export const parseSentence = createSelector( [getData, getLocationName, getSentences, getSettings], (data, locationName, sentences, settings) => { if (isEmpty(data)) return null; + const { initial, noPrimary, globalInitial, globalNoPrimary } = sentences; - const { area_ha, extent, forest_primary, planted_forest } = data; + const { area_ha, extent, forest_primary } = data; const { faoYear } = settings; + const primaryPercent = forest_primary > 0 ? (forest_primary / extent) * 100 - : (planted_forest / extent) * 100; + : (extent / area_ha) * 100; + const percent = (extent / area_ha) * 100; const params = { location: locationName === 'global' ? 'globally' : locationName,