@usereactify/search 5.0.0-beta.12 → 5.0.0-beta.13
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 +13 -0
- package/README.md +3 -21
- package/dist/package.json +1 -1
- package/dist/src/components/Example/ExampleFilters.d.ts +4 -0
- package/dist/src/components/Example/{ExampleFilterStack.js → ExampleFilters.js} +4 -4
- package/dist/src/components/Example/ExampleFilters.js.map +1 -0
- package/dist/src/components/Example/ExampleSortBy.d.ts +4 -0
- package/dist/src/components/Example/{ExampleSortby.js → ExampleSortBy.js} +4 -4
- package/dist/src/components/Example/{ExampleSortby.js.map → ExampleSortBy.js.map} +1 -1
- package/dist/src/components/Example/index.d.ts +2 -2
- package/dist/src/components/Example/index.js +2 -2
- package/dist/src/components/Example/index.js.map +1 -1
- package/dist/src/components/Filter/Filters.d.ts +7 -0
- package/dist/src/components/Filter/{FilterStack.js → Filters.js} +6 -6
- package/dist/src/components/Filter/Filters.js.map +1 -0
- package/dist/src/components/Filter/index.d.ts +1 -1
- package/dist/src/components/Filter/index.js +1 -1
- package/dist/src/components/Filter/index.js.map +1 -1
- package/dist/src/components/{ReactifySearchBase/ReactifySearchBase.d.ts → ReactifySearchProvider/ReactifySearchProvider.d.ts} +5 -9
- package/dist/src/components/{ReactifySearchBase/ReactifySearchBase.js → ReactifySearchProvider/ReactifySearchProvider.js} +12 -11
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -0
- package/dist/src/components/ReactifySearchProvider/index.d.ts +1 -0
- package/dist/src/components/{ReactifySearchBase → ReactifySearchProvider}/index.js +1 -1
- package/dist/src/components/ReactifySearchProvider/index.js.map +1 -0
- package/dist/src/components/Result/{ResultStack.d.ts → Results.d.ts} +2 -2
- package/dist/src/components/Result/{ResultStack.js → Results.js} +43 -26
- package/dist/src/components/Result/Results.js.map +1 -0
- package/dist/src/components/Result/index.d.ts +1 -1
- package/dist/src/components/Result/index.js +1 -1
- package/dist/src/components/Result/index.js.map +1 -1
- package/dist/src/components/Sensor/SensorCollection.js +2 -2
- package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
- package/dist/src/components/Sensor/SensorInventoryAvailable.js +1 -1
- package/dist/src/components/Sensor/SensorInventoryAvailable.js.map +1 -1
- package/dist/src/components/Sensor/SensorSort.js +13 -13
- package/dist/src/components/Sensor/SensorSort.js.map +1 -1
- package/dist/src/components/Sensor/Sensors.d.ts +3 -0
- package/dist/src/components/Sensor/{SensorStack.js → Sensors.js} +4 -4
- package/dist/src/components/Sensor/Sensors.js.map +1 -0
- package/dist/src/components/Sensor/index.d.ts +1 -1
- package/dist/src/components/Sensor/index.js +1 -1
- package/dist/src/components/Sensor/index.js.map +1 -1
- package/dist/src/components/SortBy/SortBy.d.ts +7 -0
- package/dist/src/components/{Sortby/Sortby.js → SortBy/SortBy.js} +7 -7
- package/dist/src/components/SortBy/SortBy.js.map +1 -0
- package/dist/src/components/SortBy/index.d.ts +1 -0
- package/dist/src/components/{Sortby → SortBy}/index.js +1 -1
- package/dist/src/components/{Sortby → SortBy}/index.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -2
- package/dist/src/components/index.js +2 -2
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/hooks/index.d.ts +2 -3
- package/dist/src/hooks/index.js +2 -3
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveReactProp.js +4 -4
- package/dist/src/hooks/reactivesearch/useReactiveReactProp.js.map +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveReactiveListProps.js +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveReactiveListProps.js.map +1 -1
- package/dist/src/hooks/useCuration.js +2 -6
- package/dist/src/hooks/useCuration.js.map +1 -1
- package/dist/src/hooks/useFilters.d.ts +3 -2
- package/dist/src/hooks/useFilters.js +45 -11
- package/dist/src/hooks/useFilters.js.map +1 -1
- package/dist/src/hooks/usePaginationLoadMore.js +1 -1
- package/dist/src/hooks/usePaginationLoadMore.js.map +1 -1
- package/dist/src/hooks/useReactifySearchContext.d.ts +4 -12
- package/dist/src/hooks/useReactifySearchContext.js.map +1 -1
- package/dist/src/hooks/useSearch.d.ts +1 -1
- package/dist/src/hooks/useSearch.js +25 -5
- package/dist/src/hooks/useSearch.js.map +1 -1
- package/dist/src/hooks/{useSortby.d.ts → useSortBy.d.ts} +1 -1
- package/dist/src/hooks/{useSortby.js → useSortBy.js} +5 -7
- package/dist/src/hooks/useSortBy.js.map +1 -0
- package/dist/src/utility/debug.d.ts +1 -1
- package/dist/src/utility/debug.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/components/Example/ExampleFilterStack.d.ts +0 -4
- package/dist/src/components/Example/ExampleFilterStack.js.map +0 -1
- package/dist/src/components/Example/ExampleSortby.d.ts +0 -4
- package/dist/src/components/Filter/FilterStack.d.ts +0 -7
- package/dist/src/components/Filter/FilterStack.js.map +0 -1
- package/dist/src/components/ReactifySearchBase/ReactifySearchBase.js.map +0 -1
- package/dist/src/components/ReactifySearchBase/index.d.ts +0 -1
- package/dist/src/components/ReactifySearchBase/index.js.map +0 -1
- package/dist/src/components/Result/ResultStack.js.map +0 -1
- package/dist/src/components/Sensor/SensorStack.d.ts +0 -3
- package/dist/src/components/Sensor/SensorStack.js.map +0 -1
- package/dist/src/components/Sortby/Sortby.d.ts +0 -7
- package/dist/src/components/Sortby/Sortby.js.map +0 -1
- package/dist/src/components/Sortby/index.d.ts +0 -1
- package/dist/src/hooks/useFilterStack.d.ts +0 -4
- package/dist/src/hooks/useFilterStack.js +0 -52
- package/dist/src/hooks/useFilterStack.js.map +0 -1
- package/dist/src/hooks/useSortby.js.map +0 -1
|
@@ -8,7 +8,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const ReactiveComponent_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent"));
|
|
9
9
|
const hooks_1 = require("../../hooks");
|
|
10
10
|
const SensorInventoryAvailable = () => {
|
|
11
|
-
const { filterStack } = (0, hooks_1.
|
|
11
|
+
const { filterStack } = (0, hooks_1.useFilters)();
|
|
12
12
|
if (!filterStack || "show_all" === filterStack.inventoryVisibility)
|
|
13
13
|
return null;
|
|
14
14
|
return (react_1.default.createElement(ReactiveComponent_1.default, { componentId: "SensorInventoryAvailable", customQuery: () => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorInventoryAvailable.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorInventoryAvailable.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAEjG,
|
|
1
|
+
{"version":3,"file":"SensorInventoryAvailable.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorInventoryAvailable.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAEjG,uCAAyC;AAElC,MAAM,wBAAwB,GAAa,GAAG,EAAE;IACrD,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,IAAI,CAAC,WAAW,IAAI,UAAU,KAAK,WAAW,CAAC,mBAAmB;QAChE,OAAO,IAAI,CAAC;IAEd,OAAO,CACL,8BAAC,2BAAiB,IAChB,WAAW,EAAC,0BAA0B,EACtC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;YAClB,KAAK,EAAE;gBACL,IAAI,EAAE;oBACJ,MAAM,EAAE;wBACN;4BACE,IAAI,EAAE;gCACJ,IAAI,EAAE;oCACJ;wCACE,IAAI,EAAE;4CACJ,IAAI,EAAE;gDACJ,KAAK,EAAE,SAAS;6CACjB;yCACF;qCACF;oCACD;wCACE,MAAM,EAAE;4CACN,IAAI,EAAE,UAAU;4CAChB,KAAK,EAAE;gDACL,KAAK,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE;6CACtC;yCACF;qCACF;iCACF;6BACF;yBACF;wBACD;4BACE,IAAI,EAAE;gCACJ,IAAI,EAAE;oCACJ,KAAK,EAAE,SAAS;iCACjB;6BACF;yBACF;qBACF;oBACD,oBAAoB,EAAE,GAAG;iBAC1B;aACF;SACF,CAAC,GACF,CACH,CAAC;AACJ,CAAC,CAAC;AAhDW,QAAA,wBAAwB,4BAgDnC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { useFilters } from \"../../hooks\";\n\nexport const SensorInventoryAvailable: React.FC = () => {\n const { filterStack } = useFilters();\n\n if (!filterStack || \"show_all\" === filterStack.inventoryVisibility)\n return null;\n\n return (\n <ReactiveComponent\n componentId=\"SensorInventoryAvailable\"\n customQuery={() => ({\n query: {\n bool: {\n should: [\n {\n bool: {\n must: [\n {\n term: {\n type: {\n value: \"product\",\n },\n },\n },\n {\n nested: {\n path: \"variants\",\n query: {\n match: { \"variants.available\": true },\n },\n },\n },\n ],\n },\n },\n {\n term: {\n type: {\n value: \"callout\",\n },\n },\n },\n ],\n minimum_should_match: \"1\",\n },\n },\n })}\n />\n );\n};\n"]}
|
|
@@ -11,14 +11,14 @@ const SensorSort = () => {
|
|
|
11
11
|
const { options, config } = (0, hooks_1.useReactifySearchContext)();
|
|
12
12
|
const curation = (0, hooks_1.useCuration)();
|
|
13
13
|
const globalCuration = (curation === null || curation === void 0 ? void 0 : curation.id) === "global";
|
|
14
|
-
const { sortOption } = (0, hooks_1.
|
|
14
|
+
const { sortOption } = (0, hooks_1.useSortBy)();
|
|
15
15
|
const { sort, query } = react_1.default.useMemo(() => {
|
|
16
16
|
return {
|
|
17
17
|
sort: buildSort({
|
|
18
|
-
sortOption,
|
|
19
|
-
collection: options.mode === "collection" ? options.collection : undefined,
|
|
20
|
-
curation,
|
|
21
18
|
globalCuration,
|
|
19
|
+
curation,
|
|
20
|
+
sortOption,
|
|
21
|
+
collectionHandle: options.mode === "collection" ? options.collectionHandle : undefined,
|
|
22
22
|
}),
|
|
23
23
|
query: buildQuery({
|
|
24
24
|
sortOption,
|
|
@@ -35,11 +35,11 @@ const SensorSort = () => {
|
|
|
35
35
|
exports.SensorSort = SensorSort;
|
|
36
36
|
const buildSort = (args) => {
|
|
37
37
|
var _a;
|
|
38
|
-
const { curation, sortOption,
|
|
38
|
+
const { curation, sortOption, collectionHandle, globalCuration } = args;
|
|
39
39
|
// return default sort option if unset
|
|
40
40
|
if (!sortOption) {
|
|
41
|
-
return
|
|
42
|
-
? mapCollectionPositionSortClause(
|
|
41
|
+
return collectionHandle
|
|
42
|
+
? mapCollectionPositionSortClause(collectionHandle)
|
|
43
43
|
: ["_score"];
|
|
44
44
|
}
|
|
45
45
|
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
@@ -49,14 +49,14 @@ const buildSort = (args) => {
|
|
|
49
49
|
}
|
|
50
50
|
// no matching curation, return default sort clause
|
|
51
51
|
if (!curation) {
|
|
52
|
-
return
|
|
53
|
-
? mapCollectionPositionSortClause(
|
|
52
|
+
return collectionHandle
|
|
53
|
+
? mapCollectionPositionSortClause(collectionHandle)
|
|
54
54
|
: ["_score"];
|
|
55
55
|
}
|
|
56
56
|
const sorts = [];
|
|
57
57
|
// show pins first
|
|
58
|
-
if (globalCuration &&
|
|
59
|
-
sorts.push(...mapCollectionPositionSortClause(
|
|
58
|
+
if (globalCuration && collectionHandle) {
|
|
59
|
+
sorts.push(...mapCollectionPositionSortClause(collectionHandle));
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
sorts.push({
|
|
@@ -118,7 +118,7 @@ const buildSort = (args) => {
|
|
|
118
118
|
/**
|
|
119
119
|
* Return a sort clause which sorts by position within the given collection.
|
|
120
120
|
*/
|
|
121
|
-
function mapCollectionPositionSortClause(
|
|
121
|
+
function mapCollectionPositionSortClause(collectionHandle) {
|
|
122
122
|
return [
|
|
123
123
|
{
|
|
124
124
|
"collections.position": {
|
|
@@ -127,7 +127,7 @@ function mapCollectionPositionSortClause(collection) {
|
|
|
127
127
|
path: "collections",
|
|
128
128
|
filter: {
|
|
129
129
|
term: {
|
|
130
|
-
"collections.handle.keyword":
|
|
130
|
+
"collections.handle.keyword": collectionHandle,
|
|
131
131
|
},
|
|
132
132
|
},
|
|
133
133
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAGjG,uCAA+E;AAExE,MAAM,UAAU,GAAa,GAAG,EAAE;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAA,mBAAW,GAAE,CAAC;IAC/B,MAAM,cAAc,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,MAAK,QAAQ,CAAC;IAEjD,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,UAAU;gBACV,UAAU,EAAE,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;gBAC1E,QAAQ;gBACR,cAAc;aACf,CAAC;YACF,KAAK,EAAE,UAAU,CAAC;gBAChB,UAAU;gBACV,QAAQ;gBACR,cAAc;aACf,CAAC;SACH,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnC,OAAO,CACL,8BAAC,2BAAiB,IAChB,WAAW,EAAC,YAAY,EACxB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;YAClB,IAAI;YACJ,KAAK;SACN,CAAC,GACF,CACH,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,UAAU,cAgCrB;A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,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 { useReactifySearchContext, useSortby, useCuration } from \"../../hooks\";\n\nexport const SensorSort: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const curation = useCuration();\n const globalCuration = curation?.id === \"global\";\n\n const { sortOption } = useSortby();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n sortOption,\n collection: options.mode === \"collection\" ? options.collection : undefined,\n curation,\n globalCuration,\n }),\n query: buildQuery({\n sortOption,\n curation,\n globalCuration,\n }),\n };\n }, [config, sortOption, curation]);\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n globalCuration?: boolean;\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n collection?: {\n id: number;\n title: string;\n handle: string;\n };\n}): any[] => {\n const { curation, sortOption, collection, globalCuration } = args;\n\n // return default sort option if unset\n if (!sortOption) {\n return collection\n ? mapCollectionPositionSortClause(collection)\n : [\"_score\"];\n }\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 (![\"_score\", \"collections.position\"].includes(sortOption.field)) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n\n // no matching curation, return default sort clause\n if (!curation) {\n return collection\n ? mapCollectionPositionSortClause(collection)\n : [\"_score\"];\n }\n\n const sorts = [];\n\n // show pins first\n if (globalCuration && collection) {\n sorts.push(...mapCollectionPositionSortClause(collection));\n } else {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\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 },\n });\n }\n\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(`query could not be parsed for boost grouping`, grouping);\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 // finally, for collections, if no other sorting is defined, sort by index order to provide\n // a consistent order\n if (\"collection\" === curation.type && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (\"search\" === curation.type) {\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(\n collection: NonNullable<{\n id: number;\n title: string;\n handle: string;\n }>\n) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collection.handle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n globalCuration?: boolean;\n}): Record<string, any> | undefined => {\n const { curation, sortOption, globalCuration } = args;\n\n if (!curation || globalCuration) {\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,uCAA+E;AAExE,MAAM,UAAU,GAAa,GAAG,EAAE;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAA,mBAAW,GAAE,CAAC;IAC/B,MAAM,cAAc,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,MAAK,QAAQ,CAAC;IAEjD,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,cAAc;gBACd,QAAQ;gBACR,U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AE;;IACpC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAEtD,IAAI,CAAC,QAAQ,IAAI,cAAc,EAAE;QAC/B,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 { useReactifySearchContext, useSortBy, useCuration } from \"../../hooks\";\n\nexport const SensorSort: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const curation = useCuration();\n const globalCuration = curation?.id === \"global\";\n\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n globalCuration,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n globalCuration,\n }),\n };\n }, [config, sortOption, curation]);\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n globalCuration?: boolean;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { curation, sortOption, collectionHandle, globalCuration } = args;\n\n // return default sort option if unset\n if (!sortOption) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\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 (![\"_score\", \"collections.position\"].includes(sortOption.field)) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n\n // no matching curation, return default sort clause\n if (!curation) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\n\n const sorts = [];\n\n // show pins first\n if (globalCuration && collectionHandle) {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n } else {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\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 },\n });\n }\n\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(`query could not be parsed for boost grouping`, grouping);\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 // finally, for collections, if no other sorting is defined, sort by index order to provide\n // a consistent order\n if (\"collection\" === curation.type && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (\"search\" === curation.type) {\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 globalCuration?: boolean;\n}): Record<string, any> | undefined => {\n const { curation, sortOption, globalCuration } = args;\n\n if (!curation || globalCuration) {\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"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.Sensors = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const hooks_1 = require("../../hooks");
|
|
9
9
|
const SensorSort_1 = require("./SensorSort");
|
|
@@ -12,7 +12,7 @@ const SensorSortScore_1 = require("./SensorSortScore");
|
|
|
12
12
|
const SensorPublished_1 = require("./SensorPublished");
|
|
13
13
|
const SensorCollection_1 = require("./SensorCollection");
|
|
14
14
|
const SensorInventoryAvailable_1 = require("./SensorInventoryAvailable");
|
|
15
|
-
const
|
|
15
|
+
const Sensors = () => {
|
|
16
16
|
const { options } = (0, hooks_1.useReactifySearchContext)();
|
|
17
17
|
// instant search mode
|
|
18
18
|
if (options.mode === "instant-search") {
|
|
@@ -28,5 +28,5 @@ const SensorStack = () => {
|
|
|
28
28
|
react_1.default.createElement(SensorCollection_1.SensorCollection, null),
|
|
29
29
|
react_1.default.createElement(SensorInventoryAvailable_1.SensorInventoryAvailable, null)));
|
|
30
30
|
};
|
|
31
|
-
exports.
|
|
32
|
-
//# sourceMappingURL=
|
|
31
|
+
exports.Sensors = Sensors;
|
|
32
|
+
//# sourceMappingURL=Sensors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sensors.js","sourceRoot":"","sources":["../../../../src/components/Sensor/Sensors.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAuD;AAEvD,6CAA0C;AAC1C,iDAA8C;AAC9C,uDAAoD;AACpD,uDAAoD;AACpD,yDAAsD;AACtD,yEAAsE;AAM/D,MAAM,OAAO,GAA2B,GAAG,EAAE;IAClD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,sBAAsB;IACtB,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE;QACrC,OAAO,CACL;YACE,8BAAC,iCAAe,OAAG;YACnB,8BAAC,iCAAe,OAAG,CAClB,CACJ,CAAC;KACH;IAED,mBAAmB;IACnB,OAAO,CACL;QACE,8BAAC,uBAAU,OAAG;QACd,8BAAC,2BAAY,OAAG;QAChB,8BAAC,iCAAe,OAAG;QACnB,8BAAC,mCAAgB,OAAG;QACpB,8BAAC,mDAAwB,OAAG,CAC3B,CACJ,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,OAAO,WAuBlB","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\n\nimport { SensorSort } from \"./SensorSort\";\nimport { SensorSearch } from \"./SensorSearch\";\nimport { SensorSortScore } from \"./SensorSortScore\";\nimport { SensorPublished } from \"./SensorPublished\";\nimport { SensorCollection } from \"./SensorCollection\";\nimport { SensorInventoryAvailable } from \"./SensorInventoryAvailable\";\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 // instant search mode\n if (options.mode === \"instant-search\") {\n return (\n <>\n <SensorPublished />\n <SensorSortScore />\n </>\n );\n }\n\n // result grid mode\n return (\n <>\n <SensorSort />\n <SensorSearch />\n <SensorPublished />\n <SensorCollection />\n <SensorInventoryAvailable />\n </>\n );\n};\n"]}
|
|
@@ -17,7 +17,7 @@ __exportStar(require("./SensorPublished"), exports);
|
|
|
17
17
|
__exportStar(require("./SensorSortScore"), exports);
|
|
18
18
|
__exportStar(require("./SensorCollection"), exports);
|
|
19
19
|
__exportStar(require("./SensorInventoryAvailable"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./Sensors"), exports);
|
|
21
21
|
// this is consumed by the react prop in various components
|
|
22
22
|
exports.SENSOR_IDS = [
|
|
23
23
|
"SensorSort",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Sensor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,iDAA+B;AAC/B,oDAAkC;AAClC,oDAAkC;AAClC,qDAAmC;AACnC,6DAA2C;AAE3C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Sensor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,iDAA+B;AAC/B,oDAAkC;AAClC,oDAAkC;AAClC,qDAAmC;AACnC,6DAA2C;AAE3C,4CAA0B;AAE1B,2DAA2D;AAC9C,QAAA,UAAU,GAAG;IACxB,YAAY;IACZ,cAAc;IACd,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,0BAA0B;CAC3B,CAAC","sourcesContent":["export * from \"./SensorSort\";\nexport * from \"./SensorSearch\";\nexport * from \"./SensorPublished\";\nexport * from \"./SensorSortScore\";\nexport * from \"./SensorCollection\";\nexport * from \"./SensorInventoryAvailable\";\n\nexport * from \"./Sensors\";\n\n// this is consumed by the react prop in various components\nexport const SENSOR_IDS = [\n \"SensorSort\",\n \"SensorSearch\",\n \"SensorSortScore\",\n \"SensorPublished\",\n \"SensorCollection\",\n \"SensorInventoryAvailable\",\n];\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useSortBy } from "../../hooks";
|
|
3
|
+
export declare type SortByProps = {
|
|
4
|
+
/** Render method called once for all sort options */
|
|
5
|
+
renderSortOptions?: React.FC<ReturnType<typeof useSortBy>>;
|
|
6
|
+
};
|
|
7
|
+
export declare const SortBy: React.FC<SortByProps>;
|
|
@@ -3,15 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.SortBy = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const hooks_1 = require("../../hooks");
|
|
9
9
|
const components_1 = require("../../components");
|
|
10
|
-
const
|
|
10
|
+
const SortBy = (props) => {
|
|
11
11
|
var _a;
|
|
12
|
-
const sortbyData = (0, hooks_1.
|
|
13
|
-
const RenderSortOptionsComponent = (_a = props.renderSortOptions) !== null && _a !== void 0 ? _a : components_1.
|
|
14
|
-
return
|
|
12
|
+
const sortbyData = (0, hooks_1.useSortBy)();
|
|
13
|
+
const RenderSortOptionsComponent = (_a = props.renderSortOptions) !== null && _a !== void 0 ? _a : components_1.ExampleSortBy;
|
|
14
|
+
return react_1.default.createElement(RenderSortOptionsComponent, Object.assign({}, sortbyData));
|
|
15
15
|
};
|
|
16
|
-
exports.
|
|
17
|
-
//# sourceMappingURL=
|
|
16
|
+
exports.SortBy = SortBy;
|
|
17
|
+
//# sourceMappingURL=SortBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortBy.js","sourceRoot":"","sources":["../../../../src/components/SortBy/SortBy.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAwC;AACxC,iDAAiD;AAO1C,MAAM,MAAM,GAA0B,CAAC,KAAK,EAAE,EAAE;;IACrD,MAAM,UAAU,GAAG,IAAA,iBAAS,GAAE,CAAC;IAE/B,MAAM,0BAA0B,GAAG,MAAA,KAAK,CAAC,iBAAiB,mCAAI,0BAAa,CAAC;IAE5E,OAAO,8BAAC,0BAA0B,oBAAK,UAAU,EAAI,CAAC;AACxD,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB","sourcesContent":["import React from \"react\";\n\nimport { useSortBy } from \"../../hooks\";\nimport { ExampleSortBy } from \"../../components\";\n\nexport type SortByProps = {\n /** Render method called once for all sort options */\n renderSortOptions?: React.FC<ReturnType<typeof useSortBy>>;\n};\n\nexport const SortBy: React.FC<SortByProps> = (props) => {\n const sortbyData = useSortBy();\n\n const RenderSortOptionsComponent = props.renderSortOptions ?? ExampleSortBy;\n\n return <RenderSortOptionsComponent {...sortbyData} />;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SortBy";
|
|
@@ -10,5 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./
|
|
13
|
+
__exportStar(require("./SortBy"), exports);
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/SortBy/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB","sourcesContent":["export * from \"./SortBy\";\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from "./Example";
|
|
2
2
|
export * from "./Filter";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./ReactifySearchProvider";
|
|
4
4
|
export * from "./Result";
|
|
5
5
|
export * from "./Search";
|
|
6
6
|
export * from "./Sensor";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./SortBy";
|
|
8
8
|
export * from "./Utility";
|
|
@@ -12,10 +12,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./Example"), exports);
|
|
14
14
|
__exportStar(require("./Filter"), exports);
|
|
15
|
-
__exportStar(require("./
|
|
15
|
+
__exportStar(require("./ReactifySearchProvider"), exports);
|
|
16
16
|
__exportStar(require("./Result"), exports);
|
|
17
17
|
__exportStar(require("./Search"), exports);
|
|
18
18
|
__exportStar(require("./Sensor"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./SortBy"), exports);
|
|
20
20
|
__exportStar(require("./Utility"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,2DAAyC;AACzC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B","sourcesContent":["export * from \"./Example\";\nexport * from \"./Filter\";\nexport * from \"./ReactifySearchProvider\";\nexport * from \"./Result\";\nexport * from \"./Search\";\nexport * from \"./Sensor\";\nexport * from \"./SortBy\";\nexport * from \"./Utility\";\n"]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
export * from "./reactivesearch";
|
|
2
2
|
export * from "./useDebugger";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./useSortBy";
|
|
4
4
|
export * from "./usePagination";
|
|
5
5
|
export * from "./usePaginationLoadMore";
|
|
6
6
|
export * from "./useSearch";
|
|
7
|
-
export * from "./useFilters";
|
|
8
7
|
export * from "./useCuration";
|
|
9
8
|
export * from "./useAnalytics";
|
|
10
|
-
export * from "./
|
|
9
|
+
export * from "./useFilters";
|
|
11
10
|
export * from "./useProductPrice";
|
|
12
11
|
export * from "./useFilterListProps";
|
|
13
12
|
export * from "./useFilterCollapsedState";
|
package/dist/src/hooks/index.js
CHANGED
|
@@ -12,14 +12,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./reactivesearch"), exports);
|
|
14
14
|
__exportStar(require("./useDebugger"), exports);
|
|
15
|
-
__exportStar(require("./
|
|
15
|
+
__exportStar(require("./useSortBy"), exports);
|
|
16
16
|
__exportStar(require("./usePagination"), exports);
|
|
17
17
|
__exportStar(require("./usePaginationLoadMore"), exports);
|
|
18
18
|
__exportStar(require("./useSearch"), exports);
|
|
19
|
-
__exportStar(require("./useFilters"), exports);
|
|
20
19
|
__exportStar(require("./useCuration"), exports);
|
|
21
20
|
__exportStar(require("./useAnalytics"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./useFilters"), exports);
|
|
23
22
|
__exportStar(require("./useProductPrice"), exports);
|
|
24
23
|
__exportStar(require("./useFilterListProps"), exports);
|
|
25
24
|
__exportStar(require("./useFilterCollapsedState"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AAEjC,gDAA8B;AAC9B,8CAA4B;AAC5B,kDAAgC;AAChC,0DAAwC;AACxC,8CAA4B;AAC5B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AAEjC,gDAA8B;AAC9B,8CAA4B;AAC5B,kDAAgC;AAChC,0DAAwC;AACxC,8CAA4B;AAC5B,gDAA8B;AAC9B,iDAA+B;AAC/B,+CAA6B;AAC7B,oDAAkC;AAClC,uDAAqC;AACrC,4DAA0C;AAC1C,8CAA4B;AAC5B,6DAA2C","sourcesContent":["export * from \"./reactivesearch\";\n\nexport * from \"./useDebugger\";\nexport * from \"./useSortBy\";\nexport * from \"./usePagination\";\nexport * from \"./usePaginationLoadMore\";\nexport * from \"./useSearch\";\nexport * from \"./useCuration\";\nexport * from \"./useAnalytics\";\nexport * from \"./useFilters\";\nexport * from \"./useProductPrice\";\nexport * from \"./useFilterListProps\";\nexport * from \"./useFilterCollapsedState\";\nexport * from \"./useConfig\";\nexport * from \"./useReactifySearchContext\";\n"]}
|
|
@@ -9,18 +9,18 @@ const hooks_1 = require("../../hooks");
|
|
|
9
9
|
const components_1 = require("../../components");
|
|
10
10
|
const useReactiveReactProp = (currentHandle) => {
|
|
11
11
|
const { options } = (0, hooks_1.useReactifySearchContext)();
|
|
12
|
-
const {
|
|
12
|
+
const { filterStack } = (0, hooks_1.useFilters)();
|
|
13
13
|
return react_1.default.useMemo(() => {
|
|
14
|
-
var _a;
|
|
14
|
+
var _a, _b;
|
|
15
15
|
return {
|
|
16
16
|
and: [
|
|
17
17
|
"SearchInput",
|
|
18
18
|
...components_1.SENSOR_IDS,
|
|
19
19
|
...((_a = options.additionalComponentHandles) !== null && _a !== void 0 ? _a : []),
|
|
20
|
-
...
|
|
20
|
+
...((_b = filterStack === null || filterStack === void 0 ? void 0 : filterStack.options.map((filter) => filter.handle)) !== null && _b !== void 0 ? _b : []),
|
|
21
21
|
].filter((handle) => handle !== currentHandle),
|
|
22
22
|
};
|
|
23
|
-
}, [
|
|
23
|
+
}, [filterStack, currentHandle, options.additionalComponentHandles]);
|
|
24
24
|
};
|
|
25
25
|
exports.useReactiveReactProp = useReactiveReactProp;
|
|
26
26
|
//# sourceMappingURL=useReactiveReactProp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReactiveReactProp.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactProp.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAmE;AACnE,iDAA8C;AAEvC,MAAM,oBAAoB,GAAG,CAAC,aAAsB,EAAE,EAAE;IAC7D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"useReactiveReactProp.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactProp.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAmE;AACnE,iDAA8C;AAEvC,MAAM,oBAAoB,GAAG,CAAC,aAAsB,EAAE,EAAE;IAC7D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,OAAO,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACxB,OAAO;YACL,GAAG,EAAE;gBACH,aAAa;gBACb,GAAG,uBAAU;gBACb,GAAG,CAAC,MAAA,OAAO,CAAC,0BAA0B,mCAAI,EAAE,CAAC;gBAC7C,GAAG,CAAC,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,mCAAI,EAAE,CAAC;aAC/D,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,aAAa,CAAC;SAC/C,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,aAAa,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext, useFilters } from \"../../hooks\";\nimport { SENSOR_IDS } from \"../../components\";\n\nexport const useReactiveReactProp = (currentHandle?: string) => {\n const { options } = useReactifySearchContext();\n const { filterStack } = useFilters();\n\n return React.useMemo(() => {\n return {\n and: [\n \"SearchInput\",\n ...SENSOR_IDS,\n ...(options.additionalComponentHandles ?? []),\n ...(filterStack?.options.map((filter) => filter.handle) ?? []),\n ].filter((handle) => handle !== currentHandle),\n };\n }, [filterStack, currentHandle, options.additionalComponentHandles]);\n};\n"]}
|
|
@@ -8,7 +8,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const hooks_1 = require("../../hooks");
|
|
9
9
|
const useReactiveReactProp_1 = require("./useReactiveReactProp");
|
|
10
10
|
const useReactiveReactiveListProps = (options) => {
|
|
11
|
-
const { filterStack } = (0, hooks_1.
|
|
11
|
+
const { filterStack } = (0, hooks_1.useFilters)();
|
|
12
12
|
const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)();
|
|
13
13
|
const size = react_1.default.useMemo(() => {
|
|
14
14
|
var _a, _b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReactiveReactiveListProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactiveListProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,
|
|
1
|
+
{"version":3,"file":"useReactiveReactiveListProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveReactiveListProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,uCAAyC;AACzC,iEAA8D;AAEvD,MAAM,4BAA4B,GAAG,CAAC,OAE5C,EAA6C,EAAE;IAC9C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IACrC,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,GAAE,CAAC;IAEjD,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC9B,OAAO,MAAA,MAAA,OAAO,CAAC,QAAQ,mCAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,mCAAI,EAAE,CAAC;IACzD,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAEpC,MAAM,yBAAyB,GAAG,eAAK,CAAC,OAAO,CAC7C,GAAG,EAAE,CAAC,CAAC;QACL,IAAI;QACJ,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,OAAO;QAClB,eAAe,EAAE,KAAK;QACtB,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,MAAM;QACnB,cAAc,EAAE,KAAK;QACrB,UAAU,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,MAAK,iBAAiB;QAC7D,cAAc,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,MAAK,iBAAiB;QACjE,eAAe,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,mDAAmD;KACjF,CAAC,EACF,CAAC,WAAW,EAAE,iBAAiB,EAAE,OAAO,CAAC,QAAQ,CAAC,CACnD,CAAC;IAEF,OAAO,yBAAyB,CAAC;AACnC,CAAC,CAAC;AA5BW,QAAA,4BAA4B,gCA4BvC","sourcesContent":["import React from \"react\";\nimport ReactiveList from \"@appbaseio/reactivesearch/lib/components/result/ReactiveList\";\n\nimport { useFilters } from \"../../hooks\";\nimport { useReactiveReactProp } from \"./useReactiveReactProp\";\n\nexport const useReactiveReactiveListProps = (options: {\n pageSize?: number;\n}): React.ComponentProps<typeof ReactiveList> => {\n const { filterStack } = useFilters();\n const reactiveReactProp = useReactiveReactProp();\n\n const size = React.useMemo(() => {\n return options.pageSize ?? filterStack?.pageSize ?? 20;\n }, [options.pageSize, filterStack]);\n\n const reactiveReactiveListProps = React.useMemo(\n () => ({\n size,\n URLParams: true,\n showLoader: false,\n dataField: \"title\",\n showResultStats: false,\n react: reactiveReactProp,\n componentId: \"page\", // this sets ?page= in the URL\n scrollOnChange: false, // @todo make this better, it's really janky when enabled\n pagination: filterStack?.paginationType !== \"infinite_scroll\",\n infiniteScroll: filterStack?.paginationType === \"infinite_scroll\",\n renderNoResults: () => null, // always use only render, otherwise both are shown\n }),\n [filterStack, reactiveReactProp, options.pageSize]\n );\n\n return reactiveReactiveListProps;\n};\n"]}
|
|
@@ -11,11 +11,7 @@ const useCuration = () => {
|
|
|
11
11
|
const { options, config } = (0, hooks_1.useReactifySearchContext)();
|
|
12
12
|
const { searchQuery } = (0, hooks_1.useSearch)();
|
|
13
13
|
const curation = react_1.default.useMemo(() => {
|
|
14
|
-
const handleOrSearchTerm = options.mode === "collection"
|
|
15
|
-
? options.collection
|
|
16
|
-
? options.collection.handle
|
|
17
|
-
: searchQuery
|
|
18
|
-
: "";
|
|
14
|
+
const handleOrSearchTerm = options.mode === "collection" ? options.collectionHandle : searchQuery;
|
|
19
15
|
const normalisedHandleOrSearchTerm = handleOrSearchTerm
|
|
20
16
|
.toLowerCase()
|
|
21
17
|
.trim();
|
|
@@ -54,7 +50,7 @@ const useCuration = () => {
|
|
|
54
50
|
: undefined;
|
|
55
51
|
}, [
|
|
56
52
|
config,
|
|
57
|
-
options.mode === "collection" ? options.
|
|
53
|
+
options.mode === "collection" ? options.collectionHandle : undefined,
|
|
58
54
|
searchQuery,
|
|
59
55
|
]);
|
|
60
56
|
react_1.default.useEffect(() => {
|
|
@@ -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,GAA+B,EAAE;IAC1D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEpC,MAAM,QAAQ,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAClC,MAAM,kBAAkB,GACtB,OAAO,CAAC,IAAI,KAAK,YAAY
|
|
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,GAA+B,EAAE;IAC1D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEpC,MAAM,QAAQ,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAClC,MAAM,kBAAkB,GACtB,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M;gBACpC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;YAEtC,IAAI,gBAAgB,IAAI,CAAC,cAAc,EAAE;gBACvC,OAAO,QAAQ,CAAC;aACjB;YAED,MAAM,0BAA0B,GAAG,gCAC9B,QAAQ,KACX,QAAQ,EAAE,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,WAAW;KACZ,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,QAAQ,CAAC;AAClB,CAAC,CAAC;AA7EW,QAAA,WAAW,eA6EtB","sourcesContent":["import React from \"react\";\n\nimport { ConfigCuration } from \"../types\";\nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): ConfigCuration | undefined => {\n const { options, config } = useReactifySearchContext();\n const { searchQuery } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchQuery;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find(\n (curation) => curation.id === \"global\" && curation.type === options.mode\n );\n\n const curation = config.curations.find((curation) => {\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\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 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 || !globalCuration) {\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 searchQuery,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return curation;\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ConfigFilterOption } from "../types";
|
|
1
|
+
import { ConfigFilter, ConfigFilterOption } from "../types";
|
|
2
2
|
export declare const useFilters: () => {
|
|
3
|
-
|
|
3
|
+
filterStack?: ConfigFilter | undefined;
|
|
4
|
+
filters?: ConfigFilterOption[] | undefined;
|
|
4
5
|
};
|
|
@@ -8,20 +8,54 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const hooks_1 = require("../hooks");
|
|
9
9
|
const utility_1 = require("../utility");
|
|
10
10
|
const useFilters = () => {
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const { options, config } = (0, hooks_1.useReactifySearchContext)();
|
|
12
|
+
const filterStack = react_1.default.useMemo(() => {
|
|
13
|
+
if (options.mode === "instant-search") {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
// select filters by type
|
|
17
|
+
const matchingFilterss = config.filters.filter((filter) => filter.type === options.mode);
|
|
18
|
+
// select filter stack by handle if provided
|
|
19
|
+
if (options.filtersHandle) {
|
|
20
|
+
const matchingFilters = matchingFilterss.find((filterStack) => options.filtersHandle === filterStack.handle);
|
|
21
|
+
if (matchingFilters) {
|
|
22
|
+
return matchingFilters;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// select filter stack by collection if provided
|
|
26
|
+
if (options.mode === "collection" && options.collectionHandle) {
|
|
27
|
+
const matchingFilters = matchingFilterss.find((filterStack) => { var _a; return (_a = filterStack.collections) === null || _a === void 0 ? void 0 : _a.includes(options.collectionHandle); });
|
|
28
|
+
if (matchingFilters) {
|
|
29
|
+
return matchingFilters;
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
// select filter with "default" handle
|
|
33
|
+
let matchingFilters = matchingFilterss.find((filterStack) => filterStack.handle === "default");
|
|
34
|
+
if (matchingFilters) {
|
|
35
|
+
return matchingFilters;
|
|
36
|
+
}
|
|
37
|
+
// select any filter with "default" handle
|
|
38
|
+
matchingFilters = config.filters.find((filterStack) => filterStack.handle === "default");
|
|
39
|
+
if (matchingFilters) {
|
|
40
|
+
return matchingFilters;
|
|
41
|
+
}
|
|
42
|
+
// select any available filter as a last resort
|
|
43
|
+
matchingFilters = config.filters[0];
|
|
44
|
+
return matchingFilters;
|
|
45
|
+
}, [
|
|
46
|
+
config,
|
|
47
|
+
options.mode === "collection" ? options.collectionHandle : undefined,
|
|
48
|
+
]);
|
|
49
|
+
const filters = react_1.default.useMemo(() => {
|
|
50
|
+
const sortedFilters = filterStack === null || filterStack === void 0 ? void 0 : filterStack.options.sort((a, b) => a.position > b.position ? 1 : -1);
|
|
51
|
+
return sortedFilters;
|
|
22
52
|
}, [filterStack]);
|
|
53
|
+
utility_1.debug.hook("useFilters", "filterStack", filterStack);
|
|
23
54
|
utility_1.debug.hook("useFilters", "filters", filters);
|
|
24
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
filterStack: filterStack,
|
|
57
|
+
filters: filters,
|
|
58
|
+
};
|
|
25
59
|
};
|
|
26
60
|
exports.useFilters = useFilters;
|
|
27
61
|
//# sourceMappingURL=useFilters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFilters.js","sourceRoot":"","sources":["../../../src/hooks/useFilters.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,
|
|
1
|
+
{"version":3,"file":"useFilters.js","sourceRoot":"","sources":["../../../src/hooks/useFilters.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAoD;AACpD,wCAAmC;AAE5B,MAAM,UAAU,GAAG,GAGxB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAEvD,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE;YACrC,OAAO,SAAS,CAAC;SAClB;QAED,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,gDAA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AC,CACjC,CAAC;QAEF,OAAO,aAAa,CAAC;IACvB,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,eAAK,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;IACrD,eAAK,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAE7C,OAAO;QACL,WAAW,EAAE,WAAW;QACxB,OAAO,EAAE,OAAO;KACjB,CAAC;AACJ,CAAC,CAAC;AA5EW,QAAA,UAAU,cA4ErB","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilter, ConfigFilterOption } from \"../types\";\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilters = (): {\n filterStack?: ConfigFilter;\n filters?: Array<ConfigFilterOption>;\n} => {\n const { options, config } = useReactifySearchContext();\n\n const filterStack = React.useMemo(() => {\n if (options.mode === \"instant-search\") {\n return undefined;\n }\n\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 debug.hook(\"useFilters\", \"filterStack\", filterStack);\n debug.hook(\"useFilters\", \"filters\", filters);\n\n return {\n filterStack: filterStack,\n filters: filters,\n };\n};\n"]}
|
|
@@ -9,7 +9,7 @@ const hooks_1 = require("../hooks");
|
|
|
9
9
|
const utility_1 = require("../utility");
|
|
10
10
|
const usePaginationLoadMore = (input) => {
|
|
11
11
|
const analyticsHook = (0, hooks_1.useAnalytics)();
|
|
12
|
-
const { filterStack } = (0, hooks_1.
|
|
12
|
+
const { filterStack } = (0, hooks_1.useFilters)();
|
|
13
13
|
const hasMore = input.resultStats.displayedResults !== input.resultStats.numberOfResults;
|
|
14
14
|
const handleLoadMore = react_1.default.useCallback(() => {
|
|
15
15
|
utility_1.debug.log("usePaginationLoadMore", "handleLoadMore");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePaginationLoadMore.js","sourceRoot":"","sources":["../../../src/hooks/usePaginationLoadMore.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,
|
|
1
|
+
{"version":3,"file":"usePaginationLoadMore.js","sourceRoot":"","sources":["../../../src/hooks/usePaginationLoadMore.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAoD;AACpD,wCAAmC;AAE5B,MAAM,qBAAqB,GAAG,CACnC,KAAgC,EAchC,EAAE;IACF,MAAM,aAAa,GAAG,IAAA,oBAAY,GAAE,CAAC;IACrC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;IAErC,MAAM,OAAO,GACX,KAAK,CAAC,WAAW,CAAC,gBAAgB,KAAK,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC;IAE3E,MAAM,cAAc,GAAG,eAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,eAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE,gBAAgB,CAAC,CAAC;QAErD,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QAED,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,aAAa,CAAC,KAAK,CAAC;YAClB,SAAS,EAAE,kBAAkB;YAC7B,OAAO,EAAE;gBACP,IAAI,EACF,IAAI,CAAC,IAAI,CACP,KAAK,CAAC,WAAW,CAAC,gBAAgB,GAAG,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,KAAI,EAAE,CAAC,CACnE,GAAG,CAAC;gBACP,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAClD,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,YAAY;aACjB;SACF,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1E,OAAO,eAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO;QACP,cAAc;QACd,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC,EACF,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,WAAW,CAAC,CAC5D,CAAC;AACJ,CAAC,CAAC;AArDW,QAAA,qBAAqB,yBAqDhC","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchResultProps } from \"../types\";\nimport { useAnalytics, useFilters } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const usePaginationLoadMore = (\n input: ReactivesearchResultProps\n): {\n loading: boolean;\n hasMore: boolean;\n handleLoadMore: () => void;\n resultStats: {\n time: number;\n hidden: number;\n promoted: number;\n currentPage: number;\n numberOfPages: number;\n numberOfResults?: number;\n displayedResults: number;\n };\n} => {\n const analyticsHook = useAnalytics();\n const { filterStack } = useFilters();\n\n const hasMore =\n input.resultStats.displayedResults !== input.resultStats.numberOfResults;\n\n const handleLoadMore = React.useCallback(() => {\n debug.log(\"usePaginationLoadMore\", \"handleLoadMore\");\n\n if (!hasMore) {\n return;\n }\n\n input.loadMore();\n analyticsHook.track({\n eventName: \"paginationChange\",\n payload: {\n page:\n Math.ceil(\n input.resultStats.displayedResults / (filterStack?.pageSize || 20)\n ) + 1,\n source: window.location.pathname.includes(\"/search\")\n ? \"search\"\n : \"collection\",\n },\n });\n }, [input.loadMore, analyticsHook.track, input.resultStats, filterStack]);\n\n return React.useMemo(\n () => ({\n loading: input.loading,\n hasMore,\n handleLoadMore,\n resultStats: input.resultStats,\n }),\n [input.loading, hasMore, handleLoadMore, input.resultStats]\n );\n};\n"]}
|