Skip to content

Commit

Permalink
clearFilters now resets to default filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jan 6, 2023
1 parent 008342d commit f5ea2d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions searchlib/components/SearchApp/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ export function resetSearch(resetState) {
// console.log('reset state', state);
driver._updateSearchResults(state);
}

export function clearFilters(except = []) {
const { setFilter } = this.driver;

this.driver.clearFilters(except);
this.appConfig.facets
.filter((f) => !!f.default)
.forEach((facet) => {
facet.default.values.forEach((value) =>
setFilter(facet.field, value, facet.default.type || 'any'),
);
});
}
8 changes: 7 additions & 1 deletion searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
onAutocompleteResultClick,
} from '@eeacms/search/lib/request';

import { resetFilters, resetSearch } from './request';
import { clearFilters, resetFilters, resetSearch } from './request';
import useFacetsWithAllOptions from './useFacetsWithAllOptions';
import { loadingFamily } from './state';
import { SearchDriver } from '@elastic/search-ui';
Expand Down Expand Up @@ -143,6 +143,12 @@ export default function useSearchApp(props) {
searchContext,
driver,
});

searchContext.clearFilters = clearFilters.bind({
appConfig,
searchContext,
driver,
});
return searchContext;
},
[appConfig, driverInstance, facetOptions],
Expand Down

0 comments on commit f5ea2d1

Please sign in to comment.