Skip to content

Commit

Permalink
fix(deniedList): fix validation of deniedList to work just like allow…
Browse files Browse the repository at this point in the history
…edList
  • Loading branch information
willian-viana committed Oct 31, 2023
1 parent 5b6d337 commit 110962d
Showing 1 changed file with 22 additions and 19 deletions.
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

0 comments on commit 110962d

Please sign in to comment.