From 97147b4943198d3ca926388cc0f5165dd64edc4f Mon Sep 17 00:00:00 2001 From: razvanMiu Date: Thu, 17 Dec 2020 19:33:03 +0200 Subject: [PATCH] Default value for reporting year on map --- .../DiscodataOpenlayersMapBlock/View.jsx | 15 ++++++---- .../manage/Blocks/FiltersBlock/View.jsx | 30 ++++++++++++++++--- src/components/theme/View/RedirectView.jsx | 6 ++-- theme/site/globals/site.overrides | 10 +++++++ 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx b/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx index 640bbe72..6e5eac74 100644 --- a/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx +++ b/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx @@ -108,7 +108,7 @@ const OpenlayersMapView = (props) => { const selectedSiteRef = useRef(null); const selectedSiteCoordinates = useRef(null); const regionsSourceWhere = useRef(''); - const firstFilteringDone = useRef(false); + const firstFilteringDone = useRef(0); const ToggleSidebarControl = useRef(null); const ViewYourAreaControl = useRef(null); const siteTermRef = useRef(null); @@ -285,9 +285,7 @@ const OpenlayersMapView = (props) => { state.map.sitesSourceLayer && state.map.sitesSourceLayer.getSource().refresh(); } - if (!firstFilteringDone.current) { - firstFilteringDone.current = true; - } + firstFilteringDone.current++; if (!state.updateMapPosition && !state.map.sitesSourceQuery.where) { applyZoom(); } @@ -686,7 +684,9 @@ const OpenlayersMapView = (props) => { stateRef.current.updateMapPosition === 'byAdvancedFilters' && mounted.current ) { - stateRef.current.map.element.getView().cancelAnimations(); + if (firstFilteringDone.current > 2) { + stateRef.current.map.element.getView().cancelAnimations(); + } setSelectedSite(null); getLocationByAdvancedFilters(options); } @@ -1088,7 +1088,10 @@ const OpenlayersMapView = (props) => { } map.on('click', function (evt) { let newZoom = map.getView().getZoom(); - if (newZoom > zoomSwitch) { + if ( + newZoom > zoomSwitch || + stateRef.current.map.sitesSourceQuery?.where + ) { displayPopup(map, evt.pixel, evt.coordinate, popupDetails, true); } }); diff --git a/src/components/manage/Blocks/FiltersBlock/View.jsx b/src/components/manage/Blocks/FiltersBlock/View.jsx index bd1e3613..cf74a026 100644 --- a/src/components/manage/Blocks/FiltersBlock/View.jsx +++ b/src/components/manage/Blocks/FiltersBlock/View.jsx @@ -5,7 +5,10 @@ import { connect } from 'react-redux'; import { Header, Modal, Select, Input, List } from 'semantic-ui-react'; import { Portal } from 'react-portal'; import { Icon } from '@plone/volto/components'; -import { setQueryParam, deleteQueryParam } from '@eeacms/volto-datablocks/actions'; +import { + setQueryParam, + deleteQueryParam, +} from '@eeacms/volto-datablocks/actions'; import { settings } from '~/config'; import _uniqueId from 'lodash/uniqueId'; import axios from 'axios'; @@ -518,6 +521,25 @@ const View = ({ content, ...props }) => { }) || []), ], }; + if (metadata[index]?.key === 'reporting_years') { + const reportingYears = + res.data?.results + ?.map((item) => item.reportingYear) + ?.sort((a, b) => b - a) || []; + if (reportingYears.length) { + props.setQueryParam({ + queryParam: { + [metadata[index].queryToSet]: [reportingYears[0]], + advancedFiltering: true, + filtersCounter: props.discodata_query.search[ + 'filtersCounter' + ] + ? props.discodata_query.search['filtersCounter'] + 1 + : 1, + }, + }); + } + } }); setLoadingData(false); setState({ @@ -892,8 +914,8 @@ const View = ({ content, ...props }) => { ...state.filters, [searchTermType]: searchTermType === 'locationTerm' - ? locationResults[locationResultsTexts.indexOf(searchTerm)] - : searchTerm, + ? locationResults[locationResultsTexts.indexOf(searchTerm)] || '' + : searchTerm || '', [emptyTermType]: null, nuts_regions: nuts, nuts_latest, @@ -902,7 +924,7 @@ const View = ({ content, ...props }) => { : 1, extent: (nuts_latest.length || - (searchTermType === 'siteTerm' && searchTerm.length)) && + (searchTermType === 'siteTerm' && searchTerm?.length)) && searchTermType !== 'locationTerm' ? null : props.discodata_query.search['extent'], diff --git a/src/components/theme/View/RedirectView.jsx b/src/components/theme/View/RedirectView.jsx index 7a8d6ec9..7a2373e1 100644 --- a/src/components/theme/View/RedirectView.jsx +++ b/src/components/theme/View/RedirectView.jsx @@ -1,5 +1,5 @@ /* REACT IMPORTS */ -import React, { useEffect, useState, useRef } from 'react'; +import React, { useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { connect } from 'react-redux'; import { getBasePath } from '~/helpers'; @@ -9,8 +9,8 @@ const RedirectView = (props) => { const history = useHistory(); const [mounted, setMounted] = useState(false); const [redirect, setRedirect] = useState(false); - const currentPage = props.content['@id']; - const redirectPage = props.content.relatedItems?.[0]?.['@id']; + const currentPage = props.content?.['@id']; + const redirectPage = props.content?.relatedItems?.[0]?.['@id']; useEffect(() => { setMounted(true); diff --git a/theme/site/globals/site.overrides b/theme/site/globals/site.overrides index 4617418e..09b6bd46 100644 --- a/theme/site/globals/site.overrides +++ b/theme/site/globals/site.overrides @@ -1708,4 +1708,14 @@ b { strong { font-weight: bold !important; +} + +.view-wrapper { + margin-top: 2rem; + margin-bottom: 2rem; +} + +.folder-contents { + margin-top: 2rem; + margin-bottom: 2rem; } \ No newline at end of file