Skip to content
Snippets Groups Projects
Commit dd97f030 authored by vimal1083's avatar vimal1083
Browse files

Fix no-results-found bug in react filters

parent a9c46f6e
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,8 @@ class ByRoundListing extends React.Component { ...@@ -44,7 +44,8 @@ class ByRoundListing extends React.Component {
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
errorMessage: PropTypes.string, errorMessage: PropTypes.string,
filters: PropTypes.array, filters: PropTypes.array,
groupBy: PropTypes.string groupBy: PropTypes.string,
loadRounds: PropTypes.func
}; };
componentDidMount() { componentDidMount() {
...@@ -54,13 +55,14 @@ class ByRoundListing extends React.Component { ...@@ -54,13 +55,14 @@ class ByRoundListing extends React.Component {
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
const { statuses, groupBy } = this.props; const { statuses } = this.props;
if (!statuses.every(v => prevProps.statuses.includes(v)) if (!statuses.every(v => prevProps.statuses.includes(v))
|| !groupBy && !Object.keys(this.props.rounds).length
|| this.props.filters != prevProps.filters) { || this.props.filters != prevProps.filters) {
loadData(this.props) loadData(this.props)
} }
if(!Object.keys(this.props.rounds).length) this.props.loadRounds()
} }
prepareOrder = () => { prepareOrder = () => {
......
...@@ -66,9 +66,9 @@ export class SubmissionFiltersContainer extends React.PureComponent { ...@@ -66,9 +66,9 @@ export class SubmissionFiltersContainer extends React.PureComponent {
} }
componentDidUpdate(prevProps, prevState){ componentDidUpdate(prevProps, prevState){
if(this.props.getScreeningLoading == false if(
&& !this.props.isGroupedIconShown !this.props.isGroupedIconShown &&
&& this.props.history.location.search.includes("&") this.props.history.location.search.includes("&")
&& !this.props.submissionFilters.loading){ && !this.props.submissionFilters.loading){
this.props.initializeAction(this.props.history.location.search, this.onFilter) this.props.initializeAction(this.props.history.location.search, this.onFilter)
} }
...@@ -82,6 +82,7 @@ export class SubmissionFiltersContainer extends React.PureComponent { ...@@ -82,6 +82,7 @@ export class SubmissionFiltersContainer extends React.PureComponent {
filterQuery.push({"key": "f_"+key, "value": options[key]}) filterQuery.push({"key": "f_"+key, "value": options[key]})
) )
this.props.updateFilterQuery(filterQuery) this.props.updateFilterQuery(filterQuery)
if(!filterQuery.length) this.props.history.push(window.location.pathname)
this.props.onFilter() this.props.onFilter()
} }
......
...@@ -16,8 +16,7 @@ function getFilters(params) { ...@@ -16,8 +16,7 @@ function getFilters(params) {
if(urlParams.get(key)){ if(urlParams.get(key)){
if(key == "f_status"){ if(key == "f_status"){
filters[key.slice(2)] = JSON.parse(urlParams.get(key)) filters[key.slice(2)] = JSON.parse(urlParams.get(key))
} }else filters[key.slice(2)] = urlParams.get(key).split(",").map(i => i !== 'null' ? Number(i) : null)
else filters[key.slice(2)] = urlParams.get(key).split(",").map(i=>Number(i))
} }
} }
return filters return filters
......
...@@ -214,13 +214,13 @@ export const setSubmissionParam = (id) => (dispatch, getState) => { ...@@ -214,13 +214,13 @@ export const setSubmissionParam = (id) => (dispatch, getState) => {
const urlParams = new URLSearchParams(state.router.location.search); const urlParams = new URLSearchParams(state.router.location.search);
const urlID = Number(urlParams.get('submission')); const urlID = Number(urlParams.get('submission'));
// check whether filters available & create searchParams accordingly // check whether filters selected & create searchParams accordingly
let searchParams = "" let searchParams = ""
if(filters && filters.length){ if(filters && filters.length){
filters.forEach(filter => { filters.forEach(filter => {
if(filter.key == "f_status"){ if(filter.key == "f_status"){
searchParams = searchParams + `&${filter.key}=${JSON.stringify(filter.value)}` searchParams = searchParams + `&${filter.key}=${JSON.stringify(filter.value)}`
}else searchParams = searchParams + `&${filter.key}=${filter.value.join()}` }else searchParams = searchParams + `&${filter.key}=${filter.value.map(v => !v ? "null" : v).join()}`
}) })
} }
...@@ -229,15 +229,18 @@ export const setSubmissionParam = (id) => (dispatch, getState) => { ...@@ -229,15 +229,18 @@ export const setSubmissionParam = (id) => (dispatch, getState) => {
const shouldUpdate = id !== null && submissionID !== id && urlID !== id 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 && !(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 && function hasEqualFilters(filter) {
filters.filter(filter => urlParams.get(filter.key) === null || if(filter.key === "f_status") return urlParams.get(filter.key) !== JSON.stringify(filter.value)
filter.value.length !== urlParams.get(filter.key).split(',').length).length) || else return urlParams.get(filter.key) !== filter.value.join(',')
urlParams.toString().includes("&") && filters != null && !filters.length || }
urlParams.toString().includes("&") && filters != null && filters.length
&& searchParams.split("&").length != urlParams.toString().split("&").length
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}`})); dispatch(push({search: `?submission=${id}${searchParams}`}));
}else if (id === null ) { }else if (id === null ) {
dispatch(clearCurrentSubmissionParam()); dispatch(clearCurrentSubmissionParam());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment