From 9d33e4dbbf611f7ccb40ab8caa3b07fffbe00d62 Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Thu, 8 Oct 2020 11:23:34 +0300 Subject: [PATCH] Added PollutantIndex Block; Flags feature --- src/actions/index.js | 10 + .../manage/Blocks/ArticlesSparql/View.jsx | 6 +- .../manage/Blocks/ArticlesSparql/style.css | 6 + src/components/manage/Blocks/Flags/Edit.jsx | 23 + src/components/manage/Blocks/Flags/View.jsx | 60 ++ src/components/manage/Blocks/Flags/style.css | 3 + .../manage/Blocks/NavigationBlock/View.jsx | 25 + .../manage/Blocks/PollutantIndex/View.jsx | 772 ++++++++++++++++-- .../manage/Blocks/PollutantIndex/style.css | 21 +- .../manage/Blocks/SidebarBlock/View.jsx | 85 +- src/constants/ActionTypes.js | 1 + src/localconfig.js | 12 + src/reducers/flags.js | 36 + src/reducers/index.js | 2 + 14 files changed, 948 insertions(+), 114 deletions(-) create mode 100644 src/components/manage/Blocks/Flags/Edit.jsx create mode 100644 src/components/manage/Blocks/Flags/View.jsx create mode 100644 src/components/manage/Blocks/Flags/style.css create mode 100644 src/reducers/flags.js diff --git a/src/actions/index.js b/src/actions/index.js index 101af985..c9aea9f2 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -15,6 +15,7 @@ import { GET_PARENT_FOLDER_DATA, GET_PAGE, GET_SPARQL_DATA, + SET_FLAGS, } from '~/constants/ActionTypes'; export function setSectionTabs(payload) { @@ -55,3 +56,12 @@ export function getSparqlData(path) { }, }; } + +export function setFlags(packageKey, id, flags) { + return { + type: SET_FLAGS, + packageKey, + id, + flags, + }; +} diff --git a/src/components/manage/Blocks/ArticlesSparql/View.jsx b/src/components/manage/Blocks/ArticlesSparql/View.jsx index 49024005..2e35af0b 100644 --- a/src/components/manage/Blocks/ArticlesSparql/View.jsx +++ b/src/components/manage/Blocks/ArticlesSparql/View.jsx @@ -60,12 +60,12 @@ const View = (props) => { isVisible(index) ? (
-
+
{ )} />
-
+

{item.title}

diff --git a/src/components/manage/Blocks/ArticlesSparql/style.css b/src/components/manage/Blocks/ArticlesSparql/style.css index db03b713..d997b13f 100644 --- a/src/components/manage/Blocks/ArticlesSparql/style.css +++ b/src/components/manage/Blocks/ArticlesSparql/style.css @@ -97,6 +97,12 @@ } } +@media (max-width: 500px) { + .xs-height-fit-content { + height: fit-content !important; + } +} + @media (max-width: 768px) { .articles .articles-row.can-be-half:last-child { transform: translateY(-10%); diff --git a/src/components/manage/Blocks/Flags/Edit.jsx b/src/components/manage/Blocks/Flags/Edit.jsx new file mode 100644 index 00000000..7c6620c7 --- /dev/null +++ b/src/components/manage/Blocks/Flags/Edit.jsx @@ -0,0 +1,23 @@ +import React, { useState, useEffect } from 'react'; +import { connect } from 'react-redux'; +import { compose } from 'redux'; +import _uniqueId from 'lodash/uniqueId'; +import View from './View'; +import './style.css'; + +const Edit = (props) => { + const [state, setState] = useState({ + id: _uniqueId('block_'), + }); + return ( +
+ +
+ ); +}; + +export default compose( + connect((state, props) => ({ + pathname: state.router.location.pathname, + })), +)(Edit); diff --git a/src/components/manage/Blocks/Flags/View.jsx b/src/components/manage/Blocks/Flags/View.jsx new file mode 100644 index 00000000..6c426688 --- /dev/null +++ b/src/components/manage/Blocks/Flags/View.jsx @@ -0,0 +1,60 @@ +/* REACT */ +import React, { useState, useEffect } from 'react'; +import { compose } from 'redux'; +import { connect } from 'react-redux'; +import { setFlags } from '~/actions'; +import './style.css'; + +const View = (props) => { + const flags = props.flags; + const siteInspireId = props.discodata_query.search.siteInspireId; + const site = props.discodata_resources.data.sites_6?.[siteInspireId]; + const facilities = site?.results; + useEffect(() => { + if (site && siteInspireId && !flags.items.sites?.[siteInspireId]) { + const facilitiesFlags = {}; + props.setFlags('sites', siteInspireId, { + has_facilities: site.has_facilities, + has_fuel_data: site.has_fuel_data, + has_installations: site.has_installations, + has_lcps: site.has_lcps, + has_ophours_data: site.has_ophours_data, + has_release_data: site.has_release_data, + has_transfer_data: site.has_transfer_data, + has_waste_data: site.has_waste_data, + }); + facilities.forEach((facility) => { + if ( + facility && + !flags.items.facilities?.[facility.facilityInspireId] && + !facilitiesFlags[facility.facilityInspireId] + ) { + facilitiesFlags[facility.facilityInspireId] = { + has_fuel_data: facility.facility_has_fuel_data, + has_installations: facility.facility_has_installations, + has_lcps: facility.facility_has_lcps, + has_ophours_data: facility.facility_has_ophours_data, + has_release_data: facility.facility_has_release_data, + has_transfer_data: facility.facility_has_transfer_data, + has_waste_data: facility.facility_has_waste_data, + }; + } + }); + props.setFlags('facilities', null, facilitiesFlags); + } + }, [siteInspireId, JSON.stringify(site)]); + + return
{props.mode === 'edit' ?

Flags

: ''}
; +}; + +export default compose( + connect( + (state, props) => ({ + query: state.router.location.search, + flags: state.flags, + discodata_query: state.discodata_query, + discodata_resources: state.discodata_resources, + }), + { setFlags }, + ), +)(View); diff --git a/src/components/manage/Blocks/Flags/style.css b/src/components/manage/Blocks/Flags/style.css new file mode 100644 index 00000000..4f0fd308 --- /dev/null +++ b/src/components/manage/Blocks/Flags/style.css @@ -0,0 +1,3 @@ +.embeded-iframe { + border: none; +} \ No newline at end of file diff --git a/src/components/manage/Blocks/NavigationBlock/View.jsx b/src/components/manage/Blocks/NavigationBlock/View.jsx index 3a30b16e..a9ca2089 100644 --- a/src/components/manage/Blocks/NavigationBlock/View.jsx +++ b/src/components/manage/Blocks/NavigationBlock/View.jsx @@ -47,6 +47,30 @@ const View = ({ content, ...props }) => { activeItem: '', }); } + if ( + props.discodata_query.search.siteInspireId && + props.flags.items.sites?.[ + props.discodata_query.search.siteInspireId + ] && + item.title === 'Regulatory information' && + !props.flags.items.sites?.[ + props.discodata_query.search.siteInspireId + ]?.has_installations + ) { + return ''; + } + if ( + props.discodata_query.search.siteInspireId && + props.flags.items.sites?.[ + props.discodata_query.search.siteInspireId + ] && + item.title === 'Large-scale fuel combustion' && + !props.flags.items.sites?.[ + props.discodata_query.search.siteInspireId + ]?.has_lcps + ) { + return ''; + } return ( { + const { pollutant = {} } = props.data; + const classification = pollutant.classification + ?.split('|') + .map((category) => category.replace(/['"]+/g, '')) + .join(', '); + const molecular_formula_sub = pollutant.molecular_formula_sub + ?.split('|') + .map((sub) => sub.replace(/['"]+/g, '')); + const molecular_formula = pollutant.molecular_formula + ?.replace(/['"]+/g, '') + .split('\n') + .map( + (element, index) => + element + + (molecular_formula_sub?.[index] + ? `${molecular_formula_sub[index]}` + : ''), + ) + .join(''); + const health_affects_sub = pollutant.health_affects_sub + ?.split('|') + ?.map((sub) => sub.replace(/['"]+/g, '')); + const health_affects = + pollutant.health_affects + ?.split('|') + ?.map((item, index) => + health_affects_sub?.[index] + ? item + .replace(/['"]+/g, '') + .replace('\n', `${health_affects_sub[index]}`) + : item.replace(/['"]+/g, ''), + ) || []; + const main_methods_of_release = + pollutant.health_affects + ?.split('|') + ?.map((item) => item.replace(/['"]+/g, '')) || []; + if (!props.data.pollutant) return ''; return ( -

Description

-

Main Uses

-

Where do the releases originate?

-

How do the releases affect you and your environment?

+ {pollutant.description ? ( +
+

Description

+

{pollutant.description}

+
+ ) : ( + '' + )} + {pollutant.main_uses ? ( +
+

Main Uses

+

{pollutant.main_uses}

+
+ ) : ( + '' + )} + {main_methods_of_release?.length > 0 ? ( +
+

Where do the releases originate?

+ {main_methods_of_release.map((item, index) => ( +

+ ))} +

+ ) : ( + '' + )} + {health_affects?.length > 0 ? ( +
+

How do the releases affect you and your environment?

+ {health_affects.map((item, index) => ( +

+ ))} +

+ ) : ( + '' + )}
); }, }, { menuItem: 'Pollutant Group', - render: () => ( - -

Pollutant Group - Greenhouse Gases

-

Group members

-
- ), + render: (props) => { + const { pollutants = [], pollutant_group = {} } = props.data; + const sub = pollutant_group.sub + ?.split('|') + ?.map((sub) => sub.replace(/['"]+/g, '')); + const description = pollutant_group.description + ?.replace(/['"]+/g, '') + .split('\n') + .map( + (element, index) => + element + (sub?.[index] ? `${sub[index]}` : ''), + ) + .join(''); + + if (!pollutants?.length) return ''; + return ( + + {pollutant_group.name && !props.data.all_groups ? ( +
+

{`Pollutant Group - ${pollutant_group.name}`}

+
+ ) : props.data.all_groups ? ( +
+

All groups

+
+ ) : ( + '' + )} + {description ? ( +
+

+

+ ) : ( + '' + )} + {pollutants?.length > 0 ? ( +
+

Group members

+
    + {pollutants.map((pollutant, index) => ( +
  • + {pollutant.name} +
  • + ))} +
+
+ ) : ( + '' + )} +
+ ); + }, }, { menuItem: 'Pollutant thresholds', - render: () => ( - -

Pollutant Group - Greenhouse Gases

-

Threshold for releases

- -
- ), + render: (props) => { + const { pollutant = {} } = props.data; + return pollutant.prtr_provision_air || + pollutant.prtr_provision_water || + pollutant.prtr_provision_land ? ( + +

Provisions under E-PRTR Regulation

+

Threshold for releases

+ +
+

+ * - indicates that the parameter and medium in question do not + trigger a reporting requirement. +

+
+
+ ) : ( + '' + ); + }, }, { menuItem: 'Measurements and calculations methods', - render: () => ( - -

Methods and uncertainty

- -
- ), + render: (props) => { + const { pollutant_iso = [] } = props.data; + + return ( + +

Methods and uncertainty

+ {pollutant_iso?.length > 0 ? ( + { + const uncertainty_sup = iso.uncertainty_sup + ?.split('|') + ?.map((sub) => sub.replace(/['"]+/g, '')); + const uncertainty_text = iso.uncertainty_text + ?.replace(/['"]+/g, '') + .split('\n') + .map( + (element, index) => + element + + (uncertainty_sup?.[index] + ? `${uncertainty_sup[index]}` + : ''), + ) + .join(''); + return { + standard: iso.standard, + title: iso.title, + target: iso.target, + uncertainty: uncertainty_text, + }; + })} + /> + ) : ( + '' + )} + +
+

Footnotes

+

+ (*) indicates that performance information is included in the + standard but not in a suitable form for inclusion. +

+

(-) Indicates that no information is available.

+

+ Notes:This table is based on the following published information: + the 2003 General Principles of Monitoring BREF{' '} + + http://eippcb.jrc.es/reference/ + + ; CEN and ISO websites and those of their relevant Technical + Committees (TCs) for details and publication dates ( i.e. CEN + TC230 – water analysis and CEN TC 264 – air quality, ISO TC 147 – + water quality and ISO TC 146 – air quality); and current UK + guidance on monitoring for air and water for IPPC Directive + installations (Environment Agency documents M2 Version 6 - January + 2010and M18 Version 2 - April 2009 covering air and water + respectively) available on{' '} + + http://www.environment-agency.gov.uk/business/regulation/31831.aspx + + ).Standard numbers have been checked against CEN and ISO websites + and, to best of our knowledge, are both available and consistent + with EN or ISO publication dates. +

+

+ Information related to uncertainty is included where it is + available, in a suitable form, in the standard.The information + given for Stationary source emissions generally refers to sampling + and analysis, that for Water quality data refers to the + coefficient of variation of reproducibility - CVR - of the + analysis alone.CVR is the reproducibility standard deviation/mean + concentration, expressed as a %, this has been expressed to one + significant decimal place %. Wherever possible we have taken the + sample matrix most similar to the industrial discharges to be + reported under the EPRTR Regulation.Where the Standard allows a + choice of technique we have taken the 'worst' case - on + the basis that if an operator reports a discharge as having been + measured in accordance with the Standard and not necessarily a + particular variation of it. +

+
+
+ ); + }, }, { menuItem: 'Synonyms or other commercial names', - render: () => Tab 2 Content, + render: (props) => { + const { pollutant = {} } = props.data; + const synonyms = []; + pollutant.synonyms && + pollutant.synonyms.split('|').forEach((synonym) => { + synonyms.push(synonym.replace(/['"]+/g, '')); + }); + return ( + +

Synonyms or other commercial names

+
    + {synonyms.map((synonym) => ( +
  • {synonym}
  • + ))} +
+
+ ); + }, }, { menuItem: 'Other relevant reporting requirements', - render: () => Tab 2 Content, + render: (props) => { + const { other_provisions = [] } = props.data; + const provisionsOrder = []; + const provisions = {}; + other_provisions.forEach((provision) => { + if (!provisions[provision.other_provision_id]) { + provisions[provision.other_provision_id] = {}; + provisionsOrder.push(provision.other_provision_id); + } + provisions[provision.other_provision_id][ + provision.other_provision_type + ] = provision; + }); + + const getProvisionText = (sub, text) => { + const parsed_sub = sub + ?.split('|') + ?.map((sub) => sub.replace(/['"]+/g, '')); + return text + ?.replace(/['"]+/g, '') + .split('\n') + .map( + (element, index) => + element + + (parsed_sub?.[index] ? `${parsed_sub[index]}` : ''), + ) + .join(''); + }; + + return ( + +
+

+ Overview of relevant reporting requirements for the selected + pollutant or compound set by European Regulations or Multilateral + Environmental Agreements (MEAs). +

+ {provisionsOrder.map((provision, index) => ( +
+ {provisions[provision].other_provision_instrument + ?.other_provision_text ? ( +

+ +

+ ) : ( + '' + )} + {provisions[provision].other_provision_overview + ?.other_provision_text ? ( +
+

Overview

+

+

+ ) : ( + '' + )} + {provisions[provision].other_provision_reporting + ?.other_provision_text ? ( +
+

General Reporting

+

+

+ ) : ( + '' + )} + {provisions[provision].other_provision_specific + ?.other_provision_text ? ( +
+

Specific Reporting

+

+

+ ) : ( + '' + )} +
+ ))} +
+
+ ); + }, + }, + { + menuItem: 'Hazards and other technical characteristics', + render: (props) => { + const { pollutant = {} } = props.data; + + return ( + +

Risk and Safety Phrases (R&S)

+

+ Risk and Safety phrases describe the risks of a substance and safety + measures that should be taken. +

+ +

Classification & Labelling

+

+ The Regulation (EC) No 1272/2008 establishes a standard + classification and labelling system for substances distinguishing a) + Hazard Class and b) Hazard Statements +

+ + Regulation (EC) No 1272/2008, OJ L 353 + +

Hazard Class

+

Hazard Statements

+

Physical Properties

+ +

Human Health & Environmental Hazard Assessment

+ +
+ ); + }, }, ]; @@ -104,6 +561,7 @@ const RenderTable = (props) => { const { headless = false, headers = [], rows = [] } = props; return ( { {headers.map((header, headerIndex) => ( - {row[header.key]} +

))} @@ -136,36 +598,167 @@ const RenderTable = (props) => { ); }; -const View = ({ content, ...props }) => { +const View = (props) => { const [activeTab, setActiveTab] = useState(0); - const pollutionType = [ - { - key: 'airPollutionPerCapita', - value: 'airPollutionPerCapita', - text: 'Air', - labelText: 'air pollution per capita', - }, - { - key: 'waterPollutionPerCapita', - value: 'waterPollutionPerCapita', - text: 'Water', - labelText: 'water pollution per capita', - }, - ]; + const [initialized, setInitialized] = useState({ + groups: false, + pollutants: false, + }); + const [currentPollutant, setCurrentPollutant] = useState(undefined); + const [currentPollutants, setCurrentPollutants] = useState([]); + const [currentPollutantGroup, setCurrentPollutantGroup] = useState(undefined); + const mounted = useRef(false); + const indexPollutantId = + props.discodata_query.search.index_pollutant_id || null; + const indexPollutantGroupId = + props.discodata_query.search.index_pollutant_group_id?.join(',') || null; + const indexPollutantGroups = + props.discodata_resources.data.index_pollutant_groups || []; + const indexPollutants = props.discodata_resources.data.index_pollutants || []; + const indexPollutantIso = + props.discodata_resources.data.index_pollutant_iso?.[indexPollutantId] + ?.results || []; + const groupsIds = + indexPollutantGroups.map((group) => group.pollutantId) || []; + const currentOtherProvisions = + props.discodata_resources.data.index_pollutant_other_provisions?.[ + indexPollutantId + ]?.results || []; + + useEffect(() => { + const newPollutant = indexPollutants.filter( + (pollutant) => pollutant.pollutantId === indexPollutantId, + )?.[0]; + setCurrentPollutant( + indexPollutantId !== null && indexPollutantId !== undefined + ? newPollutant + : undefined, + ); + if (newPollutant && newPollutant.other_provisions) { + props.setQueryParam({ + queryParam: { + index_pollutant_other_provisions: newPollutant.other_provisions + .split('|') + .map((item) => item.replace(/['"]+/g, '')), + }, + }); + } + }, [indexPollutantId]); + + useEffect(() => { + if ( + mounted.current && + !initialized.groups && + !indexPollutantGroupId && + indexPollutantGroups.length > 0 && + indexPollutants.length > 0 + ) { + props.setQueryParam({ + queryParam: { + index_pollutant_group_id: groupsIds, + index_pollutant_id: indexPollutants[0].pollutantId, + }, + }); + const newPollutants = + indexPollutants?.filter( + (pollutant) => + pollutant.pollutantId && groupsIds.includes(pollutant.parentId), + ) || []; + setCurrentPollutants(newPollutants); + setInitialized({ + ...initialized, + groups: true, + }); + } + }, [indexPollutantGroups?.length, indexPollutants?.length]); + + useEffect(() => { + mounted.current = true; + return () => { + mounted.current = false; + }; + }, []); + return (

-
+ {/* */} +
{}} + onChange={(event, data) => { + const groupId = data.options + .filter((opt) => { + return opt.value === data.value; + })[0] + ?.value?.split(','); + + const newPollutants = + indexPollutants?.filter( + (pollutant) => + pollutant.pollutantId && groupId.includes(pollutant.parentId), + ) || []; + setCurrentPollutantGroup( + indexPollutantGroups.filter( + (pollutant) => pollutant.pollutantId === groupId.join(','), + )?.[0], + ); + setCurrentPollutants(newPollutants); + props.setQueryParam({ + queryParam: { + index_pollutant_group_id: groupId, + index_pollutant_id: newPollutants?.[0]?.pollutantId, + }, + }); + }} placeholder={'Pollutant Group'} - options={pollutionType} + options={[ + { + key: 'all_groups', + value: groupsIds.join(','), + text: 'All groups', + }, + ...indexPollutantGroups + .filter((pollutantGroup) => pollutantGroup.pollutantId) + .map((pollutantGroup) => ({ + key: pollutantGroup.code, + value: pollutantGroup.pollutantId, + text: pollutantGroup.name, + })), + ]} + value={indexPollutantGroupId} /> {}} + onChange={(event, data) => { + props.setQueryParam({ + queryParam: { + index_pollutant_id: data.options.filter((opt) => { + return opt.value === data.value; + })[0]?.value, + }, + }); + }} placeholder={'Pollutant'} - options={pollutionType} + options={currentPollutants + .filter((pollutant) => pollutant.pollutantId) + .map((pollutant) => ({ + key: pollutant.code, + value: pollutant.pollutantId, + text: pollutant.name, + }))} + value={indexPollutantId} />
{ onTabChange={(event, data) => { setActiveTab(data.activeIndex); }} + data={{ + pollutants: currentPollutants, + all_groups: groupsIds.join(',') === indexPollutantGroupId, + pollutant: currentPollutant, + pollutant_iso: indexPollutantIso, + pollutant_group: currentPollutantGroup, + other_provisions: currentOtherProvisions, + }} />
); }; export default compose( - connect((state, props) => ({ - query: state.router.location.search, - search: state.discodata_query.search, - })), + connect( + (state, props) => ({ + query: state.router.location.search, + discodata_query: state.discodata_query, + discodata_resources: state.discodata_resources, + }), + { + setQueryParam, + deleteQueryParam, + }, + ), )(View); diff --git a/src/components/manage/Blocks/PollutantIndex/style.css b/src/components/manage/Blocks/PollutantIndex/style.css index a110d5d0..07215927 100644 --- a/src/components/manage/Blocks/PollutantIndex/style.css +++ b/src/components/manage/Blocks/PollutantIndex/style.css @@ -35,6 +35,15 @@ .pollutant-index-container h3 { font-size: 1.3em; + margin-bottom: 0.5em; +} + +.pollutant-index-container p:not(:last-child) { + margin-bottom: 0.5em; +} + +.pollutant-index-container p:last-child { + margin-bottom: 0; } .pollutant-index-container h3.blue { @@ -60,7 +69,17 @@ background-color: #F4F4F4 !important; } -.pollutant-index-container .ui.table.description-table tbody tr td:nth-child(1) { +/* .pollutant-index-container .ui.table.description-table tbody tr td:nth-child(1) { color: #EC776A; font-weight: bold; +} */ + +.pollutant-index-container .pollutants-list { + list-style: none; + padding: 0; + margin: 0; +} + +.pollutant-index-container .pollutants-list li { + margin-bottom: 0.5em; } \ No newline at end of file diff --git a/src/components/manage/Blocks/SidebarBlock/View.jsx b/src/components/manage/Blocks/SidebarBlock/View.jsx index 21c8e4d4..50e37a8f 100644 --- a/src/components/manage/Blocks/SidebarBlock/View.jsx +++ b/src/components/manage/Blocks/SidebarBlock/View.jsx @@ -70,6 +70,7 @@ const makeNewNavigation = ( search, history, dispatch, + flags, ) => { if ( ['facilities', 'installations', 'lcps'].includes(preset) && @@ -110,37 +111,63 @@ const makeNewNavigation = ( ); }, items: [ - ...item.items?.map((child) => ({ - ...child, - redirect: (pathname) => { - // if ( - // search.facilityInspireId !== facility.facilityInspireId && - // pathname === child.url - // ) { - // history.push(item.url); - // } + ...[ + { + title: 'Pollutant Releases', + url: `${item.items[0]?.url}#pollutant_releases_tableau`, + flag: 'has_release_data', }, - active: (pathname) => { - return ( - search.facilityInspireId === facility.facilityInspireId && - pathname.includes(child.url) - ); + { + title: 'Pollutant Transfers', + url: `${item.items[0]?.url}#pollutant_transfers_tableau`, + flag: 'has_transfer_data', }, - onClick: (pathname) => { - if (facility.facilityInspireId !== search.facilityInspireId) { - dispatch( - setQueryParam({ - queryParam: { - facilityInspireId: facility.facilityInspireId, - }, - }), - ); - } - if (pathname !== child.url) { - history.push(child.url); - } + { + title: 'Waste Transfers', + url: `${item.items[0]?.url}#pollutant_waste_tableau`, + flag: 'has_waste_data', }, - })), + ] + .filter( + (child) => + flags.items.facilities?.[facility.facilityInspireId]?.[ + child.flag + ], + ) + ?.map((child) => ({ + ...child, + redirect: (pathname) => { + // if ( + // search.facilityInspireId !== facility.facilityInspireId && + // pathname === child.url + // ) { + // history.push(item.url); + // } + }, + active: (pathname) => { + // return ( + // search.facilityInspireId === facility.facilityInspireId && + // pathname.includes(child.url) + // ); + }, + onClick: (pathname) => { + if ( + facility.facilityInspireId !== search.facilityInspireId + ) { + dispatch( + setQueryParam({ + queryParam: { + facilityInspireId: facility.facilityInspireId, + }, + }), + ); + } + + if (pathname !== child.url) { + history.push(child.url); + } + }, + })), ], })) : [], @@ -474,6 +501,7 @@ const View = ({ content, ...props }) => { props.search, history, props.dispatch, + props.flags, ), ); } else if (preset.key) { @@ -541,6 +569,7 @@ export default compose( content: state.prefetch?.[state.router.location.pathname] || state.content.data, pathname: state.router.location.pathname, + flags: state.flags, search: state.discodata_query.search, discodata_resources: state.discodata_resources, navigation: getNavigationByParent( diff --git a/src/constants/ActionTypes.js b/src/constants/ActionTypes.js index 49c1c6d0..8596f444 100644 --- a/src/constants/ActionTypes.js +++ b/src/constants/ActionTypes.js @@ -9,3 +9,4 @@ export const GET_PARENT_FOLDER_DATA = 'GET_PARENT_FOLDER_DATA'; export const GET_NAV_ITEMS = 'GET_NAV_ITEMS'; export const GET_PAGE = 'GET_PAGE'; export const GET_SPARQL_DATA = 'GET_SPARQL_DATA'; +export const SET_FLAGS = 'SET_FLAGS'; diff --git a/src/localconfig.js b/src/localconfig.js index 44a05a9f..e2f058a4 100644 --- a/src/localconfig.js +++ b/src/localconfig.js @@ -40,6 +40,9 @@ import QueryParamButtonView from '~/components/manage/Blocks/QueryParamButton/Vi import IframeEdit from '~/components/manage/Blocks/Iframe/Edit'; import IframeView from '~/components/manage/Blocks/Iframe/View'; +import FlagsEdit from '~/components/manage/Blocks/Flags/Edit'; +import FlagsView from '~/components/manage/Blocks/Flags/View'; + import PollutantIndexEdit from '~/components/manage/Blocks/PollutantIndex/Edit'; import PollutantIndexView from '~/components/manage/Blocks/PollutantIndex/View'; @@ -210,6 +213,15 @@ export function applyConfig(voltoConfig) { icon: packSVG, }; + config.blocks.blocksConfig.eprtr_flags = { + id: 'eprtr_flags', + title: 'Eprtr flags', + group: 'eprtr_blocks', + view: FlagsView, + edit: FlagsEdit, + icon: packSVG, + }; + config.blocks.blocksConfig.eprtr_pollutant_index = { id: 'eprtr_pollutant_index', title: 'Eprtr pollutant index', diff --git a/src/reducers/flags.js b/src/reducers/flags.js new file mode 100644 index 00000000..3cd5e853 --- /dev/null +++ b/src/reducers/flags.js @@ -0,0 +1,36 @@ +import { SET_FLAGS } from '~/constants/ActionTypes'; + +const initialState = { + items: {}, +}; + +export default function pages(state = initialState, action = {}) { + const items = { ...state.items }; + const packageKey = action.packageKey; + const id = action.id; + const flags = action.flags || {}; + switch (action.type) { + case SET_FLAGS: + if (!items[packageKey]) { + items[packageKey] = {}; + } + if (id) { + if (!items[packageKey][id]) { + items[packageKey][id] = {}; + } + Object.keys(flags).forEach((flag) => { + items[packageKey][id][flag] = flags[flag]; + }); + } else { + items[packageKey] = { + ...flags, + }; + } + return { + ...state, + items, + }; + default: + return state; + } +} diff --git a/src/reducers/index.js b/src/reducers/index.js index 39e2f1ce..8b2fb0dd 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -8,6 +8,7 @@ import section_tabs from './section_tabs'; import parent_folder_data from './parent_folder_data'; import pages from './pages'; import sparql from './sparql'; +import flags from './flags'; /** * Root reducer. * @function @@ -20,6 +21,7 @@ const reducers = { parent_folder_data, pages, sparql, + flags, ...defaultReducers, // Add your reducers here };