Skip to content

Commit

Permalink
feat(fao-sentence): validate if primary forest is null
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Nov 27, 2023
1 parent 660d55b commit 15035a8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions components/widgets/land-cover/fao-cover/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,20 +48,29 @@ export const parseData = createSelector(
color: colors.nonForest,
},
];

if (forest_primary === null) {
return chartItems.slice(1, chartItems.length);
}

return chartItems;
}
);

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,
Expand Down

0 comments on commit 15035a8

Please sign in to comment.