Skip to content

Commit

Permalink
Merge pull request #4719 from wri/chore/hide-european-countries-FLAG-934
Browse files Browse the repository at this point in the history
[FLAG-934] Conditionally hide 2 widgets for European countries
  • Loading branch information
willian-viana authored Nov 6, 2023
2 parents 99ce83c + bd30abc commit ddbc300
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
TREE_PLANTATIONS,
} from 'data/layers';

import { EuropeFAOCountries } from 'utils/fao-countries';

import getWidgetProps from './selectors';

export default {
Expand Down Expand Up @@ -76,6 +78,9 @@ export default {
regionWithIndicator:
'In {location} between 2000 and 2020, {gainPercent} of tree cover gain within {indicator} occurred outside of plantations.',
},
blacklists: {
adm0: EuropeFAOCountries,
},
settings: {
threshold: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
TREE_PLANTATIONS,
} from 'data/layers';

import { EuropeFAOCountries } from 'utils/fao-countries';

import getWidgetProps from './selectors';

const MIN_YEAR = 2013;
Expand Down Expand Up @@ -73,6 +75,9 @@ export default {
indicators: ['plantations'],
checkStatus: true,
},
blacklists: {
adm0: EuropeFAOCountries,
},
settings: {
threshold: 30,
startYear: MIN_YEAR,
Expand Down
41 changes: 22 additions & 19 deletions components/widgets/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ export const filterWidgetsByLocation = createSelector(
const {
types,
admins,
whitelists,
blacklists,
whitelists: allowedList,
blacklists: deniedList,
source,
datasets,
visible,
Expand Down Expand Up @@ -293,37 +293,40 @@ export const filterWidgetsByLocation = createSelector(
admins &&
admins.includes(adminLevel);

const adminWhitelist =
type === 'country' && whitelists && whitelists.adm0;
const adminAllowedList =
type === 'country' && allowedList && allowedList.adm0;

const adminBlacklist =
type === 'country' && blacklists && blacklists[adminLevel];
const notInBlacklist =
!adminBlacklist || !adminBlacklist.includes(adminLevel);
const matchesAllowedList =
!adminAllowedList || adminAllowedList.includes(location.adm0);

const adminDeniedList =
type === 'country' && deniedList && deniedList.adm0;

const notInDeniedList =
!adminDeniedList || !adminDeniedList?.includes(location.adm0);

const isFAOCountry =
source !== 'fao' || (fao && fao.find((f) => f.value === location.adm0));
const matchesAdminWhitelist =
!adminWhitelist || adminWhitelist.includes(location.adm0);

const polynameIntersection =
whitelists &&
whitelists.indicators &&
allowedList &&
allowedList.indicators &&
intersection(
polynameWhitelist?.[
w.whitelistType || w?.settings?.dataset || 'annual'
],
whitelists.indicators
allowedList.indicators
);
const matchesPolynameWhitelist =
type === 'global' ||
!whitelists ||
!whitelists.indicators ||
!allowedList ||
!allowedList.indicators ||
(polynameIntersection && polynameIntersection.length);
const isWidgetDataPending =
// for geostore shapes sometimes the data is not ready (no cached tables)
!whitelists ||
!allowedList ||
(status && status !== 'pending') ||
!whitelists.checkStatus;
!allowedList.checkStatus;

const isWidgetVisible =
(!showAnalysis && !visible) ||
Expand All @@ -341,11 +344,11 @@ export const filterWidgetsByLocation = createSelector(

return (
hasLocation &&
matchesAdminWhitelist &&
matchesAllowedList &&
matchesPolynameWhitelist &&
isFAOCountry &&
isWidgetVisible &&
notInBlacklist &&
notInDeniedList &&
isWidgetDataPending &&
published
);
Expand Down
54 changes: 54 additions & 0 deletions utils/fao-countries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const EuropeFAOCountries = [
'ALB',
'AND',
'AUT',
'BLR',
'BEL',
'BIH',
'BGR',
'HRV',
'CZE',
'DNK',
'EST',
'FRO',
'FIN',
'FRA',
'DEU',
'GIB',
'GRC',
'GGY',
'VAT',
'HUN',
'ISL',
'IRL',
'IMN',
'ITA',
'JEY',
'LVA',
'LIE',
'LTU',
'LUX',
'MLT',
'MCO',
'MNE',
'NLD',
'MKD',
'NOR',
'POL',
'PRT',
'MDA',
'ROU',
'RUS',
'SMR',
'SRB',
'SVK',
'SVN',
'ESP',
'SJM',
'SWE',
'CHE',
'UKR',
'GBR',
];

export default EuropeFAOCountries;

0 comments on commit ddbc300

Please sign in to comment.