Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#809 | Search View | URL changes on action/f…
Browse files Browse the repository at this point in the history
…ilter triggers
  • Loading branch information
snyaggarwal committed Jul 9, 2021
1 parent 883e87b commit f6ab3d7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
5 changes: 1 addition & 4 deletions src/components/collections/CollectionHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ class CollectionHome extends React.Component {
}

componentDidUpdate(prevProps) {
if(
(prevProps.location.pathname !== this.props.location.pathname) ||
(prevProps.location.search !== this.props.location.search)
) {
if(prevProps.location.pathname !== this.props.location.pathname) {
this.refreshDataByURL()
this.onTabChange(null, this.getDefaultTabIndex())
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/orgs/OrgHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ class OrgHome extends React.Component {
}

componentDidUpdate(prevProps) {
if(
(prevProps.location.pathname !== this.props.location.pathname) ||
(prevProps.location.search !== this.props.location.search)
) {
if(prevProps.location.pathname !== this.props.location.pathname) {
this.refreshDataByURL()
this.getPins()
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/search/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import InfiniteScroll from 'react-infinite-scroll-component';
const Results = props => {
const {
resource, results, viewFields, onPageChange, onCreateSimilarClick, onCreateMappingClick,
onLoadMore, isInfinite, noControls, onReferencesDelete, history, currentLayoutURL, onSelect,
onLoadMore, isInfinite, noControls, onReferencesDelete, history, onSelect,
splitView
} = props;
const items = get(results, 'items', [])
Expand All @@ -35,12 +35,11 @@ const Results = props => {
item => splitView ?
<MinimalRowComponent
key={item.uuid || item.id} onSelect={onSelectChange}
item={item} resource={resource} viewFields={viewFields}
history={history} currentLayoutURL={currentLayoutURL} /> :
item={item} resource={resource} /> :
<RowComponent
key={item.uuid || item.id} onSelect={onSelectChange}
item={item} resource={resource} viewFields={viewFields}
history={history} currentLayoutURL={currentLayoutURL} />
history={history} />
)
const infiniteResults = () => (
<InfiniteScroll
Expand Down
6 changes: 2 additions & 4 deletions src/components/search/ResultsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const LocalesTable = ({ locales, isDescription }) => {
const ExpandibleRow = props => {
const {
item, resourceDefinition, resource, isSelected, isSelectable, onPinCreate, onPinDelete, pins,
nested, showPin, columns, hapi, fhir, history, currentLayoutURL
nested, showPin, columns, hapi, fhir, history
} = props;
const [details, setDetails] = React.useState(false);
const [isFetchingMappings, setIsFetchingMappings] = React.useState(true);
Expand Down Expand Up @@ -447,7 +447,6 @@ const ExpandibleRow = props => {
url = `/fhir${getOCLFHIRResourceURL(item)}`
} else url = item.url;

history.replace(currentLayoutURL)
history.push(url)
}

Expand Down Expand Up @@ -750,7 +749,7 @@ const ResultsTable = (
resource, results, onPageChange, onSortChange, sortParams,
onPinCreate, onPinDelete, pins, nested, showPin, essentialColumns, onReferencesDelete,
isVersionedObject, onCreateSimilarClick, onCreateMappingClick, viewFields, hapi, fhir, history,
currentLayoutURL, onSelect
onSelect
}
) => {
const resourceDefinition = RESOURCE_DEFINITIONS[resource];
Expand Down Expand Up @@ -912,7 +911,6 @@ const ResultsTable = (
hapi={hapi}
fhir={fhir}
history={history}
currentLayoutURL={currentLayoutURL}
/>
))
}
Expand Down
51 changes: 32 additions & 19 deletions src/components/search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Search extends React.Component {
staticParams: {},
includeRetired: false,
userFilters: {},
isURLUpdatedByActionChange: false,
results: {
concepts: cloneDeep(resourceResultStruct),
mappings: cloneDeep(resourceResultStruct),
Expand Down Expand Up @@ -163,17 +164,18 @@ class Search extends React.Component {
}

componentDidUpdate(prevProps) {
if(get(prevProps, 'location.search') !== get(this.props, 'location.search'))
const { isURLUpdatedByActionChange } = this.state
if(get(prevProps, 'location.search') !== get(this.props, 'location.search') && !isURLUpdatedByActionChange)
this.setQueryParamsInState()
if(prevProps.baseURL !== this.props.baseURL && this.props.baseURL)
if(prevProps.baseURL !== this.props.baseURL && this.props.baseURL && !isURLUpdatedByActionChange)
this.setQueryParamsInState()
if(!isEqual(prevProps.viewFilters, this.props.viewFilters))
if(!isEqual(prevProps.viewFilters, this.props.viewFilters) && !isURLUpdatedByActionChange)
this.setQueryParamsInState()
if(!isEqual(prevProps.fixedFilters, this.props.fixedFilters))
if(!isEqual(prevProps.fixedFilters, this.props.fixedFilters) && !isURLUpdatedByActionChange)
this.setQueryParamsInState()
if(!isEqual(prevProps.userFilters, this.props.userFilters))
if(!isEqual(prevProps.userFilters, this.props.userFilters) && !isURLUpdatedByActionChange)
this.setQueryParamsInState()
if(!isEqual(prevProps.extraControlFilters, this.props.extraControlFilters))
if(!isEqual(prevProps.extraControlFilters, this.props.extraControlFilters) && !isURLUpdatedByActionChange)
this.setQueryParamsInState()
}

Expand Down Expand Up @@ -279,7 +281,7 @@ class Search extends React.Component {
}

onSearch = (value, exactMatch) => {
this.fetchNewResults({searchStr: value, page: 1, exactMatch: exactMatch}, true, true)
this.fetchNewResults({searchStr: value, page: 1, exactMatch: exactMatch}, true, true, true)
}

onFhirSearch = params => this.setState(
Expand All @@ -299,7 +301,7 @@ class Search extends React.Component {
return {...queryParam, ...viewFilters}
}

fetchNewResults(attrsToSet, counts=true, resetItems=true) {
fetchNewResults(attrsToSet, counts=true, resetItems=true, updateURL=false) {
if(!attrsToSet)
attrsToSet = {}

Expand All @@ -314,6 +316,8 @@ class Search extends React.Component {
resourceState.isLoadingCount = true
})
}
if(!this.props.fhir)
newState.isURLUpdatedByActionChange = true
this.setState(newState, () => {
const {
resource, searchStr, page, exactMatch, sortParams, updatedSince, limit,
Expand Down Expand Up @@ -343,21 +347,27 @@ class Search extends React.Component {
else
params = {...params, page: page, ...fhirParams}
}

fetchSearchResults(
_resource,
params,
!noHeaders,
this.props.baseURL,
null,
response => this.onSearchResultsLoad(resource, response, resetItems)
response => {
if(updateURL && !fhir)
window.location.hash = this.getCurrentLayoutURL()
this.onSearchResultsLoad(resource, response, resetItems)
setTimeout(() => this.setState({isURLUpdatedByActionChange: false}), 1000)
}
)
if(counts && !this.props.nested)
fetchCounts(_resource, queryParams, this.onCountsLoad)
})
}

loadMore = () => {
this.fetchNewResults({page: this.state.page + 1}, false, false);
this.fetchNewResults({page: this.state.page + 1}, false, false, true);
}

onPageChange = page => {
Expand All @@ -371,7 +381,7 @@ class Search extends React.Component {
}
}, () => this.fetchNewResults(null, false, false))
else
this.fetchNewResults({page: page}, false, false)
this.fetchNewResults({page: page}, false, false, true)

}
}
Expand All @@ -385,7 +395,7 @@ class Search extends React.Component {
}, () => this.fetchNewResults(null, false, true))
}
else
this.setState({sortParams: params}, () => this.fetchNewResults(null, false, true))
this.setState({sortParams: params}, () => this.fetchNewResults(null, false, true, true))
}

hasPrev() {
Expand Down Expand Up @@ -418,11 +428,11 @@ class Search extends React.Component {

this.setState(
{resource: resource, appliedFacets: {}, sortParams: {sortDesc: '_score'}, userFilters: {}},
() => this.fetchNewResults(null, shouldGetCounts, true)
() => this.fetchNewResults(null, shouldGetCounts, true, true)
)
}

onDateChange = date => this.fetchNewResults({updatedSince: date}, true, true)
onDateChange = date => this.fetchNewResults({updatedSince: date}, true, true, true)

getUpdatedSinceText() {
const { updatedSince } = this.state;
Expand All @@ -431,13 +441,14 @@ class Search extends React.Component {
return 'All Time'
}

onClickIncludeRetired = () => this.fetchNewResults({includeRetired: !this.state.includeRetired}, true, true)
onClickIncludeRetired = () => this.fetchNewResults({includeRetired: !this.state.includeRetired}, true, true, true)

onLayoutChange = newLayoutId => {
const existingLayoutId = this.getLayoutTypeName()
if(newLayoutId === existingLayoutId)
return
const newState = { ...this.state }
newState.isURLUpdatedByActionChange = true

if(newLayoutId === LIST_LAYOUT_ID) {
newState.isTable = false
Expand All @@ -459,8 +470,12 @@ class Search extends React.Component {
newState.isInfinite = false

this.setState(newState, () => {
window.location.hash = this.getCurrentLayoutURL()

if(includes([newLayoutId, existingLayoutId], SPLIT_LAYOUT_ID) && this.props.onSplitViewToggle)
this.props.onSplitViewToggle()

setTimeout(() => this.setState({isURLUpdatedByActionChange: false}), 1000)
})
}

Expand Down Expand Up @@ -612,7 +627,7 @@ class Search extends React.Component {

onLimitChange = limit => this.props.fhir ?
this.setState({limit: limit, fhirParams: {...this.state.fhirParams, _count: limit, _getpagesoffset: 0}}, () => this.fetchNewResults(null, false, false)) :
this.fetchNewResults({limit: limit}, false, true)
this.fetchNewResults({limit: limit}, false, true, true)

toggleFacetsDrawer = () => this.setState({openFacetsDrawer: !this.state.openFacetsDrawer})

Expand All @@ -630,7 +645,7 @@ class Search extends React.Component {
else
newFilters = omit(newFilters, id)

this.setState({userFilters: newFilters}, () => this.fetchNewResults(null, false, true))
this.setState({userFilters: newFilters}, () => this.fetchNewResults(null, false, true, true))
}

render() {
Expand Down Expand Up @@ -727,7 +742,6 @@ class Search extends React.Component {
fhir={fhir}
hapi={hapi}
history={this.props.history}
currentLayoutURL={this.getCurrentLayoutURL()}
onSelect={onSelect}
/> :
<Results
Expand All @@ -743,7 +757,6 @@ class Search extends React.Component {
onLoadMore={this.loadMore}
noControls={noControls}
history={this.props.history}
currentLayoutURL={this.getCurrentLayoutURL()}
onSelect={onSelect}
splitView={isSplit}
/>
Expand Down
5 changes: 1 addition & 4 deletions src/components/sources/SourceHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ class SourceHome extends React.Component {
}

componentDidUpdate(prevProps) {
if(
(prevProps.location.pathname !== this.props.location.pathname) ||
(prevProps.location.search !== this.props.location.search)
) {
if(prevProps.location.pathname !== this.props.location.pathname) {
this.refreshDataByURL()
this.onTabChange(null, this.getDefaultTabIndex())
}
Expand Down

0 comments on commit f6ab3d7

Please sign in to comment.