@usereactify/search 3.12.0-beta.1 → 3.12.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ declare type Props = {
27
27
  index: string;
28
28
  shopifyPermanentDomain: string;
29
29
  configId?: string;
30
- filterStackId?: string;
30
+ filterStackHandle?: string;
31
31
  collection?: Collection;
32
32
  noReactiveBase?: boolean;
33
33
  instantSearch?: boolean;
package/dist/provider.js CHANGED
@@ -38,7 +38,7 @@ const Provider = (_a) => {
38
38
  exports.Provider = Provider;
39
39
  const ConfiguredProvider = (props) => {
40
40
  var _a, _b;
41
- const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase, shopifyPermanentDomain, additionalComponentHandles, onRedirect, } = props;
41
+ const { index, config, children, collection, instantSearch, filterStackHandle, noReactiveBase, shopifyPermanentDomain, additionalComponentHandles, onRedirect, } = props;
42
42
  const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
43
43
  const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
44
44
  typography: {
@@ -107,7 +107,7 @@ const ConfiguredProvider = (props) => {
107
107
  // do not attempt to resolve a filter stack if in instantSearch mode
108
108
  const filterStack = instantSearch
109
109
  ? undefined
110
- : useFilterStack(config, collection, filterStackId);
110
+ : useFilterStack(config, collection, filterStackHandle);
111
111
  const curation = useCuration(config, collection, searchQuery);
112
112
  const contextValue = react_1.default.useMemo(() => ({
113
113
  index,
@@ -187,22 +187,31 @@ const useSortState = (config, collection) => {
187
187
  // @todo we need a better name for the overall page like "Filter Stack" or something,
188
188
  // each block is then called a filter so like Size would be a "Filter" and then each
189
189
  // value within it is a "Filter Option"
190
- const useFilterStack = (config, collection, filterStackId) => react_1.default.useMemo(() => {
191
- var _a;
192
- // manually select filter stack by ID if provided
193
- if (filterStackId) {
194
- const filterStack = config.filters.find((filter) => filterStackId === filter.handle);
195
- if (filterStack)
196
- return filterStack;
190
+ const useFilterStack = (config, collection, filterStackHandle) => react_1.default.useMemo(() => {
191
+ const type = !!collection ? "collection" : "search";
192
+ // exclude filters by type
193
+ const filterStacks = config.filters.filter((filter) => filter.type === type);
194
+ // select filter stack by handle if provided
195
+ if (filterStackHandle) {
196
+ const matchingFilterStack = filterStacks.find((filterStack) => filterStackHandle === filterStack.handle);
197
+ if (matchingFilterStack) {
198
+ return matchingFilterStack;
199
+ }
197
200
  }
198
- // automatically select filter stack by collection if provided
201
+ // select filter stack by collection if provided
199
202
  if (collection === null || collection === void 0 ? void 0 : collection.handle) {
200
- const filterStack = config.filters.find((filter) => { var _a; return (_a = filter.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
201
- if (filterStack)
202
- return filterStack;
203
+ const matchingFilterStack = filterStacks.find((filterStack) => { var _a; return (_a = filterStack.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
204
+ if (matchingFilterStack) {
205
+ return matchingFilterStack;
206
+ }
203
207
  }
204
- const type = !!collection ? "collection" : "search";
205
- return ((_a = config.filters.find((filter) => type === filter.type)) !== null && _a !== void 0 ? _a : config.filters[0]);
208
+ // select filter with "default" handle
209
+ const matchingFilterStack = filterStacks.find((filterStack) => filterStack.handle === "default");
210
+ if (matchingFilterStack) {
211
+ return matchingFilterStack;
212
+ }
213
+ // select any available filter as a last resort
214
+ return config.filters[0];
206
215
  }, [config, collection]);
207
216
  const useCuration = (config, collection, searchQuery) => react_1.default.useMemo(() => {
208
217
  debug("resolveCuration.start", { config, collection, searchQuery });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "3.12.0-beta.1",
4
+ "version": "3.12.0-beta.2",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",