Skip to content

Commit

Permalink
[Bug #129791] Make filter by location / by country independent
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed May 6, 2021
1 parent 3815661 commit acf9f60
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions src/components/manage/Blocks/FiltersBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ const View = ({ content, ...props }) => {
useEffect(function () {
mounted.current = true;
setMountState(true);
document.addEventListener('mousedown', handleClickOutside, false);
return () => {
mounted.current = false;
setMountState(false);
document.removeEventListener('mousedown', handleClickOutside, false);
};
/* eslint-disable-next-line */
}, []);

useEffect(() => {
if (mounted.current && triggerSearch) {
submit();
submit(false, true);
setTriggerSearch(false);
}
/* eslint-disable-next-line */
Expand All @@ -104,18 +106,6 @@ const View = ({ content, ...props }) => {
/* eslint-disable-next-line */
}, [state.open]);

useEffect(() => {
// register eventListener on each state update
if (mounted.current) {
document.addEventListener('mousedown', handleClickOutside, false);
}
return () => {
// unregister eventListener
document.removeEventListener('mousedown', handleClickOutside, false);
};
/* eslint-disable-next-line */
}, [state]);

useEffect(() => {
if (mounted.current) {
updateFilters();
Expand Down Expand Up @@ -435,6 +425,7 @@ const View = ({ content, ...props }) => {
});
setLoadingData(true);
}
if (!promises?.length) return;
Promise.all(promises)
.then((response) => {
if (mounted.current) {
Expand Down Expand Up @@ -625,7 +616,6 @@ const View = ({ content, ...props }) => {
filtersToDelete.forEach((filter) => {
newFilters[filter] = [];
});

setState({
...state,
filters: { ...(newFilters || {}) },
Expand Down Expand Up @@ -883,7 +873,7 @@ const View = ({ content, ...props }) => {
setSearchTerm(data.value);
};

const submit = (advancedFiltering = false) => {
const submit = (advancedFiltering = false, search = false) => {
const searchTermType =
sitesResults.indexOf(searchTerm) > -1
? 'siteTerm'
Expand Down Expand Up @@ -945,9 +935,35 @@ const View = ({ content, ...props }) => {
? null
: props.discodata_query.search['extent'],
advancedFiltering,
...(!search
? {}
: {
siteCountry: [],
province: [],
region: [],
riverBasin: [],
nuts_regions: [],
nuts_latest: [],
}),
},
});
setState({
...state,
open: false,
filters: {
...state.filters,
...(!search
? {}
: {
siteCountry: [null],
province: [null],
region: [null],
riverBasin: [null],
nuts_regions: [null],
nuts_latest: [null],
}),
},
});
setState({ ...state, open: false });
};

const getNewExtent = (searchTerm) => {
Expand Down Expand Up @@ -1388,6 +1404,8 @@ const View = ({ content, ...props }) => {
);
props.setQueryParam({
queryParam: {
locationTerm: null,
siteTerm: null,
advancedFiltering: true,
filtersCounter: props.discodata_query.search[
'filtersCounter'
Expand All @@ -1398,6 +1416,7 @@ const View = ({ content, ...props }) => {
: 1,
},
});
setSearchTerm('');
}}
placeholder={
state.filtersMeta['countries']?.placeholder
Expand Down

0 comments on commit acf9f60

Please sign in to comment.