Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy #4723

Merged
merged 6 commits into from
Nov 7, 2023
Merged

Deploy #4723

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading