@usereactify/search 5.34.0 → 5.35.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [5.35.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.34.0...release-v5.35.0) (2023-09-26)
6
+
7
+
8
+ ### Features
9
+
10
+ * expose selected filters in useFilters hook ([b71613a](https://bitbucket.org/usereactify/reactify-search-ui/commit/b71613ad42483f0e5f9364f0a0b1b5a7b308d137))
11
+
5
12
  ## [5.34.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.33.2...release-v5.34.0) (2023-09-21)
6
13
 
7
14
 
package/dist/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": "5.34.0",
4
+ "version": "5.35.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
@@ -4,6 +4,15 @@ export declare const useFilters: () => {
4
4
  filterStack?: ConfigFilter | undefined;
5
5
  /** All of the available filters within the filter stack */
6
6
  filters?: ConfigFilterOption[] | undefined;
7
+ /** All of the selected filters with their value */
8
+ selected: Array<{
9
+ handle: string;
10
+ value: string | Array<string> | Array<{
11
+ label: string;
12
+ start: number;
13
+ end: number;
14
+ }>;
15
+ }>;
7
16
  /** Clear filter by handle */
8
17
  setFilterValue: (handle: string, value: string | Array<string> | [number, number]) => void;
9
18
  };
@@ -12,6 +12,7 @@ const actions_1 = require("@appbaseio/reactivecore/lib/actions");
12
12
  const hooks_1 = require("../hooks");
13
13
  const utility_1 = require("../utility");
14
14
  const useFilters = () => {
15
+ var _a;
15
16
  const { options, config } = (0, hooks_1.useReactifySearchContext)();
16
17
  const reactivesearchContext = react_1.default.useContext(utils_1.ReactReduxContext);
17
18
  const filterStack = react_1.default.useMemo(() => {
@@ -52,15 +53,25 @@ const useFilters = () => {
52
53
  const sortedFilters = filterStack === null || filterStack === void 0 ? void 0 : filterStack.options.sort((a, b) => a.position > b.position ? 1 : -1);
53
54
  return sortedFilters;
54
55
  }, [filterStack]);
56
+ const selected = react_1.default.useMemo(() => {
57
+ return Object.keys(reactivesearchContext.storeState.selectedValues)
58
+ .filter((item) => filters.find((filter) => filter.handle === item))
59
+ .map((item) => ({
60
+ handle: item,
61
+ value: reactivesearchContext.storeState.selectedValues[item].value,
62
+ }));
63
+ }, [filters, (_a = reactivesearchContext === null || reactivesearchContext === void 0 ? void 0 : reactivesearchContext.storeState) === null || _a === void 0 ? void 0 : _a.selectedValues]);
55
64
  const setFilterValue = react_1.default.useCallback((handle, value) => {
56
65
  utility_1.debug.log("useFilters", "setFilterValue[handle,value]", handle, value);
57
66
  reactivesearchContext.store.dispatch((0, actions_1.setValue)(handle, value));
58
67
  }, [reactivesearchContext]);
59
68
  utility_1.debug.hook("useFilters", "filterStack", filterStack);
60
69
  utility_1.debug.hook("useFilters", "filters", filters);
70
+ utility_1.debug.hook("useFilters", "selected", selected);
61
71
  return {
62
72
  filterStack: filterStack,
63
73
  filters: filters,
74
+ selected: selected,
64
75
  setFilterValue: setFilterValue,
65
76
  };
66
77
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useFilters.js","sourceRoot":"","sources":["../../../src/hooks/useFilters.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,iCAAiC;AACjC,+DAAwE;AACxE,iCAAiC;AACjC,iEAA+D;AAG/D,oCAAoD;AACpD,wCAAmC;AAE5B,MAAM,UAAU,GAAG,GAUxB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,qBAAqB,GAAG,eAAK,CAAC,UAAU,CAAM,yBAAiB,CAAC,CAAC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from \"@appbaseio/reactivesearch/lib/utils\";\n// @ts-expect-error missing types\nimport { setValue } from \"@appbaseio/reactivecore/lib/actions\";\n\nimport { ConfigFilter, ConfigFilterOption } from \"../types\";\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilters = (): {\n /** The currently selected filter stack, based on mode, curation and more */\n filterStack?: ConfigFilter;\n /** All of the available filters within the filter stack */\n filters?: Array<ConfigFilterOption>;\n /** Clear filter by handle */\n setFilterValue: (\n handle: string,\n value: string | Array<string> | [number, number]\n ) => void;\n} => {\n const { options, config } = useReactifySearchContext();\n const reactivesearchContext = React.useContext<any>(ReactReduxContext);\n\n const filterStack = React.useMemo(() => {\n // select filters by type\n const matchingFilterss = config.filters.filter(\n (filter) => filter.type === options.mode\n );\n\n // select filter stack by handle if provided\n if (options.filtersHandle) {\n const matchingFilters = matchingFilterss.find(\n (filterStack) => options.filtersHandle === filterStack.handle\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n }\n\n // select filter stack by collection if provided\n if (options.mode === \"collection\" && options.collectionHandle) {\n const matchingFilters = matchingFilterss.find((filterStack) =>\n filterStack.collections?.includes(options.collectionHandle)\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n }\n\n // select filter with \"default\" handle\n let matchingFilters = matchingFilterss.find(\n (filterStack) => filterStack.handle === \"default\"\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n\n // select any filter with \"default\" handle\n matchingFilters = config.filters.find(\n (filterStack) => filterStack.handle === \"default\"\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n\n // select any available filter as a last resort\n matchingFilters = config.filters[0];\n\n return matchingFilters;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n ]);\n\n const filters = React.useMemo(() => {\n const sortedFilters = filterStack?.options.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n return sortedFilters;\n }, [filterStack]);\n\n const setFilterValue = React.useCallback(\n (\n handle: string,\n value: string | Array<string> | [number, number]\n ): void => {\n debug.log(\"useFilters\", \"setFilterValue[handle,value]\", handle, value);\n reactivesearchContext.store.dispatch(setValue(handle, value));\n },\n [reactivesearchContext]\n );\n\n debug.hook(\"useFilters\", \"filterStack\", filterStack);\n debug.hook(\"useFilters\", \"filters\", filters);\n\n return {\n filterStack: filterStack,\n filters: filters,\n setFilterValue: setFilterValue,\n };\n};\n"]}
1
+ {"version":3,"file":"useFilters.js","sourceRoot":"","sources":["../../../src/hooks/useFilters.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,iCAAiC;AACjC,+DAAwE;AACxE,iCAAiC;AACjC,iEAA+D;AAG/D,oCAAoD;AACpD,wCAAmC;AAE5B,MAAM,UAAU,GAAG,GAmBxB,EAAE;;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,qBAAqB,GAAG,eAAK,CAAC,UAAU,CAAM,yBAAiB,CAAC,CAAC;IAEvE,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,yBAAyB;QACzB,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAC5C,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CACzC,CAAC;QAEF,4CAA4C;QAC5C,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,MAAM,eAAe,GAAG,gBAAgB,CAAC,IAAI,CAC3C,CAAC,WAAW,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,KAAK,WAAW,CAAC,MAAM,CAC9D,CAAC;YACF,IAAI,eAAe,EAAE;gBACnB,OAAO,eAAe,CAAC;aACxB;SACF;QAED,gDAAgD;QAChD,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,OAAO,CAAC,gBAAgB,EAAE;YAC7D,MAAM,eAAe,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,WAAW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U,cAgHrB","sourcesContent":["import React from \"react\";\n// @ts-expect-error missing types\nimport { ReactReduxContext } from \"@appbaseio/reactivesearch/lib/utils\";\n// @ts-expect-error missing types\nimport { setValue } from \"@appbaseio/reactivecore/lib/actions\";\n\nimport { ConfigFilter, ConfigFilterOption } from \"../types\";\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilters = (): {\n /** The currently selected filter stack, based on mode, curation and more */\n filterStack?: ConfigFilter;\n /** All of the available filters within the filter stack */\n filters?: Array<ConfigFilterOption>;\n /** All of the selected filters with their value */\n selected: Array<{\n handle: string;\n value: string | Array<string> | Array<{\n label: string;\n start: number;\n end: number;\n }>;\n }>;\n /** Clear filter by handle */\n setFilterValue: (\n handle: string,\n value: string | Array<string> | [number, number]\n ) => void;\n} => {\n const { options, config } = useReactifySearchContext();\n const reactivesearchContext = React.useContext<any>(ReactReduxContext);\n\n const filterStack = React.useMemo(() => {\n // select filters by type\n const matchingFilterss = config.filters.filter(\n (filter) => filter.type === options.mode\n );\n\n // select filter stack by handle if provided\n if (options.filtersHandle) {\n const matchingFilters = matchingFilterss.find(\n (filterStack) => options.filtersHandle === filterStack.handle\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n }\n\n // select filter stack by collection if provided\n if (options.mode === \"collection\" && options.collectionHandle) {\n const matchingFilters = matchingFilterss.find((filterStack) =>\n filterStack.collections?.includes(options.collectionHandle)\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n }\n\n // select filter with \"default\" handle\n let matchingFilters = matchingFilterss.find(\n (filterStack) => filterStack.handle === \"default\"\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n\n // select any filter with \"default\" handle\n matchingFilters = config.filters.find(\n (filterStack) => filterStack.handle === \"default\"\n );\n if (matchingFilters) {\n return matchingFilters;\n }\n\n // select any available filter as a last resort\n matchingFilters = config.filters[0];\n\n return matchingFilters;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n ]);\n\n const filters = React.useMemo(() => {\n const sortedFilters = filterStack?.options.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n return sortedFilters;\n }, [filterStack]);\n\n const selected = React.useMemo(() => {\n return Object.keys(reactivesearchContext.storeState.selectedValues)\n .filter((item) => filters.find((filter) => filter.handle === item))\n .map((item) => ({\n handle: item,\n value: reactivesearchContext.storeState.selectedValues[item].value,\n }));\n }, [filters, reactivesearchContext?.storeState?.selectedValues]);\n\n const setFilterValue = React.useCallback(\n (\n handle: string,\n value: string | Array<string> | [number, number]\n ): void => {\n debug.log(\"useFilters\", \"setFilterValue[handle,value]\", handle, value);\n reactivesearchContext.store.dispatch(setValue(handle, value));\n },\n [reactivesearchContext]\n );\n\n debug.hook(\"useFilters\", \"filterStack\", filterStack);\n debug.hook(\"useFilters\", \"filters\", filters);\n debug.hook(\"useFilters\", \"selected\", selected);\n\n return {\n filterStack: filterStack,\n filters: filters,\n selected: selected,\n setFilterValue: setFilterValue,\n };\n};\n"]}
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": "5.34.0",
4
+ "version": "5.35.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",