Skip to content

Commit

Permalink
Fixed Map filters; Fixed View;
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Sep 2, 2020
1 parent d47361c commit 427df5e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 46 deletions.
65 changes: 42 additions & 23 deletions src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const OpenlayersMapView = (props) => {
}, [
JSON.stringify(props.discodata_query.search.siteTerm),
JSON.stringify(props.discodata_query.search.locationTerm),
JSON.stringify(props.discodata_query.search.EEASector),
JSON.stringify(props.discodata_query.search.EEASubSector),
JSON.stringify(props.discodata_query.search.siteCountry),
JSON.stringify(props.discodata_query.search.region),
JSON.stringify(props.discodata_query.search.riverBasin),
Expand Down Expand Up @@ -230,26 +230,30 @@ const OpenlayersMapView = (props) => {
sql: `(siteName LIKE ':options%')`,
type: 'string',
},
//? Industries
EEASector: {
sql: `(EEASector IN (:options))`,
// Industries
EEASubSector: {
sql: `(eea_activities IN (:options))`,
},
// Country
siteCountry: {
sql: `(country IN (:options))`,
},
//? Regions
region: {
sql: `(region IN (:options))`,
},
//? River Basin
riverBasin: {
sql: `(riverBasinDistrict IN (:options))`,
},
//? Town/Village
townVillage: {
sql: `(townVillage IN (:options))`,
nuts_regions: {
sql: `(nuts_regions LIKE '%:options%')`,
type: 'multiple',
},
// // Country
// siteCountry: {
// sql: `(countryCode IN (:options))`,
// },
// //? Regions
// region: {
// sql: `(region IN (:options))`,
// },
// //? River Basin
// riverBasin: {
// sql: `(riverBasinDistrict IN (:options))`,
// },
// //? Town/Village
// townVillage: {
// sql: `(townVillage IN (:options))`,
// },
// Pollutant groups
// pollutantGroup: {
// sql: `(pollutantGroup IN (:options))`,
Expand All @@ -260,7 +264,7 @@ const OpenlayersMapView = (props) => {
},
// Reporting year
reportingYear: {
sql: `(rep_yr IN (:options))`,
sql: `(Site_reporting_year IN (:options))`,
},
//! Installation specifics
//? BAT conclusion
Expand All @@ -282,12 +286,27 @@ const OpenlayersMapView = (props) => {
let options;
if (where.type === 'string') {
options = props.discodata_query.search[id];
} else if (where.type === 'multiple') {
options = props.discodata_query.search[id];
} else if (!props.discodata_query.search[id]) {
options = null;
} else {
options = splitBy(props.discodata_query.search[id], ',');
}
where.sql = options ? where.sql.replace(':options', options) : null;
if (where.type === 'multiple') {
const conditions = [];
if (options?.length) {
options.forEach((option) => {
let baseSql = where.sql;
option && conditions.push(baseSql.replace(':options', option));
});
where.sql = conditions.join(' AND ');
} else {
where.sql = null;
}
} else {
where.sql = options ? where.sql.replace(':options', options) : null;
}
if (!where.sql) delete sitesSourceQuery.whereStatements[id];
});

Expand Down Expand Up @@ -720,12 +739,12 @@ const OpenlayersMapView = (props) => {
layers: [worldLightGrayBase, worldHillshade],
}),
);
// Append popups to the map
popup && map.addOverlay(popup);
popupDetails && map.addOverlay(popupDetails);
// Append dynamic filters to the map
dynamicFilters && map.addOverlay(dynamicFilters);
dynamicFilters && dynamicFilters.setPosition([0, 0]);
// Append popups to the map
popup && map.addOverlay(popup);
// Append source layers to the map
map.addLayer(
new Group({
Expand Down
60 changes: 46 additions & 14 deletions src/components/manage/Blocks/FiltersBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const View = ({ content, ...props }) => {
? {
factId: 'Country_quick_facts',
sql: `SELECT DISTINCT MP.siteCountry, MP.siteCountryName, MM.siteCount
FROM [IED].[latest].[vw_Browse2_MapPOPUP] as MP
FROM [IED].[latest].[Browse2_MapPOPUP] as MP
LEFT JOIN [IED].[latest].[vw_MainMap_totalSitesPerCountry] as MM
ON MP.siteCountry = MM.countryCode
WHERE siteCountry = '${alphaFeature.getProperties().country}'`,
Expand Down Expand Up @@ -211,38 +211,38 @@ const View = ({ content, ...props }) => {
const onMountRequests = {
sqls: [
// INDUSTRIES QUERY
`SELECT DISTINCT EEASector
`SELECT DISTINCT EEASubSector
FROM [IED].[latest].[EPRTR_sectors]
ORDER BY EEASector`,
ORDER BY EEASubSector`,
// COUNTRIES QUERY
`SELECT DISTINCT siteCountry, siteCountryName
FROM [IED].[latest].[vw_Browse2_MapPOPUP]
FROM [IED].[latest].[Browse2_MapPOPUP]
ORDER BY siteCountryName`,
// POLLUTANT GROUPS QUERY
`SELECT DISTINCT pollutantgroup
FROM [IED].[latest].[vw_Browse2_MapPOPUP]
FROM [IED].[latest].[Browse2_MapPOPUP]
WHERE NOT(pollutantgroup='')
ORDER BY pollutantgroup`,
// REPORTING YEARS QUERY
`SELECT DISTINCT reportingYear FROM [IED].[latest].[ReportData] ORDER BY reportingYear`,
// BAT CONCLUSSIONS QUERY
`SELECT DISTINCT code, Label, AcceptedDate FROM [IED].[latest].[BATConclusionValue] ORDER BY Label`,
`SELECT DISTINCT id, Label, AcceptedDate FROM [IED].[latest].[BATConclusionValue] ORDER BY Label`,
],
meta: [
// INDUSTRIES META
{
key: 'industries',
title: 'Industries',
queryToSet: 'EEASector',
queryToSet: 'EEASubSector',
firstInput: {
id: _uniqueId('select_'),
type: 'select',
position: 0,
},
placeholder: 'Select industry',
optionKey: 'EEASector',
optionValue: 'EEASector',
optionText: 'EEASector',
optionKey: 'EEASubSector',
optionValue: 'EEASubSector',
optionText: 'EEASubSector',
static: true,
},
// COUNTRIES META
Expand Down Expand Up @@ -304,8 +304,8 @@ const View = ({ content, ...props }) => {
position: 0,
},
placeholder: 'Select BAT conclusion',
optionKey: 'code',
optionValue: 'code',
optionKey: 'id',
optionValue: 'id',
optionText: 'Label',
static: true,
},
Expand Down Expand Up @@ -509,7 +509,7 @@ const View = ({ content, ...props }) => {
/* eslint-disable-next-line */
}, [
state.mounted,
state.filters?.EEASector && JSON.stringify(state.filters.EEASector),
state.filters?.EEASubSector && JSON.stringify(state.filters.EEASubSector),
state.filters?.siteCountry && JSON.stringify(state.filters.siteCountry),
state.filters?.region && JSON.stringify(state.filters.region),
state.filters?.townVillage && JSON.stringify(state.filters.townVillage),
Expand Down Expand Up @@ -635,6 +635,7 @@ const View = ({ content, ...props }) => {
queryParam: {
...props.discodata_query.search,
...newFilters,
nuts_regions: [],
},
});
};
Expand Down Expand Up @@ -730,6 +731,36 @@ const View = ({ content, ...props }) => {
: 'locationTerm';
const emptyTermType =
searchTermType === 'siteTerm' ? 'locationTerm' : 'siteTerm';
const siteCountries = state.filters.siteCountry;
const regions = state.filters.region;
const townVillages = state.filters.townVillage;
let nuts = [];
siteCountries &&
siteCountries.forEach((country) => {
const filteredRegions = regions
? regions.filter((region) => {
return region.includes(country);
})
: [];
if (filteredRegions.length) {
filteredRegions.forEach((region) => {
const filteredTowns = townVillages
? townVillages.filter((town) => {
return town.includes(region);
})
: [];
if (filteredTowns.length) {
filteredTowns.forEach((town) => {
nuts.push(`${town},${region},${country}`);
});
} else {
nuts.push(`${region},${country}`);
}
});
} else {
nuts.push(country);
}
});
props.setQueryParam({
queryParam: {
...state.filters,
Expand All @@ -738,6 +769,7 @@ const View = ({ content, ...props }) => {
? locationResults[locationResultsTexts.indexOf(searchTerm)]
: searchTerm,
[emptyTermType]: null,
nuts_regions: nuts,
},
});
setState({ ...state, open: false });
Expand Down Expand Up @@ -1017,7 +1049,7 @@ const View = ({ content, ...props }) => {
}}
placeholder={state.filtersMeta['industries']?.placeholder}
options={state.filtersMeta['industries']?.options}
value={state.filters['EEASector']?.[0]}
value={state.filters['EEASubSector']?.[0]}
/>
</div>
</div>
Expand Down
10 changes: 4 additions & 6 deletions src/components/theme/View/RedirectView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import React, { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { connect } from 'react-redux';
/* ROOT IMPORTS */
import DiscodataView from './DiscodataView';
/* LOCAL IMPORTS */
import { getBasePath } from '~/helpers';
import { Dimmer, Loader } from 'semantic-ui-react';
const RedirectView = (props) => {
const history = useHistory();
const [redirect, setRedirect] = useState(false);
Expand All @@ -27,9 +25,9 @@ const RedirectView = (props) => {
}
}
return (
<div id="discodata-mosaic-view">
<h1>Redirecting...</h1>
</div>
<Dimmer active inverted>
<Loader inverted>European Environment Agency</Loader>
</Dimmer>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/customizations/volto/components/theme/View/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class View extends Component {
}

componentDidUpdate(prevProps, prevState) {
if (prevProps.content['@id'] !== this.props.content['@id']) {
if (prevProps.content?.['@id'] !== this.props.content?.['@id']) {
const RenderedView = this.getRenderedView();
this.setState({ RenderedView });
}
Expand Down Expand Up @@ -187,7 +187,7 @@ class View extends Component {
] || null;

getRenderedView = () =>
getBasePath(this.props.content['@id']) === this.props.pathname
getBasePath(this.props.content?.['@id']) === this.props.pathname
? this.getViewByType() || this.getViewByLayout() || this.getViewDefault()
: null;

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/api.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getLcps = (dispatch, siteInspireId) => {
facilityInspireId,
installationInspireId,
string_agg(concat(lcpInspireId, ''), ',') as lcps
FROM [IED].[latest].[vw_Browse10_Header] as Results
FROM [IED].[latest].[Browse10_Header] as Results
WHERE siteInspireId = '${siteInspireId}'
GROUP BY facilityInspireId, installationInspireId`);
const url = `${settings.providerUrl}?query=${sql}`;
Expand Down

0 comments on commit 427df5e

Please sign in to comment.