Skip to content

Commit

Permalink
Default value for reporting year on map
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Dec 17, 2020
1 parent 1a13d46 commit 97147b4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
});
Expand Down
30 changes: 26 additions & 4 deletions src/components/manage/Blocks/FiltersBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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'],
Expand Down
6 changes: 3 additions & 3 deletions src/components/theme/View/RedirectView.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions theme/site/globals/site.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 97147b4

Please sign in to comment.