@usereactify/search 5.41.0 → 5.43.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 +14 -0
- package/dist/package.json +1 -1
- package/dist/src/components/Sensor/SensorCustom.d.ts +2 -0
- package/dist/src/components/Sensor/SensorCustom.js +16 -0
- package/dist/src/components/Sensor/SensorCustom.js.map +1 -0
- package/dist/src/components/Sensor/SensorSort.js +1 -1
- package/dist/src/components/Sensor/SensorSort.js.map +1 -1
- package/dist/src/components/Sensor/Sensors.js +5 -2
- package/dist/src/components/Sensor/Sensors.js.map +1 -1
- package/dist/src/components/Sensor/index.d.ts +2 -1
- package/dist/src/components/Sensor/index.js +15 -7
- package/dist/src/components/Sensor/index.js.map +1 -1
- package/dist/src/components/Suggestions/Suggestions.js +3 -1
- package/dist/src/components/Suggestions/Suggestions.js.map +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +6 -5
- package/dist/src/hooks/reactivesearch/useReactiveReactProp.js.map +1 -1
- package/dist/src/hooks/useCuration.js +18 -3
- package/dist/src/hooks/useCuration.js.map +1 -1
- package/dist/src/types/config.d.ts +4 -0
- package/dist/src/types/config.js.map +1 -1
- package/package.json +1 -1
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.43.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.42.0...release-v5.43.0) (2024-01-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add support for selecting market-specific global curations ([8e4a042](https://bitbucket.org/usereactify/reactify-search-ui/commit/8e4a042dd896b3e57bed36daaac4b3c85c0df363))
|
|
11
|
+
|
|
12
|
+
## [5.42.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.41.0...release-v5.42.0) (2023-12-18)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add support for custom sensors via config ([71ce82f](https://bitbucket.org/usereactify/reactify-search-ui/commit/71ce82f16630d74d156e3d58fc716d7b9ef36a05))
|
|
18
|
+
|
|
5
19
|
## [5.41.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.40.0...release-v5.41.0) (2023-12-18)
|
|
6
20
|
|
|
7
21
|
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SensorCustom = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const ReactiveComponent_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent"));
|
|
9
|
+
const hooks_1 = require("../../hooks");
|
|
10
|
+
const SensorCustom = () => {
|
|
11
|
+
const reactifySearchContext = (0, hooks_1.useReactifySearchContext)();
|
|
12
|
+
const sensors = reactifySearchContext.options.mode === "collection" ? reactifySearchContext.config.sensors.collection : reactifySearchContext.config.sensors.search;
|
|
13
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, sensors.map((item, index) => react_1.default.createElement(ReactiveComponent_1.default, { componentId: `SensorCustom_${index}`, customQuery: () => item }))));
|
|
14
|
+
};
|
|
15
|
+
exports.SensorCustom = SensorCustom;
|
|
16
|
+
//# sourceMappingURL=SensorCustom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SensorCustom.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorCustom.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAEjG,uCAAuD;AAEhD,MAAM,YAAY,GAAa,GAAG,EAAE;IACzC,MAAM,qBAAqB,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAEzD,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAEpK,OAAO,CACL,8DACG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAC3B,8BAAC,2BAAiB,IAChB,WAAW,EAAE,gBAAgB,KAAK,EAAE,EACpC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,GACvB,CACH,CACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\n\nexport const SensorCustom: React.FC = () => {\n const reactifySearchContext = useReactifySearchContext();\n\n const sensors = reactifySearchContext.options.mode === \"collection\" ? reactifySearchContext.config.sensors.collection : reactifySearchContext.config.sensors.search;\n\n return (\n <>\n {sensors.map((item, index) => \n <ReactiveComponent\n componentId={`SensorCustom_${index}`}\n customQuery={() => item}\n />\n )}\n </>\n );\n};\n"]}
|
|
@@ -172,7 +172,7 @@ const buildQuery = (args) => {
|
|
|
172
172
|
var _a;
|
|
173
173
|
const { curation, sortOption } = args;
|
|
174
174
|
if (!curation ||
|
|
175
|
-
|
|
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,y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C,mBAAmB,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,WA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,EAAE;wBACN,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"]}
|
|
@@ -11,6 +11,7 @@ const SensorPublished_1 = require("./SensorPublished");
|
|
|
11
11
|
const SensorCollection_1 = require("./SensorCollection");
|
|
12
12
|
const SensorSearchTerm_1 = require("./SensorSearchTerm");
|
|
13
13
|
const SensorInventoryAvailable_1 = require("./SensorInventoryAvailable");
|
|
14
|
+
const SensorCustom_1 = require("./SensorCustom");
|
|
14
15
|
const Sensors = () => {
|
|
15
16
|
const { options } = (0, hooks_1.useReactifySearchContext)();
|
|
16
17
|
if (options.mode === "search" || options.mode === "instant-search") {
|
|
@@ -18,14 +19,16 @@ const Sensors = () => {
|
|
|
18
19
|
react_1.default.createElement(SensorSort_1.SensorSort, null),
|
|
19
20
|
react_1.default.createElement(SensorPublished_1.SensorPublished, null),
|
|
20
21
|
react_1.default.createElement(SensorSearchTerm_1.SensorSearchTerm, null),
|
|
21
|
-
react_1.default.createElement(SensorInventoryAvailable_1.SensorInventoryAvailable, null)
|
|
22
|
+
react_1.default.createElement(SensorInventoryAvailable_1.SensorInventoryAvailable, null),
|
|
23
|
+
react_1.default.createElement(SensorCustom_1.SensorCustom, null)));
|
|
22
24
|
}
|
|
23
25
|
if (options.mode === "collection") {
|
|
24
26
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
25
27
|
react_1.default.createElement(SensorSort_1.SensorSort, null),
|
|
26
28
|
react_1.default.createElement(SensorPublished_1.SensorPublished, null),
|
|
27
29
|
react_1.default.createElement(SensorCollection_1.SensorCollection, null),
|
|
28
|
-
react_1.default.createElement(SensorInventoryAvailable_1.SensorInventoryAvailable, null)
|
|
30
|
+
react_1.default.createElement(SensorInventoryAvailable_1.SensorInventoryAvailable, null),
|
|
31
|
+
react_1.default.createElement(SensorCustom_1.SensorCustom, null)));
|
|
29
32
|
}
|
|
30
33
|
return null;
|
|
31
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sensors.js","sourceRoot":"","sources":["../../../../src/components/Sensor/Sensors.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAuD;AAEvD,6CAA0C;AAC1C,uDAAoD;AACpD,yDAAsD;AACtD,yDAAsD;AACtD,yEAAsE;
|
|
1
|
+
{"version":3,"file":"Sensors.js","sourceRoot":"","sources":["../../../../src/components/Sensor/Sensors.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAuD;AAEvD,6CAA0C;AAC1C,uDAAoD;AACpD,yDAAsD;AACtD,yDAAsD;AACtD,yEAAsE;AACtE,iDAA8C;AAMvC,MAAM,OAAO,GAA2B,GAAG,EAAE;IAClD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE;QAClE,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG;YACpB,8BAAC,mDAAwB,OAAG;YAC5B,8BAAC,2BAAY,OAAG,CACf,CACJ,CAAC;KACH;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY,EAAE;QACjC,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG;YACpB,8BAAC,mDAAwB,OAAG;YAC5B,8BAAC,2BAAY,OAAG,CACf,CACJ,CAAC;KACH;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA5BW,QAAA,OAAO,WA4BlB","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\n\nimport { SensorSort } from \"./SensorSort\";\nimport { SensorPublished } from \"./SensorPublished\";\nimport { SensorCollection } from \"./SensorCollection\";\nimport { SensorSearchTerm } from \"./SensorSearchTerm\";\nimport { SensorInventoryAvailable } from \"./SensorInventoryAvailable\";\nimport { SensorCustom } from \"./SensorCustom\";\n\nexport type SensorsProps = {\n /** This component does not support any props */\n};\n\nexport const Sensors: React.FC<SensorsProps> = () => {\n const { options } = useReactifySearchContext();\n\n if (options.mode === \"search\" || options.mode === \"instant-search\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorSearchTerm />\n <SensorInventoryAvailable />\n <SensorCustom />\n </>\n );\n }\n\n if (options.mode === \"collection\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorCollection />\n <SensorInventoryAvailable />\n <SensorCustom />\n </>\n );\n }\n\n return null;\n};\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Config } from "../../types";
|
|
1
2
|
export * from "./SensorSort";
|
|
2
3
|
export * from "./SensorPublished";
|
|
3
4
|
export * from "./SensorCollection";
|
|
4
5
|
export * from "./SensorSearchTerm";
|
|
5
6
|
export * from "./SensorInventoryAvailable";
|
|
6
7
|
export * from "./Sensors";
|
|
7
|
-
export declare const SENSOR_IDS: string[];
|
|
8
|
+
export declare const SENSOR_IDS: (mode: "search" | "collection" | "instant-search", config: Config) => string[];
|
|
@@ -18,11 +18,19 @@ __exportStar(require("./SensorSearchTerm"), exports);
|
|
|
18
18
|
__exportStar(require("./SensorInventoryAvailable"), exports);
|
|
19
19
|
__exportStar(require("./Sensors"), exports);
|
|
20
20
|
// this is consumed by the react prop in various components
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const SENSOR_IDS = (mode, config) => {
|
|
22
|
+
const sensorIds = [
|
|
23
|
+
"SensorSort",
|
|
24
|
+
"SensorPublished",
|
|
25
|
+
"SensorCollection",
|
|
26
|
+
"SensorSearchTerm",
|
|
27
|
+
"SensorInventoryAvailable",
|
|
28
|
+
];
|
|
29
|
+
const customSensors = mode === "collection" ? config.sensors.collection : config.sensors.search;
|
|
30
|
+
if (customSensors.length > 0) {
|
|
31
|
+
sensorIds.push(...customSensors.map((item, index) => `SensorCustom_${index}`));
|
|
32
|
+
}
|
|
33
|
+
return sensorIds;
|
|
34
|
+
};
|
|
35
|
+
exports.SENSOR_IDS = SENSOR_IDS;
|
|
28
36
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Sensor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Sensor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,+CAA6B;AAC7B,oDAAkC;AAClC,qDAAmC;AACnC,qDAAmC;AACnC,6DAA2C;AAE3C,4CAA0B;AAE1B,2DAA2D;AACpD,MAAM,UAAU,GAAG,CAAC,IAAgD,EAAE,MAAc,EAAE,EAAE;IAC7F,MAAM,SAAS,GAAG;QAChB,YAAY;QACZ,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,0BAA0B;KAC3B,CAAC;IACF,MAAM,aAAa,GAAG,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAChG,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,SAAS,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,KAAK,EAAE,CAAC,CAAC,CAAC;KAChF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA;AAdY,QAAA,UAAU,cActB","sourcesContent":["import { Config } from \"../../types\";\n\nexport * from \"./SensorSort\";\nexport * from \"./SensorPublished\";\nexport * from \"./SensorCollection\";\nexport * from \"./SensorSearchTerm\";\nexport * from \"./SensorInventoryAvailable\";\n\nexport * from \"./Sensors\";\n\n// this is consumed by the react prop in various components\nexport const SENSOR_IDS = (mode: \"search\" | \"collection\" | \"instant-search\", config: Config) => {\n const sensorIds = [\n \"SensorSort\",\n \"SensorPublished\",\n \"SensorCollection\",\n \"SensorSearchTerm\",\n \"SensorInventoryAvailable\",\n ];\n const customSensors = mode === \"collection\" ? config.sensors.collection : config.sensors.search;\n if (customSensors.length > 0) {\n sensorIds.push(...customSensors.map((item, index) => `SensorCustom_${index}`));\n }\n\n return sensorIds;\n}"]}
|
|
@@ -10,7 +10,9 @@ const hooks_1 = require("../../hooks");
|
|
|
10
10
|
const Suggestions = (props) => {
|
|
11
11
|
var _a;
|
|
12
12
|
const RenderComponent = (_a = props.render) !== null && _a !== void 0 ? _a : components_1.ExampleSuggestions;
|
|
13
|
+
const reactifySearchContext = (0, hooks_1.useReactifySearchContext)();
|
|
13
14
|
const { searchTerm } = (0, hooks_1.useSearch)();
|
|
15
|
+
const sensorIds = (0, components_1.SENSOR_IDS)(reactifySearchContext.options.mode, reactifySearchContext.config);
|
|
14
16
|
return (react_1.default.createElement(components_1.CustomComponent, { componentId: "SensorSuggestions", defaultQuery: () => {
|
|
15
17
|
return {
|
|
16
18
|
suggest: {
|
|
@@ -25,7 +27,7 @@ const Suggestions = (props) => {
|
|
|
25
27
|
},
|
|
26
28
|
};
|
|
27
29
|
}, react: {
|
|
28
|
-
and:
|
|
30
|
+
and: sensorIds,
|
|
29
31
|
}, render: (renderProps) => {
|
|
30
32
|
var _a, _b, _c;
|
|
31
33
|
const props = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Suggestions.js","sourceRoot":"","sources":["../../../../src/components/Suggestions/Suggestions.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,iDAI0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"Suggestions.js","sourceRoot":"","sources":["../../../../src/components/Suggestions/Suggestions.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,iDAI0B;AAC1B,uCAAkE;AAa3D,MAAM,WAAW,GAA+B,CAAC,KAAK,EAAE,EAAE;;IAC/D,MAAM,eAAe,GAAG,MAAA,KAAK,CAAC,MAAM,mCAAI,+BAAkB,CAAC;IAE3D,MAAM,qBAAqB,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAEzD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE/F,OAAO,CACL,8BAAC,4BAAe,IACd,WAAW,EAAC,mBAAmB,EAC/B,YAAY,EAAE,GAAG,EAAE;YACjB,OAAO;gBACL,OAAO,EAAE;oBACP,WAAW,EAAE;wBACX,IAAI,EAAE,UAAU;wBAChB,IAAI,EAAE;4BACJ,KAAK,EAAE,KAAK,CAAC,KAAK;4BAClB,IAAI,EAAE,OAAO;4BACb,YAAY,EAAE,QAAQ;yBACvB;qBACF;iBACF;aACF,CAAC;QACJ,CAAC,EACD,KAAK,EAAE;YACL,GAAG,EAAE,SAAS;SACf,EACD,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE;;YACtB,MAAM,KAAK,GAEP;gBACF,WAAW,EAAE,EAAE;aAChB,CAAC;YAEF,IAAI,MAAA,MAAA,WAAW,CAAC,OAAO,0CAAE,OAAO,0CAAE,WAAW,CAAC,MAAM,EAAE;gBACpD,MAAM,OAAO,GACX,MAAA,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CACrC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CACnD,0CAAE,OAAO,CAAC;gBACb,KAAK,CAAC,WAAW,CAAC,IAAI,CACpB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAsC,EAAE,EAAE,CAAC,CAAC;oBAC1D,IAAI,EAAE,MAAM,CAAC,IAAI;iBAClB,CAAC,CAAC,CACJ,CAAC;aACH;YAED,OAAO,8BAAC,eAAe,oBAAK,KAAK,EAAI,CAAC;QACxC,CAAC,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AApDW,QAAA,WAAW,eAoDtB","sourcesContent":["import React from \"react\";\n\nimport {\n CustomComponent,\n ExampleSuggestions,\n SENSOR_IDS,\n} from \"../../components\";\nimport { useReactifySearchContext, useSearch } from \"../../hooks\";\n\nexport type SuggestionsProps = {\n /** The field which should be used for autocompletion */\n field: \"title\";\n /** Render method */\n render?: React.FC<{\n suggestions: Array<{\n text: string;\n }>;\n }>;\n};\n\nexport const Suggestions: React.FC<SuggestionsProps> = (props) => {\n const RenderComponent = props.render ?? ExampleSuggestions;\n\n const reactifySearchContext = useReactifySearchContext();\n\n const { searchTerm } = useSearch();\n\n const sensorIds = SENSOR_IDS(reactifySearchContext.options.mode, reactifySearchContext.config);\n\n return (\n <CustomComponent\n componentId=\"SensorSuggestions\"\n defaultQuery={() => {\n return {\n suggest: {\n suggestions: {\n text: searchTerm,\n term: {\n field: props.field,\n sort: \"score\",\n suggest_mode: \"always\",\n },\n },\n },\n };\n }}\n react={{\n and: sensorIds,\n }}\n render={(renderProps) => {\n const props: React.ComponentProps<\n NonNullable<SuggestionsProps[\"render\"]>\n > = {\n suggestions: [],\n };\n\n if (renderProps.rawData?.suggest?.suggestions.length) {\n const options =\n renderProps.rawData.suggest.suggestions[\n renderProps.rawData.suggest.suggestions.length - 1\n ]?.options;\n props.suggestions.push(\n ...options.map((option: { text: string; freq: number }) => ({\n text: option.text,\n }))\n );\n }\n\n return <RenderComponent {...props} />;\n }}\n />\n );\n};\n"]}
|
|
@@ -8,23 +8,24 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const hooks_1 = require("../../hooks");
|
|
9
9
|
const components_1 = require("../../components");
|
|
10
10
|
const useReactiveReactProp = (currentHandle, filter) => {
|
|
11
|
-
const
|
|
11
|
+
const reactifySearchContext = (0, hooks_1.useReactifySearchContext)();
|
|
12
12
|
const { filterStack } = (0, hooks_1.useFilters)();
|
|
13
|
+
const sensorIds = (0, components_1.SENSOR_IDS)(reactifySearchContext.options.mode, reactifySearchContext.config);
|
|
13
14
|
const reactProp = react_1.default.useMemo(() => {
|
|
14
15
|
var _a, _b;
|
|
15
16
|
if (filter && filter.settingsShowEmptyValues) {
|
|
16
17
|
return {
|
|
17
|
-
and:
|
|
18
|
+
and: sensorIds,
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
return {
|
|
21
22
|
and: [
|
|
22
|
-
...
|
|
23
|
-
...((_a = options.additionalComponentIds) !== null && _a !== void 0 ? _a : []),
|
|
23
|
+
...sensorIds,
|
|
24
|
+
...((_a = reactifySearchContext.options.additionalComponentIds) !== null && _a !== void 0 ? _a : []),
|
|
24
25
|
...((_b = filterStack === null || filterStack === void 0 ? void 0 : filterStack.options.map((filter) => filter.handle)) !== null && _b !== void 0 ? _b : []),
|
|
25
26
|
].filter((handle) => handle !== currentHandle),
|
|
26
27
|
};
|
|
27
|
-
}, [filterStack, currentHandle, options.additionalComponentIds]);
|
|
28
|
+
}, [filterStack, currentHandle, reactifySearchContext.options.additionalComponentIds]);
|
|
28
29
|
return reactProp;
|
|
29
30
|
};
|
|
30
31
|
exports.useReactiveReactProp = useReactiveReactProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReactiveReactProp.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactProp.ts"],"names":[],"mappings":";;;;;;AA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AAS,CAAC;AACnB,CAAC,CAAC;AA1BW,QAAA,oBAAoB,wBA0B/B","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext, useFilters } from \"../../hooks\";\nimport { SENSOR_IDS } from \"../../components\";\nimport { ConfigFilterOption } from \"../../types\";\n\nexport const useReactiveReactProp = (\n currentHandle?: string,\n filter?: ConfigFilterOption\n) => {\n const reactifySearchContext = useReactifySearchContext();\n const { filterStack } = useFilters();\n \n const sensorIds = SENSOR_IDS(reactifySearchContext.options.mode, reactifySearchContext.config);\n\n const reactProp = React.useMemo(() => {\n if (filter && filter.settingsShowEmptyValues) {\n return {\n and: sensorIds,\n };\n }\n\n return {\n and: [\n ...sensorIds,\n ...(reactifySearchContext.options.additionalComponentIds ?? []),\n ...(filterStack?.options.map((filter) => filter.handle) ?? []),\n ].filter((handle) => handle !== currentHandle),\n };\n }, [filterStack, currentHandle, reactifySearchContext.options.additionalComponentIds]);\n\n return reactProp;\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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,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,OAAO,QAAQ,CAAC,EAAE,KAAK,eAAe,CAAC;
|
|
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,I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,cAAc,CAAC,QAAQ,GAChB,CAAC;YAEpB,OAAO,0BAA0B,CAAC;QACpC,CAAC,CAAC;QAEF,OAAO,QAAQ;YACb,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC;YAC7B,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC,EAAE;QACD,MAAM;QACN,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;QACpE,UAAU;KACX,CAAC,CAAC;IAEH,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,10 @@ export interface Config {
|
|
|
12
12
|
filters: Array<ConfigFilter>;
|
|
13
13
|
redirects: Array<ConfigRedirect>;
|
|
14
14
|
curations: Array<ConfigCuration>;
|
|
15
|
+
sensors: {
|
|
16
|
+
search: Array<unknown>;
|
|
17
|
+
collection: Array<unknown>;
|
|
18
|
+
};
|
|
15
19
|
}
|
|
16
20
|
export declare type ConfigSort = Omit<Sort, "enabled">;
|
|
17
21
|
export declare type ConfigField = Omit<Field, "enabled">;
|
|
@@ -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}\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 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"]}
|