@usereactify/search 3.4.4 → 3.7.0-beta.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.
@@ -1,7 +1,7 @@
1
1
  export declare const useAnalytics: () => {
2
2
  track: (event: TrackEvent) => Promise<import("axios").AxiosResponse<any, any> | undefined>;
3
3
  };
4
- export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.ClickProductEvent;
4
+ export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.ZeroResultsEvent | TrackEvent.ViewProductEvent | TrackEvent.ClickProductEvent;
5
5
  export declare namespace TrackEvent {
6
6
  interface SearchEvent {
7
7
  eventName: "search";
@@ -12,6 +12,24 @@ export declare namespace TrackEvent {
12
12
  searchTerm: string;
13
13
  }
14
14
  }
15
+ interface ZeroResultsEvent {
16
+ eventName: "zeroResults";
17
+ payload: ZeroResultsEvent.Payload;
18
+ }
19
+ namespace ZeroResultsEvent {
20
+ interface Payload {
21
+ searchTerm: string;
22
+ }
23
+ }
24
+ interface ViewProductEvent {
25
+ eventName: "viewProduct";
26
+ payload: ViewProductEvent.Payload;
27
+ }
28
+ namespace ViewProductEvent {
29
+ interface Payload {
30
+ elasticProduct: ElasticProduct;
31
+ }
32
+ }
15
33
  interface ClickProductEvent {
16
34
  eventName: "clickProduct";
17
35
  payload: ClickProductEvent.Payload;
@@ -41,6 +41,14 @@ function getTrackEvents(event) {
41
41
  },
42
42
  ];
43
43
  break;
44
+ case "viewProduct":
45
+ events = [
46
+ {
47
+ eventName,
48
+ payload: event.payload,
49
+ },
50
+ ];
51
+ break;
44
52
  case "clickProduct":
45
53
  events = [
46
54
  {
@@ -49,6 +57,14 @@ function getTrackEvents(event) {
49
57
  },
50
58
  ];
51
59
  break;
60
+ case "zeroResults":
61
+ events = [
62
+ {
63
+ eventName,
64
+ payload: event.payload,
65
+ },
66
+ ];
67
+ break;
52
68
  }
53
69
  return events;
54
70
  }
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]);
@@ -5,7 +5,10 @@ declare type Props = {
5
5
  pagePosition: number;
6
6
  product: ElasticProduct;
7
7
  document: ElasticProduct;
8
- render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice>) => JSX.Element;
8
+ render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice> & {
9
+ itemRef: (node?: Element | null) => void;
10
+ handleClick: () => void;
11
+ }) => JSX.Element;
9
12
  };
10
13
  export declare const ResultCard: React.FC<Props>;
11
14
  export {};
@@ -16,15 +16,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.ResultCard = void 0;
18
18
  const react_1 = __importDefault(require("react"));
19
+ const react_intersection_observer_1 = require("react-intersection-observer");
19
20
  const hooks_1 = require("../hooks");
20
21
  const ResultCard = (_a) => {
21
22
  var { render } = _a, props = __rest(_a, ["render"]);
22
23
  const { product } = props;
23
24
  const productPrice = (0, hooks_1.useProductPrice)(product);
24
- if (render)
25
- return render(Object.assign(Object.assign({}, props), productPrice));
26
25
  const { formattedPrice, formattedCompareAtPrice, onSale } = productPrice;
27
26
  const { track } = (0, hooks_1.useAnalytics)();
27
+ const { ref, inView } = (0, react_intersection_observer_1.useInView)({
28
+ threshold: 0.5,
29
+ triggerOnce: true,
30
+ });
28
31
  const handleClick = react_1.default.useCallback(() => {
29
32
  track({
30
33
  eventName: "clickProduct",
@@ -36,7 +39,24 @@ const ResultCard = (_a) => {
36
39
  },
37
40
  });
38
41
  }, [track, product]);
39
- return (react_1.default.createElement("article", null,
42
+ const handleView = react_1.default.useCallback(() => {
43
+ track({
44
+ eventName: "viewProduct",
45
+ payload: {
46
+ elasticProduct: {
47
+ id: product.id,
48
+ title: product.title,
49
+ },
50
+ },
51
+ });
52
+ }, [track, product]);
53
+ react_1.default.useEffect(() => {
54
+ if (inView)
55
+ handleView();
56
+ }, [inView]);
57
+ if (render)
58
+ return render(Object.assign(Object.assign(Object.assign({}, props), productPrice), { itemRef: ref, handleClick }));
59
+ return (react_1.default.createElement("article", { ref: ref },
40
60
  react_1.default.createElement("a", { onClick: handleClick, href: `/products/${product.handle}` },
41
61
  product.image && react_1.default.createElement("img", { src: product.image, width: "100%" }),
42
62
  product.title),
@@ -11,6 +11,7 @@ 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 __1 = require("../");
14
15
  const hooks_1 = require("../hooks");
15
16
  const elastic_1 = require("../types/elastic");
16
17
  const ResultList = (props) => {
@@ -24,7 +25,8 @@ exports.ResultList = ResultList;
24
25
  const ResultListInner = (props) => {
25
26
  const { gridColumns, renderError, renderAfter, renderBefore, renderLoading, listClassName, renderResults, renderNoResults, renderResultCard, renderLoadMoreButton, renderResultCardCallout, reactivesearchResultProps, } = props;
26
27
  const filterStack = (0, hooks_1.useFilterStack)();
27
- const { instantSearch } = (0, hooks_1.useSearch)();
28
+ const { instantSearch, searchQuery } = (0, hooks_1.useSearch)();
29
+ const { track } = (0, __1.useAnalytics)();
28
30
  const initialSearchHasRun = react_1.default.useMemo(() => "undefined" !==
29
31
  typeof reactivesearchResultProps.resultStats.numberOfResults, [reactivesearchResultProps]);
30
32
  const styleProp = react_1.default.useMemo(() => ({
@@ -45,6 +47,11 @@ const ResultListInner = (props) => {
45
47
  return react_1.default.createElement("div", null, "Loading...");
46
48
  }
47
49
  if (!reactivesearchResultProps.resultStats.numberOfResults) {
50
+ if (searchQuery)
51
+ track({
52
+ eventName: "zeroResults",
53
+ payload: { searchTerm: searchQuery },
54
+ });
48
55
  if (renderNoResults)
49
56
  return renderNoResults();
50
57
  return react_1.default.createElement("div", null, "No results");
@@ -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.4.4",
4
+ "version": "3.7.0-beta.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -32,14 +32,15 @@
32
32
  "ahooks": "2.10.11",
33
33
  "axios": "0.26.1",
34
34
  "currency.js": "2.0.4",
35
- "debug": "4.3.2"
35
+ "debug": "4.3.2",
36
+ "react-intersection-observer": "9.1.0"
36
37
  },
37
38
  "peerDependencies": {
38
- "@appbaseio/reactivesearch": "^3.16.1",
39
+ "@appbaseio/reactivesearch": "^3.14.0",
39
40
  "react": "^17.0.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@appbaseio/reactivesearch": "3.24.3",
43
+ "@appbaseio/reactivesearch": "^3.14.0",
43
44
  "@commitlint/cli": "13.2.0",
44
45
  "@commitlint/config-conventional": "13.2.0",
45
46
  "@storybook/addon-actions": "6.3.10",