@usereactify/search 3.0.0-beta.0 → 3.1.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.d.ts +0 -4
- package/dist/provider.js +3 -5
- package/dist/result/ResultCard.d.ts +2 -1
- package/dist/result/ResultCardCallout.d.ts +2 -1
- package/dist/result/ResultCardCallout.js +2 -2
- package/dist/result/ResultList.js +9 -13
- package/dist/sensor/SensorSort.js +39 -10
- package/package.json +1 -1
package/dist/provider.d.ts
CHANGED
|
@@ -19,8 +19,6 @@ declare type Context = {
|
|
|
19
19
|
curation?: ConfigCuration;
|
|
20
20
|
/** Array of additional component IDs managed outside of Reactify Search */
|
|
21
21
|
additionalComponentIds?: string[];
|
|
22
|
-
/** Enable the new callouts feature */
|
|
23
|
-
enableCallouts?: boolean;
|
|
24
22
|
};
|
|
25
23
|
declare const Context: React.Context<Context | undefined>;
|
|
26
24
|
declare type Props = {
|
|
@@ -34,8 +32,6 @@ declare type Props = {
|
|
|
34
32
|
theme?: Theme;
|
|
35
33
|
/** Array of additional component IDs managed outside of Reactify Search */
|
|
36
34
|
additionalComponentIds?: string[];
|
|
37
|
-
/** Enable the new callouts feature */
|
|
38
|
-
enableCallouts?: boolean;
|
|
39
35
|
};
|
|
40
36
|
export declare const Provider: React.FC<Props>;
|
|
41
37
|
export declare const useContext: () => Context;
|
package/dist/provider.js
CHANGED
|
@@ -14,10 +14,10 @@ const defaultCredentials = {
|
|
|
14
14
|
endpoint: "https://api.search.reactify.app",
|
|
15
15
|
};
|
|
16
16
|
const Provider = (props) => {
|
|
17
|
-
var _a;
|
|
18
|
-
const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase,
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase, additionalComponentIds, } = props;
|
|
19
19
|
const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
|
|
20
|
-
const theme = props.theme
|
|
20
|
+
const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
|
|
21
21
|
typography: {
|
|
22
22
|
fontFamily: "inherit",
|
|
23
23
|
fontSize: "inherit",
|
|
@@ -76,7 +76,6 @@ const Provider = (props) => {
|
|
|
76
76
|
setShowInstantSearchResults,
|
|
77
77
|
theme,
|
|
78
78
|
curation,
|
|
79
|
-
enableCallouts,
|
|
80
79
|
additionalComponentIds,
|
|
81
80
|
instantSearch: !!instantSearch,
|
|
82
81
|
showInstantSearchResults: !!showInstantSearchResults && !!searchQuery,
|
|
@@ -92,7 +91,6 @@ const Provider = (props) => {
|
|
|
92
91
|
sortOptions,
|
|
93
92
|
submitSearch,
|
|
94
93
|
instantSearch,
|
|
95
|
-
enableCallouts,
|
|
96
94
|
additionalComponentIds,
|
|
97
95
|
showInstantSearchResults,
|
|
98
96
|
theme,
|
|
@@ -2,8 +2,9 @@ import React from "react";
|
|
|
2
2
|
import type { ElasticProduct } from "../types/elastic";
|
|
3
3
|
import { useProductPrice } from "../hooks";
|
|
4
4
|
declare type Props = {
|
|
5
|
-
product: ElasticProduct;
|
|
6
5
|
pagePosition: number;
|
|
6
|
+
product: ElasticProduct;
|
|
7
|
+
document: ElasticProduct;
|
|
7
8
|
render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice>) => JSX.Element;
|
|
8
9
|
};
|
|
9
10
|
export declare const ResultCard: React.FC<Props>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ElasticCallout } from "../types/elastic";
|
|
3
3
|
declare type Props = {
|
|
4
|
-
callout: ElasticCallout;
|
|
5
4
|
pagePosition: number;
|
|
5
|
+
document: ElasticCallout;
|
|
6
|
+
callout: ElasticCallout["callout"];
|
|
6
7
|
render?: (props: Omit<Props, "render">) => JSX.Element;
|
|
7
8
|
};
|
|
8
9
|
export declare const ResultCardCallout: React.FC<Props>;
|
|
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.ResultCardCallout = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const ResultCardCallout = (props) => {
|
|
20
|
-
const { callout
|
|
20
|
+
const { callout } = props;
|
|
21
21
|
const styleProp = react_1.default.useMemo(() => {
|
|
22
22
|
var _a, _b;
|
|
23
23
|
return ({
|
|
@@ -31,7 +31,7 @@ const ResultCardCallout = (props) => {
|
|
|
31
31
|
exports.ResultCardCallout = ResultCardCallout;
|
|
32
32
|
const ResultCardCalloutInner = (_a) => {
|
|
33
33
|
var { render } = _a, props = __rest(_a, ["render"]);
|
|
34
|
-
const { callout
|
|
34
|
+
const { callout } = props;
|
|
35
35
|
if (render)
|
|
36
36
|
return render(props);
|
|
37
37
|
return react_1.default.createElement("p", null, callout.title);
|
|
@@ -11,7 +11,6 @@ const ResultPagination_1 = require("./ResultPagination");
|
|
|
11
11
|
const ResultCardCallout_1 = require("./ResultCardCallout");
|
|
12
12
|
const ResultLoadMoreButton_1 = require("./ResultLoadMoreButton");
|
|
13
13
|
const ResultPaginationNextPrev_1 = require("./ResultPaginationNextPrev");
|
|
14
|
-
const provider_1 = require("../provider");
|
|
15
14
|
const hooks_1 = require("../hooks");
|
|
16
15
|
const elastic_1 = require("../types/elastic");
|
|
17
16
|
const ResultList = (props) => {
|
|
@@ -24,18 +23,14 @@ const ResultList = (props) => {
|
|
|
24
23
|
exports.ResultList = ResultList;
|
|
25
24
|
const ResultListInner = (props) => {
|
|
26
25
|
const { gridColumns, renderError, renderAfter, renderBefore, renderLoading, listClassName, renderResults, renderNoResults, renderResultCard, renderLoadMoreButton, renderResultCardCallout, reactivesearchResultProps, } = props;
|
|
27
|
-
const curation = (0, hooks_1.useCuration)();
|
|
28
26
|
const filterStack = (0, hooks_1.useFilterStack)();
|
|
29
27
|
const { instantSearch } = (0, hooks_1.useSearch)();
|
|
30
|
-
const { enableCallouts } = (0, provider_1.useContext)();
|
|
31
28
|
const initialSearchHasRun = react_1.default.useMemo(() => "undefined" !==
|
|
32
29
|
typeof reactivesearchResultProps.resultStats.numberOfResults, [reactivesearchResultProps]);
|
|
33
|
-
const styleProp = react_1.default.useMemo(() =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
: {}, [curation]);
|
|
30
|
+
const styleProp = react_1.default.useMemo(() => ({
|
|
31
|
+
display: "grid",
|
|
32
|
+
gridTemplateColumns: `repeat(${gridColumns !== null && gridColumns !== void 0 ? gridColumns : 4}, minmax(0, 1fr))`,
|
|
33
|
+
}), [gridColumns]);
|
|
39
34
|
if (reactivesearchResultProps.error) {
|
|
40
35
|
if (renderError)
|
|
41
36
|
return renderError({ error: reactivesearchResultProps.error });
|
|
@@ -59,11 +54,12 @@ const ResultListInner = (props) => {
|
|
|
59
54
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
60
55
|
renderBefore && renderBefore(reactivesearchResultProps),
|
|
61
56
|
react_1.default.createElement("section", { className: listClassName, style: styleProp }, reactivesearchResultProps.data.map((result, key) => {
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
// @todo result.type is missing in v1 indexes, this check ensures that they are assumed to be products
|
|
58
|
+
if (elastic_1.ElasticDocumentType.Product === result.type || !result.type) {
|
|
59
|
+
return (react_1.default.createElement(ResultCard_1.ResultCard, { key: result._id, product: result, document: result, pagePosition: key + 1, render: renderResultCard }));
|
|
64
60
|
}
|
|
65
|
-
if (
|
|
66
|
-
return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { key: result._id,
|
|
61
|
+
if (elastic_1.ElasticDocumentType.Callout === result.type) {
|
|
62
|
+
return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { key: result._id, document: result, pagePosition: key + 1, callout: result.callout, render: renderResultCardCallout }));
|
|
67
63
|
}
|
|
68
64
|
return null;
|
|
69
65
|
})),
|
|
@@ -11,6 +11,7 @@ const debug = require("debug")("reactify-search:SensorSort");
|
|
|
11
11
|
const SensorSort = () => {
|
|
12
12
|
const config = (0, hooks_1.useConfig)();
|
|
13
13
|
const curation = (0, hooks_1.useCuration)();
|
|
14
|
+
const collection = (0, hooks_1.useCollection)();
|
|
14
15
|
const { sortOption } = (0, hooks_1.useSort)();
|
|
15
16
|
const searchQuery = react_1.default.useMemo(() => {
|
|
16
17
|
if (typeof window === "undefined")
|
|
@@ -20,7 +21,7 @@ const SensorSort = () => {
|
|
|
20
21
|
}, []);
|
|
21
22
|
const { sort, query } = react_1.default.useMemo(() => {
|
|
22
23
|
return {
|
|
23
|
-
sort: buildSort(config, curation, sortOption),
|
|
24
|
+
sort: buildSort({ config, curation, sortOption, collection }),
|
|
24
25
|
query: buildQuery(curation),
|
|
25
26
|
};
|
|
26
27
|
}, [config, sortOption, curation]);
|
|
@@ -35,25 +36,30 @@ const SensorSort = () => {
|
|
|
35
36
|
}) }));
|
|
36
37
|
};
|
|
37
38
|
exports.SensorSort = SensorSort;
|
|
38
|
-
const buildSort = (
|
|
39
|
+
const buildSort = (args) => {
|
|
39
40
|
var _a;
|
|
41
|
+
const { config, curation, sortOption, collection } = args;
|
|
40
42
|
debug("buildSortQuery.start", {
|
|
41
43
|
config,
|
|
42
44
|
curation,
|
|
43
|
-
|
|
45
|
+
sortOption,
|
|
44
46
|
});
|
|
45
|
-
// return default
|
|
46
|
-
if (!
|
|
47
|
-
return
|
|
47
|
+
// return default sort option if unset
|
|
48
|
+
if (!sortOption) {
|
|
49
|
+
return collection
|
|
50
|
+
? mapCollectionPositionSortClause(collection)
|
|
51
|
+
: ["_score"];
|
|
48
52
|
}
|
|
49
53
|
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
50
54
|
// if the sort is something else, apply a normal sort which applies what the user has requested
|
|
51
|
-
if (!["
|
|
52
|
-
return [{ [
|
|
55
|
+
if (!["_score", "collections.position"].includes(sortOption.field)) {
|
|
56
|
+
return [{ [sortOption.field]: sortOption.direction }];
|
|
53
57
|
}
|
|
54
|
-
// no matching curation, return default sort
|
|
58
|
+
// no matching curation, return default sort clause
|
|
55
59
|
if (!curation) {
|
|
56
|
-
return
|
|
60
|
+
return collection
|
|
61
|
+
? mapCollectionPositionSortClause(collection)
|
|
62
|
+
: ["_score"];
|
|
57
63
|
}
|
|
58
64
|
const sorts = [];
|
|
59
65
|
// show pins first
|
|
@@ -106,8 +112,31 @@ const buildSort = (config, curation, sortState) => {
|
|
|
106
112
|
sorts.push("_doc");
|
|
107
113
|
else
|
|
108
114
|
sorts.push("_score");
|
|
115
|
+
// @todo ideally, once pins are extinguished and there are no boost rules, the rest of the
|
|
116
|
+
// result should be ordered by the shopify collection position rather than the index order,
|
|
117
|
+
// but this will need some proper testing to ensure it does not break curations
|
|
109
118
|
return sorts;
|
|
110
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Return a sort clause which sorts by position within the given collection.
|
|
122
|
+
*/
|
|
123
|
+
function mapCollectionPositionSortClause(collection) {
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
"collections.position": {
|
|
127
|
+
order: "asc",
|
|
128
|
+
nested: {
|
|
129
|
+
path: "collections",
|
|
130
|
+
filter: {
|
|
131
|
+
term: {
|
|
132
|
+
"collections.handle.keyword": collection.handle,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
111
140
|
const buildQuery = (curation) => {
|
|
112
141
|
var _a;
|
|
113
142
|
if (!curation)
|