Skip to content

Commit

Permalink
Added modified HOCs to handle filter persist. Added WithSavedFilters …
Browse files Browse the repository at this point in the history
…as wrapper for TaskBundleWidget to facilitate saves
  • Loading branch information
AndrewPhilbin committed Aug 11, 2023
1 parent 8c35eb6 commit e159934
Show file tree
Hide file tree
Showing 6 changed files with 869 additions and 158 deletions.
32 changes: 0 additions & 32 deletions src/components/HOCs/WithFilterCriteria/WithFilterCriteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,

updateCriteria = (newCriteria) => {
const criteria = _cloneDeep(this.state.criteria)
console.log('filter criteria in updateCriteria', criteria)
criteria.sortCriteria = newCriteria.sortCriteria
criteria.page = newCriteria.page
criteria.filters = newCriteria.filters
Expand All @@ -59,7 +58,6 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,

updateTaskPropertyCriteria = (propertySearch) => {
const criteria = _cloneDeep(this.state.criteria)
console.log('filter added in updateTaskPropertyCriteria', propertySearch)
criteria.filters.taskPropertySearch = propertySearch
this.setState({criteria})
}
Expand All @@ -81,20 +79,17 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,

clearAllFilters = () => {
if (this.props.clearAllFilters) {
console.log('is upstream clear filters running?')
this.props.clearAllFilters()
}

const newCriteria = _cloneDeep(DEFAULT_CRITERIA)

newCriteria.boundingBox = null
newCriteria.zoom = this.state.zoom
newCriteria.filters["status"] = _keys(_pickBy(this.props.includeTaskStatuses, (s) => s))
newCriteria.filters["reviewStatus"] = _keys(_pickBy(this.props.includeReviewStatuses, (r) => r))
newCriteria.filters["metaReviewStatus"] = _keys(_pickBy(this.props.includeMetaReviewStatuses, (r) => r))
newCriteria.filters["priorities"] = _keys(_pickBy(this.props.includeTaskPriorities, (p) => p))


if (!ignoreURL) {
this.props.history.push({
pathname: this.props.history.location.pathname,
Expand All @@ -105,30 +100,6 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,
this.setState({criteria: newCriteria, loading: true})
}

// Alternate clear function to maintain map zoom and bounding box when clearing filters

clearAllFiltersAndMaintainMapState = () => {

// Runs upstream clear function, specifically in HOCs that manage filter state and pass filter statuses to this component.

if (this.props.clearAllFilters) {
console.log('is this running?')
this.props.clearAllFilters()
}

const newCriteria = _cloneDeep(DEFAULT_CRITERIA)

newCriteria.boundingBox = this.state.criteria.boundingBox
newCriteria.zoom = this.state.criteria.zoom
newCriteria.filters["status"] = _keys(_pickBy(this.props.includeTaskStatuses, (s) => s))
newCriteria.filters["reviewStatus"] = _keys(_pickBy(this.props.includeReviewStatuses, (r) => r))
newCriteria.filters["metaReviewStatus"] = _keys(_pickBy(this.props.includeMetaReviewStatuses, (r) => r))
newCriteria.filters["priorities"] = _keys(_pickBy(this.props.includeTaskPriorities, (p) => p))

this.setState({criteria: newCriteria, loading: true})

}

changePageSize = (pageSize) => {
const typedCriteria = _cloneDeep(this.state.criteria)
typedCriteria.pageSize = pageSize
Expand All @@ -146,7 +117,6 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,

updateIncludedFilters(props, criteria = {}) {
const typedCriteria = _merge({}, criteria, _cloneDeep(this.state.criteria))
console.log('typedCriteria in updateIncludedFilters', typedCriteria)
typedCriteria.filters["status"] = _keys(_pickBy(props.includeTaskStatuses, (s) => s))
typedCriteria.filters["reviewStatus"] = _keys(_pickBy(props.includeTaskReviewStatuses, (r) => r))
typedCriteria.filters["metaReviewStatus"] = _keys(_pickBy(props.includeMetaReviewStatuses, (r) => r))
Expand Down Expand Up @@ -256,7 +226,6 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,
}

componentDidUpdate(prevProps, prevState) {
console.log('update ran in withfiltercriteria')
const challengeId = _get(this.props, 'challenge.id') || this.props.challengeId
if (!challengeId) {
return
Expand Down Expand Up @@ -316,7 +285,6 @@ export const WithFilterCriteria = function(WrappedComponent, ignoreURL = true,
updateCriteria={this.updateCriteria}
refreshTasks={this.refreshTasks}
clearAllFilters={this.clearAllFilters}
clearAllFiltersAndMaintainMapState={this.clearAllFiltersAndMaintainMapState}
{..._omit(this.props, ['loadingChallenge', 'clearAllFilters'])} />)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function WithFilteredClusteredTasks(WrappedComponent,
initialFilters) {
return class extends Component {
defaultFilters = () => {
console.log('initialfilters in defaultFilters', initialFilters)

return {
includeStatuses: _get(initialFilters, 'statuses',
_fromPairs(_map(TaskStatus, status => [status, true]))),
Expand Down Expand Up @@ -282,8 +282,6 @@ export default function WithFilteredClusteredTasks(WrappedComponent,

setupFilters = () => {
let useURLFilters = false
console.log('history location search prop in setupFilters', this.props.history.location.search)
console.log('history location state prop in setupFilters', this.props.history.location.state)
const criteria =
this.props.history.location.search ?
buildSearchCriteriafromURL(this.props.history.location.search) :
Expand Down Expand Up @@ -343,7 +341,6 @@ export default function WithFilteredClusteredTasks(WrappedComponent,
}

componentDidMount() {
console.log('does this run in other workflow contexts?')
this.setupFilters()
}

Expand Down
Loading

0 comments on commit e159934

Please sign in to comment.