Skip to content

Commit

Permalink
fix(fao-deforestation): validate no FAO deforestation in countries
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Nov 30, 2023
1 parent 668bc46 commit a5f06ce
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/widgets/forest-change/fao-deforest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 1 addition & 6 deletions components/widgets/forest-change/fao-deforest/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,7 +78,7 @@ export const parseSentence = createSelector(
sentence = globalInitial;
}

if (!deforest) {
if (currentLabel !== 'global' && !countryDeforestation) {
sentence = noDeforest;
}

Expand Down

0 comments on commit a5f06ce

Please sign in to comment.