From dd97f0309857ddd31aa2a84e7dfd9003c4c42ca6 Mon Sep 17 00:00:00 2001 From: vimal1083 <vimal1083@gmail.com> Date: Thu, 22 Jul 2021 12:39:16 +0530 Subject: [PATCH] Fix no-results-found bug in react filters --- .../src/app/src/containers/ByRoundListing.js | 8 +++--- .../src/containers/SubmissionFilters/index.js | 7 +++--- .../src/containers/SubmissionFilters/sagas.js | 3 +-- .../src/app/src/redux/actions/submissions.js | 25 +++++++++++-------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/hypha/static_src/src/app/src/containers/ByRoundListing.js b/hypha/static_src/src/app/src/containers/ByRoundListing.js index 12c32e958..ec687f7da 100644 --- a/hypha/static_src/src/app/src/containers/ByRoundListing.js +++ b/hypha/static_src/src/app/src/containers/ByRoundListing.js @@ -44,7 +44,8 @@ class ByRoundListing extends React.Component { isLoading: PropTypes.bool, errorMessage: PropTypes.string, filters: PropTypes.array, - groupBy: PropTypes.string + groupBy: PropTypes.string, + loadRounds: PropTypes.func }; componentDidMount() { @@ -54,13 +55,14 @@ class ByRoundListing extends React.Component { } componentDidUpdate(prevProps) { - const { statuses, groupBy } = this.props; + const { statuses } = this.props; if (!statuses.every(v => prevProps.statuses.includes(v)) - || !groupBy && !Object.keys(this.props.rounds).length || this.props.filters != prevProps.filters) { loadData(this.props) } + + if(!Object.keys(this.props.rounds).length) this.props.loadRounds() } prepareOrder = () => { diff --git a/hypha/static_src/src/app/src/containers/SubmissionFilters/index.js b/hypha/static_src/src/app/src/containers/SubmissionFilters/index.js index 026c9d990..4aae7c2c1 100644 --- a/hypha/static_src/src/app/src/containers/SubmissionFilters/index.js +++ b/hypha/static_src/src/app/src/containers/SubmissionFilters/index.js @@ -66,9 +66,9 @@ export class SubmissionFiltersContainer extends React.PureComponent { } componentDidUpdate(prevProps, prevState){ - if(this.props.getScreeningLoading == false - && !this.props.isGroupedIconShown - && this.props.history.location.search.includes("&") + if( + !this.props.isGroupedIconShown && + this.props.history.location.search.includes("&") && !this.props.submissionFilters.loading){ this.props.initializeAction(this.props.history.location.search, this.onFilter) } @@ -82,6 +82,7 @@ export class SubmissionFiltersContainer extends React.PureComponent { filterQuery.push({"key": "f_"+key, "value": options[key]}) ) this.props.updateFilterQuery(filterQuery) + if(!filterQuery.length) this.props.history.push(window.location.pathname) this.props.onFilter() } diff --git a/hypha/static_src/src/app/src/containers/SubmissionFilters/sagas.js b/hypha/static_src/src/app/src/containers/SubmissionFilters/sagas.js index e68cefeee..112b5bd85 100644 --- a/hypha/static_src/src/app/src/containers/SubmissionFilters/sagas.js +++ b/hypha/static_src/src/app/src/containers/SubmissionFilters/sagas.js @@ -16,8 +16,7 @@ function getFilters(params) { if(urlParams.get(key)){ if(key == "f_status"){ filters[key.slice(2)] = JSON.parse(urlParams.get(key)) - } - else filters[key.slice(2)] = urlParams.get(key).split(",").map(i=>Number(i)) + }else filters[key.slice(2)] = urlParams.get(key).split(",").map(i => i !== 'null' ? Number(i) : null) } } return filters diff --git a/hypha/static_src/src/app/src/redux/actions/submissions.js b/hypha/static_src/src/app/src/redux/actions/submissions.js index 251bc054f..a64ff3c86 100644 --- a/hypha/static_src/src/app/src/redux/actions/submissions.js +++ b/hypha/static_src/src/app/src/redux/actions/submissions.js @@ -214,13 +214,13 @@ export const setSubmissionParam = (id) => (dispatch, getState) => { const urlParams = new URLSearchParams(state.router.location.search); const urlID = Number(urlParams.get('submission')); - // check whether filters available & create searchParams accordingly + // check whether filters selected & create searchParams accordingly let searchParams = "" if(filters && filters.length){ filters.forEach(filter => { if(filter.key == "f_status"){ - searchParams = searchParams + `&${filter.key}=${JSON.stringify(filter.value)}` - }else searchParams = searchParams + `&${filter.key}=${filter.value.join()}` + searchParams = searchParams + `&${filter.key}=${JSON.stringify(filter.value)}` + }else searchParams = searchParams + `&${filter.key}=${filter.value.map(v => !v ? "null" : v).join()}` }) } @@ -229,15 +229,18 @@ export const setSubmissionParam = (id) => (dispatch, getState) => { const shouldUpdate = id !== null && submissionID !== id && urlID !== id && !(submissionID == null && urlParams.toString().includes("&")); // if url contains filter query & it is shared, don't update id - // check both url query parmas & filters are equal - const queryUpdate = (filters && - filters.filter(filter => urlParams.get(filter.key) === null || - filter.value.length !== urlParams.get(filter.key).split(',').length).length) || - urlParams.toString().includes("&") && filters != null && !filters.length || - urlParams.toString().includes("&") && filters != null && filters.length - && searchParams.split("&").length != urlParams.toString().split("&").length + + function hasEqualFilters(filter) { + if(filter.key === "f_status") return urlParams.get(filter.key) !== JSON.stringify(filter.value) + else return urlParams.get(filter.key) !== filter.value.join(',') + } - if (shouldSet || shouldUpdate || queryUpdate) { + const hasEqualNoOfFilters = searchParams.split("&").length == urlParams.toString().split("&").length + + // check url query parmas are same as filters selected + const shouldUpdateURLQuery = filters && (filters.filter(hasEqualFilters).length || !hasEqualNoOfFilters) + + if (shouldSet || shouldUpdate || Boolean(shouldUpdateURLQuery)) { dispatch(push({search: `?submission=${id}${searchParams}`})); }else if (id === null ) { dispatch(clearCurrentSubmissionParam()); -- GitLab