@usereactify/search 3.5.0 → 3.6.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/dist/provider.js CHANGED
@@ -171,6 +171,7 @@ const useCuration = (config, collection, searchQuery) => react_1.default.useMemo
171
171
  const normalisedHandleOrSearchTerm = handleOrSearchTerm
172
172
  .toLowerCase()
173
173
  .trim();
174
+ const globalCuration = config.curations.find((curation) => curation.id === "global" && curation.type === type);
174
175
  const curation = config.curations.find((curation) => {
175
176
  var _a, _b;
176
177
  const normalisedSearchTerm = (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
@@ -183,5 +184,5 @@ const useCuration = (config, collection, searchQuery) => react_1.default.useMemo
183
184
  normalisedHandleOrSearchTerm === normalisedCollectionHandle);
184
185
  return false;
185
186
  });
186
- return curation ? curation : undefined;
187
+ return curation ? curation : globalCuration ? globalCuration : undefined;
187
188
  }, [config, collection, searchQuery]);
@@ -12,6 +12,7 @@ const SensorSort = () => {
12
12
  const config = (0, hooks_1.useConfig)();
13
13
  const curation = (0, hooks_1.useCuration)();
14
14
  const collection = (0, hooks_1.useCollection)();
15
+ const globalCuration = (curation === null || curation === void 0 ? void 0 : curation.id) === "global";
15
16
  const { sortOption } = (0, hooks_1.useSort)();
16
17
  const searchQuery = react_1.default.useMemo(() => {
17
18
  if (typeof window === "undefined")
@@ -21,8 +22,14 @@ const SensorSort = () => {
21
22
  }, []);
22
23
  const { sort, query } = react_1.default.useMemo(() => {
23
24
  return {
24
- sort: buildSort({ config, curation, sortOption, collection }),
25
- query: buildQuery(curation),
25
+ sort: buildSort({
26
+ config,
27
+ curation,
28
+ sortOption,
29
+ collection,
30
+ globalCuration,
31
+ }),
32
+ query: buildQuery(curation, globalCuration),
26
33
  };
27
34
  }, [config, sortOption, curation]);
28
35
  react_1.default.useEffect(() => {
@@ -38,7 +45,7 @@ const SensorSort = () => {
38
45
  exports.SensorSort = SensorSort;
39
46
  const buildSort = (args) => {
40
47
  var _a;
41
- const { config, curation, sortOption, collection } = args;
48
+ const { config, curation, sortOption, collection, globalCuration } = args;
42
49
  debug("buildSortQuery.start", {
43
50
  config,
44
51
  curation,
@@ -63,22 +70,25 @@ const buildSort = (args) => {
63
70
  }
64
71
  const sorts = [];
65
72
  // show pins first
66
- sorts.push({
67
- "curations.position": {
68
- unmapped_type: "long",
69
- order: "asc",
70
- nested: {
71
- path: "curations",
72
- filter: {
73
- term: {
74
- [`curations.${"collection" === curation.type ? "collectionHandle" : "searchTerm"}.keyword`]: "collection" === curation.type
75
- ? curation.collectionHandle
76
- : (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
73
+ if (!globalCuration)
74
+ sorts.push({
75
+ "curations.position": {
76
+ unmapped_type: "long",
77
+ order: "asc",
78
+ nested: {
79
+ path: "curations",
80
+ filter: {
81
+ term: {
82
+ [`curations.${"collection" === curation.type
83
+ ? "collectionHandle"
84
+ : "searchTerm"}.keyword`]: "collection" === curation.type
85
+ ? curation.collectionHandle
86
+ : (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
87
+ },
77
88
  },
78
89
  },
79
90
  },
80
- },
81
- });
91
+ });
82
92
  if (0 < curation.boosting.groupings.length) {
83
93
  const groupings = curation.boosting.groupings.sort((a, b) => a.position > b.position ? 1 : -1);
84
94
  for (const grouping of groupings) {
@@ -137,9 +147,9 @@ function mapCollectionPositionSortClause(collection) {
137
147
  },
138
148
  ];
139
149
  }
140
- const buildQuery = (curation) => {
150
+ const buildQuery = (curation, globalCuration) => {
141
151
  var _a;
142
- if (!curation)
152
+ if (!curation || globalCuration)
143
153
  return undefined;
144
154
  return {
145
155
  bool: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "3.5.0",
4
+ "version": "3.6.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",