From a5f06ce6da0daa3ebc391b94cc37e830ed8dca03 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Thu, 30 Nov 2023 14:58:55 -0300 Subject: [PATCH] fix(fao-deforestation): validate no FAO deforestation in countries --- components/widgets/forest-change/fao-deforest/index.js | 2 +- components/widgets/forest-change/fao-deforest/selectors.js | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/components/widgets/forest-change/fao-deforest/index.js b/components/widgets/forest-change/fao-deforest/index.js index 433bbcf9af..94e31cb813 100644 --- a/components/widgets/forest-change/fao-deforest/index.js +++ b/components/widgets/forest-change/fao-deforest/index.js @@ -36,7 +36,7 @@ export default { 'According to the FAO, the {location} rate of deforestation in between {startYearRange} and {endYearRange} was {rate} per year.', initial: 'According to the FAO, the rate of deforestation in {location} was {rate} per year between {startYearRange} and {endYearRange}.', - noDeforest: 'No deforestation data in {location}.', + noDeforest: 'No FAO deforestation data in {location}.', }, settings: { yearRange: '2015-2020', diff --git a/components/widgets/forest-change/fao-deforest/selectors.js b/components/widgets/forest-change/fao-deforest/selectors.js index 72f2d8491d..31d99ac819 100644 --- a/components/widgets/forest-change/fao-deforest/selectors.js +++ b/components/widgets/forest-change/fao-deforest/selectors.js @@ -58,15 +58,10 @@ export const parseSentence = createSelector( if (!data || !data.fao) return null; const { initial, noDeforest, globalInitial } = sentences; - const topFAOByDeforestation = data.fao.rows - ?.filter((regionData) => regionData.year === settings.yearRange) - .sort((a, b) => Number(b.deforest) - Number(a.deforest)); - const yearRangeSeparated = settings.yearRange.split('-'); const startYearRange = yearRangeSeparated[0]; const endYearRange = yearRangeSeparated[1]; - const { deforest } = topFAOByDeforestation[0] || {}; const globalDeforestation = sumBy(data.rank, 'def_per_year') || 0; const countryDeforestation = data.rank.filter( (country) => country.iso === adm0 @@ -83,7 +78,7 @@ export const parseSentence = createSelector( sentence = globalInitial; } - if (!deforest) { + if (currentLabel !== 'global' && !countryDeforestation) { sentence = noDeforest; }