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

feat(widget): add constraints to alert widgets #4823

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions components/widget/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Widget extends PureComponent {
customComponent: PropTypes.string,
authenticated: PropTypes.bool,
chartDecorationConfig: PropTypes.object,
adm0: PropTypes.string,
};

state = {
Expand Down Expand Up @@ -139,6 +140,7 @@ class Widget extends PureComponent {
customComponent,
authenticated,
chartDecorationConfig,
adm0,
} = this.props;

const urlParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -242,6 +244,8 @@ class Widget extends PureComponent {
/>
{sentence && data && (
<WidgetFooter
adm0={adm0}
admLevel={adminLevel}
showAttributionLink={showAttributionLink}
statements={statements}
type={type}
Expand Down
23 changes: 20 additions & 3 deletions components/widget/components/widget-footer/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ class WidgetFooter extends PureComponent {
showAttributionLink: PropTypes.bool,
alertSystem: PropTypes.string,
decorationMessage: PropTypes.string,
admLevel: PropTypes.string,
adm0: PropTypes.string,
};

renderAlert = (alerts, alertSystem, type, locationType) => {
renderAlert = (alerts, alertSystem, type, locationType, admLevel, adm0) => {
if (!alerts) return null;

return alerts.map((alert, index) => {
if (alert.system === alertSystem || alertSystem === 'all') {
const validation = alert.hasConstraints
? (alert.system === alertSystem || alertSystem === 'all') &&
alert.constraints?.admins?.includes(admLevel) &&
alert.constraints?.countries?.includes(adm0)
: alert.system === alertSystem || alertSystem === 'all';

if (validation) {
return (
<WidgetAlert
key={`alert-${index}`}
Expand All @@ -45,6 +53,8 @@ class WidgetFooter extends PureComponent {
showAttributionLink,
alertSystem,
decorationMessage,
admLevel,
adm0,
} = this.props;

const statementsMapped = statements && statements.join(' | ');
Expand All @@ -59,7 +69,14 @@ class WidgetFooter extends PureComponent {
dangerouslySetInnerHTML={{ __html: decorationMessage }}
/>
)}
{this.renderAlert(alerts, alertSystem, type, locationType)}
{this.renderAlert(
alerts,
alertSystem,
type,
locationType,
admLevel,
adm0
)}
{statementsMapped && !!statementsMapped.length && (
<div className="notranslate">{ReactHtmlParser(statementsMapped)}</div>
)}
Expand Down
5 changes: 5 additions & 0 deletions components/widgets/forest-change/tree-loss-primary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export default {
{
text: 'The methods behind this data have changed over time. Be cautious comparing old and new data, especially before/after 2015. [Read more here](https://www.globalforestwatch.org/blog/data-and-research/tree-cover-loss-satellite-data-trend-analysis/).',
visible: ['global', 'country', 'geostore', 'aoi', 'wdpa', 'use'],
hasConstraints: true,
constraints: {
countries: ['MEX'],
admins: ['adm0'],
},
},
],
large: true,
Expand Down
Loading