Skip to content

Commit

Permalink
Merge pull request #126 from AddSearch/sc-10633/filters-and-facets-ch…
Browse files Browse the repository at this point in the history
…anged-callback

Sc 10633/filters and facets changed callback
  • Loading branch information
haoAddsearch authored Oct 7, 2024
2 parents b3b0238 + 6ef5176 commit 874629d
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 172 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The configuration object can contain following values:
| collectAnalytics | boolean | true | Control if analytics events are collected at all |
| matchAllQuery | boolean | false | Execute "match all" query when the Search UI is started |
| onFilterChange | function | n/a | Function to call when active filters are changed (for conditional visibility) |
| onFilteredSearchRefresh | function | n/a | Function to call when search results are refreshed due to changes in filters or facets |
| searchResultsPageUrl | String | null | Redirect the user to a separate search results page, instead of showing search results on the current page |
| searchParameter | String | "search" | Name of the search parameter which is added to the URL, by default the library adds "?search=" |
| updateBrowserHistory | boolean | true | Set this value to false for a second/third searchui's instance to prevent conflict in browser's URL |
Expand Down
2 changes: 1 addition & 1 deletion dist/addsearch-search-ui.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/addsearch-search-ui.min.js

Large diffs are not rendered by default.

311 changes: 145 additions & 166 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "addsearch-search-ui",
"version": "0.8.14",
"version": "0.8.15",
"description": "JavaScript library to develop Search UIs for the web",
"main": "./dist/addsearch-search-ui.min.js",
"jsdelivr": "./dist/addsearch-search-ui.min.js",
Expand Down
6 changes: 5 additions & 1 deletion src/components/filters/filterstateobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ export function createFilterObject(state, baseFilters, excludedFacetGroup) {
*/
export default class FilterStateObserver {

constructor(client, reduxStore, createFilterObjectFunction, onFilterChange, baseFilters, segmentedSearchClients) {
constructor(client, reduxStore, createFilterObjectFunction, onFilterChange, baseFilters, segmentedSearchClients, onFilteredSearchRefresh) {
this.client = client;
this.reduxStore = reduxStore;
this.createFilterObjectFunction = createFilterObjectFunction;
this.onFilterChange = onFilterChange;
this.onFilteredSearchRefresh = onFilteredSearchRefresh;
this.segmentedSearchClients = segmentedSearchClients;

observeStoreByKey(this.reduxStore, 'filters', state => this.onFilterStateChange(state, baseFilters));
Expand All @@ -140,6 +141,9 @@ export default class FilterStateObserver {
this.segmentedSearchClients[key].client.setFilterObject(segmentFilters);
this.reduxStore.dispatch(segmentedSearch(this.segmentedSearchClients[key].client, key, keyword));
}
if (this.onFilteredSearchRefresh) {
this.onFilteredSearchRefresh();
}
} else if (state.setHistory) {
const filterObject = this.createFilterObjectFunction(state, baseFilters);
this.client.setFilterObject(filterObject);
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class AddSearchUI {

// FilterStateObserver to update client's filter object when any of the filters change
new FilterStateObserver(this.client, this.reduxStore, createFilterObjectFunction, this.settings.onFilterChange,
this.settings.baseFilters, this.segmentedSearchClients);
this.settings.baseFilters, this.segmentedSearchClients, this.settings.onFilteredSearchRefresh);

// Possible match all query on load
if (this.settings.matchAllQuery === true) {
Expand Down

0 comments on commit 874629d

Please sign in to comment.