@usereactify/search 5.42.0 → 5.44.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,20 @@
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.44.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.43.0...release-v5.44.0) (2024-01-10)
6
+
7
+
8
+ ### Features
9
+
10
+ * update config types to include markets field ([508c6b3](https://bitbucket.org/usereactify/reactify-search-ui/commit/508c6b3c28209ef250a7020dad8eb3147060dcb8))
11
+
12
+ ## [5.43.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.42.0...release-v5.43.0) (2024-01-08)
13
+
14
+
15
+ ### Features
16
+
17
+ * add support for selecting market-specific global curations ([8e4a042](https://bitbucket.org/usereactify/reactify-search-ui/commit/8e4a042dd896b3e57bed36daaac4b3c85c0df363))
18
+
5
19
  ## [5.42.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.41.0...release-v5.42.0) (2023-12-18)
6
20
 
7
21
 
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.42.0",
4
+ "version": "5.44.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
@@ -172,7 +172,7 @@ const buildQuery = (args) => {
172
172
  var _a;
173
173
  const { curation, sortOption } = args;
174
174
  if (!curation ||
175
- ["global_collection", "global_search"].includes(curation.id)) {
175
+ curation.id.includes("global")) {
176
176
  return undefined;
177
177
  }
178
178
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAA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BAAmB,EAAE,eAAe,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAC5D;QACA,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI,EAAE;YACJ,QAAQ,EAAE;gBACR;oBACE,MAAM,EAAE;wBACN,IAAI,EAAE,WAAW;wBACjB,KAAK,EAAE;4BACL,IAAI,EAAE;gCACJ,IAAI,EAAE;oCACJ;wCACE,IAAI,EAAE;4CACJ,CAAC,aACC,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,kBAAkB;gDACpB,CAAC,CAAC,YACN,UAAU,CAAC,EACT,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,QAAQ,CAAC,gBAAgB;gDAC3B,CAAC,CAAC,MAAA,QAAQ,CAAC,UAAU,0CAAE,WAAW,EAAE;yCACzC;qCACF;oCACD;wCACE,IAAI,EAAE;4CACJ,kBAAkB,EAAE,IAAI;yCACzB;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;gBACD,kEAAkE;gBAClE,GAAG,CAAC,UAAU;oBACd,CAAC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;oBAC5D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE;gCACJ,IAAI,EAAE,SAAS;6BAChB;yBACF;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { ConfigCuration, ConfigSort } from \"../../types\";\nimport {\n useReactifySearchContext,\n useSortBy,\n useCuration,\n ReactifySearchMode,\n useFlags,\n} from \"../../hooks\";\n\nexport const SensorSort: React.FC = () => {\n const flagsHook = useFlags();\n const { options, config } = useReactifySearchContext();\n const { curation } = useCuration();\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n mode: options.mode,\n market: options.market,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n }),\n };\n }, [options, config, sortOption, curation]);\n\n if (!flagsHook.flags[\"reactify-search:flag_sensor_sort\"]) {\n return null;\n }\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n mode: ReactifySearchMode;\n market?: string;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { mode, curation, sortOption, collectionHandle } = args;\n\n // curation positions are only applied for the default `collections.position` or `_score` sort\n // if the sort is something else, apply a normal sort which applies what the user has requested\n if (mode !== \"instant-search\") {\n if (\n sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n }\n\n const sorts = [];\n\n // collection curation pin sorting\n if (mode === \"collection\" && collectionHandle) {\n if (curation?.collectionHandle) {\n const queries: Array<unknown> = [{\n term: {\n \"curations.collectionHandle.keyword\": curation.collectionHandle,\n },\n }];\n if (args.market) {\n queries.push({\n term: {\n \"curations.markets.keyword\": args.market,\n },\n });\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queries\n }\n }\n },\n },\n });\n }\n }\n\n // search curation pin sorting\n if (mode === \"search\" || mode === \"instant-search\") {\n if (curation?.searchTerm) {\n const queries: Array<unknown> = [{\n term: {\n \"curations.searchTerm.keyword\": curation.searchTerm.toLowerCase(),\n },\n }];\n if (args.market) {\n queries.push({\n term: {\n \"curations.markets.keyword\": args.market,\n },\n });\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queries\n }\n }\n },\n },\n });\n }\n }\n\n // curation boost sorting\n if (curation) {\n if (0 < curation.boosting.groupings.length) {\n const groupings = curation.boosting.groupings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const grouping of groupings) {\n try {\n const query = JSON.parse(grouping.query);\n if (query) sorts.push(query);\n } catch {\n console.error(\n `query could not be parsed for boost grouping`,\n grouping\n );\n }\n }\n }\n\n if (0 < curation.boosting.sortings.length) {\n const sortings = curation.boosting.sortings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n const query = JSON.parse(sorting.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n }\n\n // default collection sorting\n if (mode === \"collection\" && collectionHandle) {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n }\n\n // default search sorting\n if (mode === \"search\" || mode === \"instant-search\") {\n sorts.push(\"_score\");\n }\n\n return sorts;\n};\n\n/**\n * Return a sort clause which sorts by position within the given collection.\n */\nfunction mapCollectionPositionSortClause(collectionHandle: string) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collectionHandle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n}): Record<string, any> | undefined => {\n const { curation, sortOption } = args;\n\n if (\n !curation ||\n [\"global_collection\", \"global_search\"].includes(curation.id)\n ) {\n return undefined;\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: [\n {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n },\n ],\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
1
+ {"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAGjG,uCAMqB;AAEd,MAAM,UAAU,GAAa,GAAG,EAAE;IACvC,MAAM,SAAS,GAAG,IAAA,gBAAQ,GAAE,CAAC;IAC7B,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,mBAAW,GAAE,CAAC;IACnC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACzC,OAAO;YACL,IAAI,EAAE,SAAS,CAAC;gBACd,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,QAAQ;gBACR,UAAU;gBACV,gBAAgB,EACd,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;aACvE,CAAC;YACF,KAAK,EAAE,UAAU,CAAC;gBAChB,UAAU;gBACV,QAAQ;aACT,CAAC;SACH,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,kCAAkC,CAAC,EAAE;QACxD,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,8BAAC,2BAAiB,IAChB,WAAW,EAAC,YAAY,EACxB,WAAW,EAAE,G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N,IAAI,EAAE;4BACJ,4BAA4B,EAAE,gBAAgB;yBAC/C;qBACF;iBACF;aACF;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,IAGnB,EAAmC,EAAE;;IACpC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEtC,IACE,CAAC,QAAQ;QACT,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC9B;QACA,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI,EAAE;YACJ,QAAQ,EAAE;gBACR;oBACE,MAAM,EAAE;wBACN,IAAI,EAAE,WAAW;wBACjB,KAAK,EAAE;4BACL,IAAI,EAAE;gCACJ,IAAI,EAAE;oCACJ;wCACE,IAAI,EAAE;4CACJ,CAAC,aACC,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,kBAAkB;gDACpB,CAAC,CAAC,YACN,UAAU,CAAC,EACT,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,QAAQ,CAAC,gBAAgB;gDAC3B,CAAC,CAAC,MAAA,QAAQ,CAAC,UAAU,0CAAE,WAAW,EAAE;yCACzC;qCACF;oCACD;wCACE,IAAI,EAAE;4CACJ,kBAAkB,EAAE,IAAI;yCACzB;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;gBACD,kEAAkE;gBAClE,GAAG,CAAC,UAAU;oBACd,CAAC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;oBAC5D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE;gCACJ,IAAI,EAAE,SAAS;6BAChB;yBACF;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { ConfigCuration, ConfigSort } from \"../../types\";\nimport {\n useReactifySearchContext,\n useSortBy,\n useCuration,\n ReactifySearchMode,\n useFlags,\n} from \"../../hooks\";\n\nexport const SensorSort: React.FC = () => {\n const flagsHook = useFlags();\n const { options, config } = useReactifySearchContext();\n const { curation } = useCuration();\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n mode: options.mode,\n market: options.market,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n }),\n };\n }, [options, config, sortOption, curation]);\n\n if (!flagsHook.flags[\"reactify-search:flag_sensor_sort\"]) {\n return null;\n }\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n mode: ReactifySearchMode;\n market?: string;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { mode, curation, sortOption, collectionHandle } = args;\n\n // curation positions are only applied for the default `collections.position` or `_score` sort\n // if the sort is something else, apply a normal sort which applies what the user has requested\n if (mode !== \"instant-search\") {\n if (\n sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n }\n\n const sorts = [];\n\n // collection curation pin sorting\n if (mode === \"collection\" && collectionHandle) {\n if (curation?.collectionHandle) {\n const queries: Array<unknown> = [{\n term: {\n \"curations.collectionHandle.keyword\": curation.collectionHandle,\n },\n }];\n if (args.market) {\n queries.push({\n term: {\n \"curations.markets.keyword\": args.market,\n },\n });\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queries\n }\n }\n },\n },\n });\n }\n }\n\n // search curation pin sorting\n if (mode === \"search\" || mode === \"instant-search\") {\n if (curation?.searchTerm) {\n const queries: Array<unknown> = [{\n term: {\n \"curations.searchTerm.keyword\": curation.searchTerm.toLowerCase(),\n },\n }];\n if (args.market) {\n queries.push({\n term: {\n \"curations.markets.keyword\": args.market,\n },\n });\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queries\n }\n }\n },\n },\n });\n }\n }\n\n // curation boost sorting\n if (curation) {\n if (0 < curation.boosting.groupings.length) {\n const groupings = curation.boosting.groupings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const grouping of groupings) {\n try {\n const query = JSON.parse(grouping.query);\n if (query) sorts.push(query);\n } catch {\n console.error(\n `query could not be parsed for boost grouping`,\n grouping\n );\n }\n }\n }\n\n if (0 < curation.boosting.sortings.length) {\n const sortings = curation.boosting.sortings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n const query = JSON.parse(sorting.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n }\n\n // default collection sorting\n if (mode === \"collection\" && collectionHandle) {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n }\n\n // default search sorting\n if (mode === \"search\" || mode === \"instant-search\") {\n sorts.push(\"_score\");\n }\n\n return sorts;\n};\n\n/**\n * Return a sort clause which sorts by position within the given collection.\n */\nfunction mapCollectionPositionSortClause(collectionHandle: string) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collectionHandle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n}): Record<string, any> | undefined => {\n const { curation, sortOption } = args;\n\n if (\n !curation ||\n curation.id.includes(\"global\")\n ) {\n return undefined;\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: [\n {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n },\n ],\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
@@ -17,13 +17,28 @@ const useCuration = () => {
17
17
  .trim();
18
18
  const globalCuration = config.curations.find((curation) => {
19
19
  if (options.mode === "search") {
20
- return curation.id === "global_search";
20
+ if (options.market) {
21
+ return curation.id === `global_${options.market}_search`;
22
+ }
23
+ else {
24
+ return curation.id === "global_search";
25
+ }
21
26
  }
22
27
  if (options.mode === "instant-search") {
23
- return curation.id === "global_search";
28
+ if (options.market) {
29
+ return curation.id === `global_${options.market}_search`;
30
+ }
31
+ else {
32
+ return curation.id === "global_search";
33
+ }
24
34
  }
25
35
  if (options.mode === "collection") {
26
- return curation.id === "global_collection";
36
+ if (options.market) {
37
+ return curation.id === `global_${options.market}_collection`;
38
+ }
39
+ else {
40
+ return curation.id === "global_collection";
41
+ }
27
42
  }
28
43
  return false;
29
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"useCuration.js","sourceRoot":"","sources":["../../../src/hooks/useCuration.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAA+D;AAC/D,wCAAmC;AAE5B,MAAM,WAAW,GAAG,GAEzB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,QAAQ,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAClC,MAAM,kBAAkB,GACt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EH,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO;QACL,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC,CAAC;AA3GW,QAAA,WAAW,eA2GtB","sourcesContent":["import React from \"react\";\n\nimport { ConfigCuration } from \"../types\";\nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): {\n curation?: ConfigCuration;\n} => {\n const { options, config } = useReactifySearchContext();\n const { searchTerm } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchTerm;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find((curation) => {\n if (options.mode === \"search\") {\n return curation.id === \"global_search\";\n }\n if (options.mode === \"instant-search\") {\n return curation.id === \"global_search\";\n }\n if (options.mode === \"collection\") {\n return curation.id === \"global_collection\";\n }\n return false;\n });\n\n const curation = config.curations.find((curation) => {\n if (options.market) {\n if (curation.markets && !curation.markets.includes(options.market)) {\n return false;\n }\n }\n\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\n\n if (\"instant-search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"collection\" === options.mode) {\n return (\n \"collection\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedCollectionHandle\n );\n }\n\n return false;\n });\n\n const addGlobalBoosting = (curation: ConfigCuration) => {\n if (!globalCuration) {\n return curation;\n }\n\n const curationIsCollection = curation.type === \"collection\";\n if (!curationIsCollection) {\n return curation;\n }\n\n const curationHasRules =\n !!curation.boosting.groupings.length ||\n !!curation.boosting.sortings.length;\n\n if (curationHasRules) {\n return curation;\n }\n\n const curationWithGlobalBoosting = {\n ...curation,\n boosting: globalCuration.boosting,\n } as ConfigCuration;\n\n return curationWithGlobalBoosting;\n };\n\n return curation\n ? addGlobalBoosting(curation)\n : globalCuration\n ? globalCuration\n : undefined;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n searchTerm,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return {\n curation: curation,\n };\n};\n"]}
1
+ {"version":3,"file":"useCuration.js","sourceRoot":"","sources":["../../../src/hooks/useCuration.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAA+D;AAC/D,wCAAmC;AAE5B,MAAM,WAAW,GAAG,GAEzB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,QAAQ,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAClC,MAAM,kBAAkB,GACtB,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC;QAExE,MAAM,4BAA4B,GAAG,kBAAkB;aACpD,WAAW,EAAE;aACb,IAAI,EAAE,CAAC;QAEV,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACxD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC7B,IAAI,OAAO,CAAC,MAAM,EAAE;oBAClB,OAAO,QAAQ,CAAC,EAAE,KAAK,UAAU,OAAO,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eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO;QACL,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC,CAAC;AAvHW,QAAA,WAAW,eAuHtB","sourcesContent":["import React from \"react\";\n\nimport { ConfigCuration } from \"../types\";\nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): {\n curation?: ConfigCuration;\n} => {\n const { options, config } = useReactifySearchContext();\n const { searchTerm } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchTerm;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find((curation) => {\n if (options.mode === \"search\") {\n if (options.market) {\n return curation.id === `global_${options.market}_search`;\n } else {\n return curation.id === \"global_search\";\n }\n }\n if (options.mode === \"instant-search\") {\n if (options.market) {\n return curation.id === `global_${options.market}_search`;\n } else {\n return curation.id === \"global_search\";\n }\n }\n if (options.mode === \"collection\") {\n if (options.market) {\n return curation.id === `global_${options.market}_collection`;\n } else {\n return curation.id === \"global_collection\";\n }\n }\n return false;\n });\n\n const curation = config.curations.find((curation) => {\n if (options.market) {\n if (curation.markets && !curation.markets.includes(options.market)) {\n return false;\n }\n }\n\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\n\n if (\"instant-search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"collection\" === options.mode) {\n return (\n \"collection\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedCollectionHandle\n );\n }\n\n return false;\n });\n\n const addGlobalBoosting = (curation: ConfigCuration) => {\n if (!globalCuration) {\n return curation;\n }\n\n const curationIsCollection = curation.type === \"collection\";\n if (!curationIsCollection) {\n return curation;\n }\n\n const curationHasRules =\n !!curation.boosting.groupings.length ||\n !!curation.boosting.sortings.length;\n\n if (curationHasRules) {\n return curation;\n }\n\n const curationWithGlobalBoosting = {\n ...curation,\n boosting: globalCuration.boosting,\n } as ConfigCuration;\n\n return curationWithGlobalBoosting;\n };\n\n return curation\n ? addGlobalBoosting(curation)\n : globalCuration\n ? globalCuration\n : undefined;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n searchTerm,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return {\n curation: curation,\n };\n};\n"]}
@@ -12,6 +12,7 @@ export interface Config {
12
12
  filters: Array<ConfigFilter>;
13
13
  redirects: Array<ConfigRedirect>;
14
14
  curations: Array<ConfigCuration>;
15
+ markets: Array<ConfigMarket>;
15
16
  sensors: {
16
17
  search: Array<unknown>;
17
18
  collection: Array<unknown>;
@@ -34,3 +35,9 @@ export declare type ConfigCuration = Omit<Curation, "keywords" | "boosting" | "l
34
35
  })[];
35
36
  };
36
37
  };
38
+ export declare type ConfigMarket = {
39
+ id: string;
40
+ label: string;
41
+ handle: string;
42
+ enabled: boolean;
43
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Sort,\n Filter,\n FilterOption,\n Redirect,\n Field,\n Curation,\n} from \"./firestore\";\n\n// when exposed as config, most resources have the `enabled` and `keywords` attributes removed\n// curation boosting groupings and sortings both have a json encoded elastic query added to them\nexport interface Config {\n index: string;\n endpoint: string;\n version: string;\n cache: {\n enabled: boolean;\n seconds: number;\n };\n sort: Array<ConfigSort>;\n fields: Array<ConfigField>;\n filters: Array<ConfigFilter>;\n redirects: Array<ConfigRedirect>;\n curations: Array<ConfigCuration>;\n sensors: {\n search: Array<unknown>;\n collection: Array<unknown>;\n };\n}\n\nexport type ConfigSort = Omit<Sort, \"enabled\">;\nexport type ConfigField = Omit<Field, \"enabled\">;\nexport type ConfigRedirect = Omit<Redirect, \"enabled\" | \"keywords\">;\nexport type ConfigFilter = Omit<Filter, \"enabled\" | \"keywords\"> & {\n options: Omit<FilterOption, \"enabled\">[];\n};\nexport type ConfigFilterOption = Omit<FilterOption, \"enabled\">;\nexport type ConfigCuration = Omit<\n Curation,\n \"keywords\" | \"boosting\" | \"longRunningTask\" | \"callouts\"\n> & {\n boosting: {\n groupings: (NonNullable<\n NonNullable<Curation[\"boosting\"]>[\"groupings\"]\n >[0] & { query: string })[];\n sortings: (NonNullable<NonNullable<Curation[\"boosting\"]>[\"sortings\"]>[0] & {\n query: string;\n })[];\n };\n};\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Sort,\n Filter,\n FilterOption,\n Redirect,\n Field,\n Curation,\n} from \"./firestore\";\n\n// when exposed as config, most resources have the `enabled` and `keywords` attributes removed\n// curation boosting groupings and sortings both have a json encoded elastic query added to them\nexport interface Config {\n index: string;\n endpoint: string;\n version: string;\n cache: {\n enabled: boolean;\n seconds: number;\n };\n sort: Array<ConfigSort>;\n fields: Array<ConfigField>;\n filters: Array<ConfigFilter>;\n redirects: Array<ConfigRedirect>;\n curations: Array<ConfigCuration>;\n markets: Array<ConfigMarket>;\n sensors: {\n search: Array<unknown>;\n collection: Array<unknown>;\n };\n}\n\nexport type ConfigSort = Omit<Sort, \"enabled\">;\nexport type ConfigField = Omit<Field, \"enabled\">;\nexport type ConfigRedirect = Omit<Redirect, \"enabled\" | \"keywords\">;\nexport type ConfigFilter = Omit<Filter, \"enabled\" | \"keywords\"> & {\n options: Omit<FilterOption, \"enabled\">[];\n};\nexport type ConfigFilterOption = Omit<FilterOption, \"enabled\">;\nexport type ConfigCuration = Omit<\n Curation,\n \"keywords\" | \"boosting\" | \"longRunningTask\" | \"callouts\"\n> & {\n boosting: {\n groupings: (NonNullable<\n NonNullable<Curation[\"boosting\"]>[\"groupings\"]\n >[0] & { query: string })[];\n sortings: (NonNullable<NonNullable<Curation[\"boosting\"]>[\"sortings\"]>[0] & {\n query: string;\n })[];\n };\n};\nexport type ConfigMarket = {\n id: string;\n label: string;\n handle: string;\n enabled: boolean;\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.42.0",
4
+ "version": "5.44.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",