Skip to content

Commit

Permalink
Allow hiding of all filters in a category
Browse files Browse the repository at this point in the history
Expands the functionality of the sidebar filter badges to allow inactivation of all (active) filters in a category.

The choice was made to keep a sidebar badge "active" if any of its constituent filters was active. For example, if there were a mixture of 3 active and 2 inactive country filters (displayed at the top of the page), then the sidebar badge will be active and show "3 x country", with the option to inactivate those 3 filters, or remove all 5.

Closes #1358
  • Loading branch information
jameshadfield committed Jul 9, 2021
1 parent 6fbd8eb commit d81700f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/controls/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class FilterData extends React.Component {
return {
filterName,
displayName: filterBadgeDisplayName(n, this.getFilterTitle(filterName)),
remove: () => {this.props.dispatch(applyFilter("set", filterName, []));}
anyFiltersActive: () => this.props.activeFilters[filterName].filter((f) => f.active).length>0,
remove: () => {this.props.dispatch(applyFilter("set", filterName, []));},
activate: () => {this.props.dispatch(applyFilter("add", filterName, this.props.activeFilters[filterName].map((f) => f.value)));},
inactivate: () => {this.props.dispatch(applyFilter("inactivate", filterName, this.props.activeFilters[filterName].map((f) => f.value)));}
};
});
}
Expand Down Expand Up @@ -138,9 +141,12 @@ class FilterData extends React.Component {
{inUseFilters.map((filter) => (
<div style={{display: 'inline-block', margin: '2px'}} key={filter.displayName}>
<FilterBadge
active
active={filter.anyFiltersActive()}
canMakeInactive
id={filter.displayName}
remove={filter.remove}
activate={filter.activate}
inactivate={filter.inactivate}
onHoverMessage={`Data is currently filtered by ${filter.displayName}`}
>
{filter.displayName}
Expand Down

0 comments on commit d81700f

Please sign in to comment.