@usereactify/search 3.5.0 → 3.7.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/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +5 -1
- package/dist/hooks/reactivesearch/useReactiveDataSearchProps.js +5 -20
- package/dist/provider.js +2 -1
- package/dist/search/SearchInput.d.ts +1 -0
- package/dist/search/SearchInput.js +2 -4
- package/dist/sensor/SensorSort.js +28 -18
- package/package.json +1 -1
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
declare type Props = {
|
|
2
|
+
[key: string]: any;
|
|
2
3
|
debounce?: number;
|
|
3
4
|
placeholder?: string;
|
|
4
5
|
inputClassName?: string;
|
|
5
6
|
};
|
|
6
7
|
export declare const useReactiveDataSearchProps: (props?: Props) => {
|
|
8
|
+
debounce?: number | undefined;
|
|
9
|
+
placeholder: string;
|
|
10
|
+
inputClassName?: string | undefined;
|
|
11
|
+
type: string;
|
|
7
12
|
showIcon: boolean;
|
|
8
13
|
fuzziness: 0 | 1 | 2 | "AUTO";
|
|
9
14
|
queryFormat: "and" | "or";
|
|
@@ -11,7 +16,6 @@ export declare const useReactiveDataSearchProps: (props?: Props) => {
|
|
|
11
16
|
value: string;
|
|
12
17
|
onKeyUp: (e: any) => void;
|
|
13
18
|
componentId: string;
|
|
14
|
-
placeholder: string;
|
|
15
19
|
dataField: string[];
|
|
16
20
|
fieldWeights: number[];
|
|
17
21
|
onChange: (value: string, triggerQuery: () => {}) => void;
|
|
@@ -45,35 +45,20 @@ const useReactiveDataSearchProps = (props = {}) => {
|
|
|
45
45
|
}, {
|
|
46
46
|
wait: debounce !== null && debounce !== void 0 ? debounce : 300,
|
|
47
47
|
});
|
|
48
|
-
return react_1.default.useMemo(() => ({
|
|
49
|
-
showIcon: false,
|
|
50
|
-
fuzziness: 1,
|
|
51
|
-
queryFormat: "and",
|
|
52
|
-
autosuggest: false,
|
|
53
|
-
value: searchQuery !== null && searchQuery !== void 0 ? searchQuery : "",
|
|
54
|
-
onKeyUp: handleKeyPress,
|
|
55
|
-
componentId: "SearchInput",
|
|
56
|
-
placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "Search for a product...",
|
|
57
|
-
dataField: searchFields.map((field) => field.field),
|
|
58
|
-
fieldWeights: searchFields.map((field) => field.importance),
|
|
59
|
-
onChange: (value, triggerQuery) => {
|
|
48
|
+
return react_1.default.useMemo(() => (Object.assign({ type: "search", showIcon: false, fuzziness: 1, queryFormat: "and", autosuggest: false, value: searchQuery !== null && searchQuery !== void 0 ? searchQuery : "", onKeyUp: handleKeyPress, componentId: "SearchInput", placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : "Search for a product...", dataField: searchFields.map((field) => field.field), fieldWeights: searchFields.map((field) => field.importance), onChange: (value, triggerQuery) => {
|
|
60
49
|
setSearchQuery(value);
|
|
61
50
|
if (!!value)
|
|
62
51
|
runDebouncedTriggerQuery(triggerQuery);
|
|
63
52
|
else
|
|
64
53
|
cancelDebouncedTriggerQuery();
|
|
65
|
-
},
|
|
66
|
-
onBlur: () => {
|
|
54
|
+
}, onBlur: () => {
|
|
67
55
|
// requestAnimationFrame ensures that results are still clickable before close
|
|
68
56
|
window.requestAnimationFrame(() => setShowInstantSearchResults(false));
|
|
69
|
-
},
|
|
70
|
-
onFocus: () => {
|
|
57
|
+
}, onFocus: () => {
|
|
71
58
|
setShowInstantSearchResults(true);
|
|
72
|
-
},
|
|
73
|
-
innerClass: {
|
|
59
|
+
}, innerClass: {
|
|
74
60
|
input: inputClassName,
|
|
75
|
-
},
|
|
76
|
-
}), [
|
|
61
|
+
} }, props)), [
|
|
77
62
|
searchQuery,
|
|
78
63
|
handleKeyPress,
|
|
79
64
|
placeholder,
|
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]);
|
|
@@ -9,11 +9,9 @@ const DataSearch_1 = __importDefault(require("@appbaseio/reactivesearch/lib/comp
|
|
|
9
9
|
const hooks_1 = require("../hooks");
|
|
10
10
|
const SearchInput = (props) => {
|
|
11
11
|
const { debounce, placeholder, inputClassName } = props;
|
|
12
|
-
const reactiveDataSearchProps = (0, hooks_1.useReactiveDataSearchProps)({
|
|
13
|
-
debounce,
|
|
12
|
+
const reactiveDataSearchProps = (0, hooks_1.useReactiveDataSearchProps)(Object.assign({ debounce,
|
|
14
13
|
placeholder,
|
|
15
|
-
inputClassName,
|
|
16
|
-
});
|
|
14
|
+
inputClassName }, props));
|
|
17
15
|
return react_1.default.createElement(DataSearch_1.default, Object.assign({}, reactiveDataSearchProps));
|
|
18
16
|
};
|
|
19
17
|
exports.SearchInput = SearchInput;
|
|
@@ -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({
|
|
25
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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: {
|