Skip to content

Commit

Permalink
Merge pull request #1625 from Vizzuality/fix/subnational-commodities
Browse files Browse the repository at this point in the history
Fix/subnational commodities
  • Loading branch information
tomasmoose authored Nov 19, 2020
2 parents 896d4e2 + 05b7eb9 commit 199f461
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions frontend/scripts/react-components/explore/explore.selectors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSelector } from 'reselect';
import uniqBy from 'lodash/uniqBy';
import groupBy from 'lodash/groupBy';
import { EXPLORE_STEPS } from 'constants';
import translateLink from 'utils/translate-link';

Expand All @@ -21,14 +22,12 @@ export const getStep = createSelector(

export const getCommodities = createSelector([getContexts], contexts => {
if (!contexts) return null;
return uniqBy(
contexts.map(c => ({
name: c.commodityName,
id: c.commodityId,
isSubnational: !!c.subnationalYears
})),
'name'
);
const groupedContexts = groupBy(contexts, 'commodityName');
return Object.keys(groupedContexts).map(name => ({
name,
id: groupedContexts[name][0].commodityId,
isSubnational: groupedContexts[name].some(c => !!c.subnationalYears)
}));
});

const getAllCountries = createSelector([getContexts], contexts => {
Expand Down

0 comments on commit 199f461

Please sign in to comment.