@usereactify/search 2.1.0-beta.6 → 3.0.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.
Files changed (49) hide show
  1. package/README.md +0 -3
  2. package/dist/filter/Filter.d.ts +1 -1
  3. package/dist/filter/FilterStack.d.ts +1 -1
  4. package/dist/hooks/index.d.ts +0 -2
  5. package/dist/hooks/index.js +0 -2
  6. package/dist/hooks/reactivesearch/useReactiveBaseProps.d.ts +1 -1
  7. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.js +0 -8
  8. package/dist/hooks/reactivesearch/useReactiveFilterListProps.d.ts +1 -1
  9. package/dist/hooks/reactivesearch/useReactiveResultListProps.d.ts +0 -1
  10. package/dist/hooks/reactivesearch/useReactiveResultListProps.js +3 -3
  11. package/dist/hooks/useCollection.d.ts +1 -1
  12. package/dist/hooks/useFilterCollapsedState.d.ts +1 -1
  13. package/dist/hooks/useFilterListProps.d.ts +2 -1
  14. package/dist/hooks/useFilters.d.ts +1 -1
  15. package/dist/hooks/usePages.d.ts +1 -1
  16. package/dist/hooks/usePages.js +2 -7
  17. package/dist/hooks/useProductPrice.d.ts +2 -2
  18. package/dist/index.d.ts +3 -1
  19. package/dist/index.js +3 -1
  20. package/dist/provider.d.ts +34 -7
  21. package/dist/provider.js +3 -5
  22. package/dist/result/ResultCard.d.ts +3 -2
  23. package/dist/result/ResultCard.js +3 -16
  24. package/dist/result/ResultCardCallout.d.ts +3 -2
  25. package/dist/result/ResultList.d.ts +4 -7
  26. package/dist/result/ResultList.js +10 -20
  27. package/dist/result/ResultLoadMoreButton.d.ts +1 -1
  28. package/dist/result/ResultPagination.d.ts +1 -1
  29. package/dist/result/ResultPaginationNextPrev.d.ts +1 -1
  30. package/dist/result/ResultStateProvider.d.ts +1 -1
  31. package/dist/sensor/SensorSort.js +39 -10
  32. package/dist/types/config.d.ts +17 -122
  33. package/dist/types/elastic.d.ts +209 -0
  34. package/dist/types/elastic.js +18 -0
  35. package/dist/types/firestore.d.ts +276 -0
  36. package/dist/types/firestore.js +18 -0
  37. package/dist/types/graphql.d.ts +26545 -0
  38. package/dist/types/graphql.js +4687 -0
  39. package/dist/types/{index.d.ts → reactivesearch.d.ts} +5 -11
  40. package/dist/types/{results.js → reactivesearch.js} +0 -0
  41. package/dist/types/shopify.d.ts +21 -0
  42. package/dist/types/shopify.js +27 -0
  43. package/package.json +1 -3
  44. package/dist/hooks/useAnalytics.d.ts +0 -28
  45. package/dist/hooks/useAnalytics.js +0 -45
  46. package/dist/hooks/useCombinedResults.d.ts +0 -7
  47. package/dist/hooks/useCombinedResults.js +0 -25
  48. package/dist/types/index.js +0 -14
  49. package/dist/types/results.d.ts +0 -48
package/README.md CHANGED
@@ -38,7 +38,4 @@ npm run storybook
38
38
 
39
39
  # release a version
40
40
  npm run release
41
-
42
- # release a beta version
43
- npm run build && npm run release -- --prerelease beta && npm publish --tag beta
44
41
  ```
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import type { ConfigFilterOption } from "../types";
2
+ import type { ConfigFilterOption } from "../types/config";
3
3
  import { useFilterListProps, useFilterCollapsedState } from "../hooks";
4
4
  declare type Props = {
5
5
  noWrapper?: boolean;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import type { ConfigFilterOption } from "../types";
2
+ import type { ConfigFilterOption } from "../types/config";
3
3
  import { useFilterCollapsedState } from "../hooks";
4
4
  declare type Props = {
5
5
  render?: (filters: ConfigFilterOption[]) => JSX.Element;
@@ -5,10 +5,8 @@ export * from "./useConfig";
5
5
  export * from "./useSearch";
6
6
  export * from "./useFilters";
7
7
  export * from "./useCuration";
8
- export * from "./useAnalytics";
9
8
  export * from "./useCollection";
10
9
  export * from "./useFilterStack";
11
10
  export * from "./useProductPrice";
12
11
  export * from "./useFilterListProps";
13
- export * from "./useCombinedResults";
14
12
  export * from "./useFilterCollapsedState";
@@ -17,10 +17,8 @@ __exportStar(require("./useConfig"), exports);
17
17
  __exportStar(require("./useSearch"), exports);
18
18
  __exportStar(require("./useFilters"), exports);
19
19
  __exportStar(require("./useCuration"), exports);
20
- __exportStar(require("./useAnalytics"), exports);
21
20
  __exportStar(require("./useCollection"), exports);
22
21
  __exportStar(require("./useFilterStack"), exports);
23
22
  __exportStar(require("./useProductPrice"), exports);
24
23
  __exportStar(require("./useFilterListProps"), exports);
25
- __exportStar(require("./useCombinedResults"), exports);
26
24
  __exportStar(require("./useFilterCollapsedState"), exports);
@@ -2,6 +2,6 @@ export declare const useReactiveBaseProps: () => {
2
2
  app: string;
3
3
  url: string;
4
4
  credentials: string;
5
- theme: import("../..").ConfigTheme | undefined;
5
+ theme: import("../../provider").Theme | undefined;
6
6
  transformResponse: (response: any) => Promise<any>;
7
7
  };
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useReactiveDataSearchProps = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const ahooks_1 = require("ahooks");
9
- const useAnalytics_1 = require("../useAnalytics");
10
9
  const debug = require("debug")("reactify-search:useReactiveDataSearchProps");
11
10
  const __1 = require("../");
12
11
  // default field for when zero search fields have been configured in Reactify
@@ -34,15 +33,8 @@ const useReactiveDataSearchProps = (props = {}) => {
34
33
  return;
35
34
  submitSearch();
36
35
  }, [submitSearch]);
37
- const { track } = (0, useAnalytics_1.useAnalytics)();
38
- const trackQuery = react_1.default.useCallback(() => {
39
- if (!searchQuery)
40
- return;
41
- track({ eventName: "search", payload: { searchTerm: searchQuery } });
42
- }, [searchQuery, track]);
43
36
  const { run: runDebouncedTriggerQuery, cancel: cancelDebouncedTriggerQuery } = (0, ahooks_1.useDebounceFn)((triggerQuery) => {
44
37
  triggerQuery();
45
- trackQuery();
46
38
  }, {
47
39
  wait: debounce !== null && debounce !== void 0 ? debounce : 300,
48
40
  });
@@ -1,4 +1,4 @@
1
- import type { ConfigFilterOption } from "../../types";
1
+ import type { ConfigFilterOption } from "../../types/config";
2
2
  export declare const useReactiveFilterListProps: (filter: ConfigFilterOption) => {
3
3
  nestedField: string | undefined;
4
4
  customQuery: ((value?: string | string[] | undefined) => {
@@ -1,6 +1,5 @@
1
1
  declare type Props = {
2
2
  pageSize?: number;
3
- pageSizeAdjust?: number;
4
3
  };
5
4
  export declare const useReactiveResultListProps: (props?: Props) => {
6
5
  size: number;
@@ -8,13 +8,13 @@ const react_1 = __importDefault(require("react"));
8
8
  const hooks_1 = require("../../hooks");
9
9
  const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
10
  const useReactiveResultListProps = (props = {}) => {
11
- const { pageSize, pageSizeAdjust } = props;
11
+ const { pageSize } = props;
12
12
  const filterStack = (0, hooks_1.useFilterStack)();
13
13
  const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)();
14
14
  const size = react_1.default.useMemo(() => {
15
15
  var _a;
16
- return ((_a = pageSize !== null && pageSize !== void 0 ? pageSize : filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) !== null && _a !== void 0 ? _a : 20) - (pageSizeAdjust !== null && pageSizeAdjust !== void 0 ? pageSizeAdjust : 0);
17
- }, [pageSize, pageSizeAdjust, filterStack]);
16
+ return (_a = pageSize !== null && pageSize !== void 0 ? pageSize : filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) !== null && _a !== void 0 ? _a : 20;
17
+ }, [pageSize, filterStack]);
18
18
  return react_1.default.useMemo(() => ({
19
19
  size,
20
20
  URLParams: true,
@@ -1 +1 @@
1
- export declare const useCollection: () => import("..").Collection | undefined;
1
+ export declare const useCollection: () => import("../provider").Collection | undefined;
@@ -1,4 +1,4 @@
1
- import { ConfigFilterOption } from "../types";
1
+ import { ConfigFilterOption } from "../types/config";
2
2
  export declare const useFilterCollapsedState: (filter: ConfigFilterOption) => {
3
3
  collapsed: boolean;
4
4
  shouldRender: boolean;
@@ -1,4 +1,5 @@
1
- import { ConfigFilterOption, ReactivesearchFilterProps } from "../types";
1
+ import { ConfigFilterOption } from "../types/config";
2
+ import { ReactivesearchFilterProps } from "../types/reactivesearch";
2
3
  export declare const useFilterListProps: (filter: ConfigFilterOption, reactivesearchFilterProps: ReactivesearchFilterProps) => {
3
4
  filter: ConfigFilterOption;
4
5
  options: {
@@ -1 +1 @@
1
- export declare const useFilters: () => import("..").ConfigFilterOption[];
1
+ export declare const useFilters: () => Omit<import("../types/firestore").FilterOption, "enabled">[];
@@ -1,4 +1,4 @@
1
- import { ReactivesearchPaginationProps } from "../types";
1
+ import { ReactivesearchPaginationProps } from "../types/reactivesearch";
2
2
  export declare const usePages: (props: ReactivesearchPaginationProps) => {
3
3
  pagesToShow: number[];
4
4
  hasNextPage: boolean;
@@ -16,19 +16,14 @@ const usePages = (props) => {
16
16
  const pagesToShow = react_1.default.useMemo(() => getPages(pages, totalPages, currentPage), [pages, totalPages, currentPage]);
17
17
  // default currentPage is zero-indexed, actualCurrentPage is one-indexed
18
18
  const actualCurrentPage = react_1.default.useMemo(() => currentPage + 1, [currentPage]);
19
- const hasNextPage = react_1.default.useMemo(() => actualCurrentPage < totalPages, [
20
- actualCurrentPage,
21
- totalPages,
22
- ]);
19
+ const hasNextPage = react_1.default.useMemo(() => actualCurrentPage < totalPages, [actualCurrentPage, totalPages]);
23
20
  const handleNextPage = react_1.default.useCallback((event) => {
24
21
  event === null || event === void 0 ? void 0 : event.preventDefault();
25
22
  if (!hasNextPage)
26
23
  return;
27
24
  setPage(currentPage + 1);
28
25
  }, [hasNextPage, currentPage, setPage]);
29
- const hasPreviousPage = react_1.default.useMemo(() => actualCurrentPage > 1, [
30
- actualCurrentPage,
31
- ]);
26
+ const hasPreviousPage = react_1.default.useMemo(() => actualCurrentPage > 1, [actualCurrentPage]);
32
27
  const handlePreviousPage = react_1.default.useCallback((event) => {
33
28
  event === null || event === void 0 ? void 0 : event.preventDefault();
34
29
  if (!hasPreviousPage)
@@ -1,5 +1,5 @@
1
1
  import currency from "currency.js";
2
- import { Product } from "../types";
2
+ import { ElasticProduct } from "../types/elastic";
3
3
  declare type PriceResponse = {
4
4
  onSale: boolean;
5
5
  price?: currency;
@@ -8,5 +8,5 @@ declare type PriceResponse = {
8
8
  compareAtPrice?: currency;
9
9
  formattedCompareAtPrice?: string;
10
10
  };
11
- export declare const useProductPrice: (product: Product) => PriceResponse;
11
+ export declare const useProductPrice: (product: ElasticProduct) => PriceResponse;
12
12
  export {};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- export * from "./types";
2
1
  export * from "./hooks";
3
2
  export * from "./filter";
4
3
  export * from "./sensor";
5
4
  export * from "./result";
6
5
  export * from "./search";
7
6
  export * from "./provider";
7
+ export * from "./types/config";
8
+ export * from "./types/elastic";
9
+ export * from "./types/reactivesearch";
package/dist/index.js CHANGED
@@ -10,10 +10,12 @@ 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("./types"), exports);
14
13
  __exportStar(require("./hooks"), exports);
15
14
  __exportStar(require("./filter"), exports);
16
15
  __exportStar(require("./sensor"), exports);
17
16
  __exportStar(require("./result"), exports);
18
17
  __exportStar(require("./search"), exports);
19
18
  __exportStar(require("./provider"), exports);
19
+ __exportStar(require("./types/config"), exports);
20
+ __exportStar(require("./types/elastic"), exports);
21
+ __exportStar(require("./types/reactivesearch"), exports);
@@ -1,22 +1,21 @@
1
1
  import React from "react";
2
- import type { Collection, Config, ConfigSort, ConfigFilter, ConfigCuration, ConfigCredentials, ConfigTheme } from "./types";
2
+ import type { Config, ConfigSort, ConfigFilter, ConfigCuration } from "./types/config";
3
3
  declare type Context = {
4
4
  index: string;
5
5
  config: Config;
6
- shopName: string;
7
6
  sortOption: ConfigSort;
8
7
  sortOptions: ConfigSort[];
9
8
  searchQuery?: string;
10
9
  filterStack?: ConfigFilter;
11
10
  collection?: Collection;
12
11
  instantSearch: boolean;
13
- credentials: ConfigCredentials;
12
+ credentials: Credentials;
14
13
  submitSearch: (localSearchQuery?: string) => void;
15
14
  setSearchQuery: (searchQuery: string) => void;
16
15
  setSortOption: (sortOptionId: string) => void;
17
16
  showInstantSearchResults: boolean;
18
17
  setShowInstantSearchResults: (showInstantSearchResults: boolean) => void;
19
- theme?: ConfigTheme;
18
+ theme?: Theme;
20
19
  curation?: ConfigCuration;
21
20
  /** Array of additional component IDs managed outside of Reactify Search */
22
21
  additionalComponentIds?: string[];
@@ -27,13 +26,12 @@ declare const Context: React.Context<Context | undefined>;
27
26
  declare type Props = {
28
27
  index: string;
29
28
  config: Config;
30
- shopName: string;
31
29
  filterStackId?: string;
32
30
  collection?: Collection;
33
31
  noReactiveBase?: boolean;
34
32
  instantSearch?: boolean;
35
- credentials?: ConfigCredentials;
36
- theme?: ConfigTheme;
33
+ credentials?: Credentials;
34
+ theme?: Theme;
37
35
  /** Array of additional component IDs managed outside of Reactify Search */
38
36
  additionalComponentIds?: string[];
39
37
  /** Enable the new callouts feature */
@@ -41,4 +39,33 @@ declare type Props = {
41
39
  };
42
40
  export declare const Provider: React.FC<Props>;
43
41
  export declare const useContext: () => Context;
42
+ export interface Collection {
43
+ id: number;
44
+ handle: string;
45
+ title: string;
46
+ }
47
+ export interface Credentials {
48
+ username: string;
49
+ password: string;
50
+ endpoint: string;
51
+ }
52
+ export interface Theme {
53
+ component?: any;
54
+ colors?: ThemeColors;
55
+ typography?: ThemeTypography;
56
+ }
57
+ export interface ThemeTypography {
58
+ fontFamily?: string;
59
+ fontSize?: string;
60
+ }
61
+ export interface ThemeColors {
62
+ alertColor?: string;
63
+ backgroundColor?: string;
64
+ borderColor?: string;
65
+ extColor?: string;
66
+ primaryTextColor?: string;
67
+ primaryColor?: string;
68
+ textColor?: string;
69
+ titleColor?: string;
70
+ }
44
71
  export {};
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, shopName, children, collection, instantSearch, filterStackId, noReactiveBase, enableCallouts, additionalComponentIds, } = props;
17
+ var _a, _b;
18
+ const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase, enableCallouts, 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",
@@ -64,7 +64,6 @@ const Provider = (props) => {
64
64
  const contextValue = react_1.default.useMemo(() => ({
65
65
  index,
66
66
  config,
67
- shopName,
68
67
  collection,
69
68
  credentials,
70
69
  searchQuery,
@@ -85,7 +84,6 @@ const Provider = (props) => {
85
84
  index,
86
85
  config,
87
86
  curation,
88
- shopName,
89
87
  collection,
90
88
  credentials,
91
89
  searchQuery,
@@ -1,9 +1,10 @@
1
1
  import React from "react";
2
- import { Product } from "../types";
2
+ import type { ElasticProduct } from "../types/elastic";
3
3
  import { useProductPrice } from "../hooks";
4
4
  declare type Props = {
5
- product: Product;
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>;
@@ -24,23 +24,10 @@ const ResultCard = (_a) => {
24
24
  if (render)
25
25
  return render(Object.assign(Object.assign({}, props), productPrice));
26
26
  const { formattedPrice, formattedCompareAtPrice, onSale } = productPrice;
27
- const { track } = (0, hooks_1.useAnalytics)();
28
- const handleClick = react_1.default.useCallback((e) => {
29
- e.preventDefault();
30
- const { id, title } = product;
31
- console.log("tracking click product event");
32
- track({
33
- eventName: "clickProduct",
34
- payload: {
35
- elasticProduct: { id, title },
36
- },
37
- }).then(() => {
38
- console.log("tracking click product event finished");
39
- window.location.href = `/products/${product.handle}`;
40
- });
41
- }, [track, product]);
42
27
  return (react_1.default.createElement("article", null,
43
- react_1.default.createElement("a", { onClick: handleClick }, product.title),
28
+ react_1.default.createElement("a", { href: `/products/${product.handle}` },
29
+ product.image && react_1.default.createElement("img", { src: product.image, width: "100%" }),
30
+ product.title),
44
31
  react_1.default.createElement("span", null, formattedPrice),
45
32
  onSale && (react_1.default.createElement("span", { style: { textDecoration: "line-through" } }, formattedCompareAtPrice))));
46
33
  };
@@ -1,8 +1,9 @@
1
1
  import React from "react";
2
- import { ConfigCallout } from "../types";
2
+ import { ElasticCallout } from "../types/elastic";
3
3
  declare type Props = {
4
- callout: ConfigCallout;
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>;
@@ -4,10 +4,7 @@ import { ResultPagination } from "./ResultPagination";
4
4
  import { ResultCardCallout } from "./ResultCardCallout";
5
5
  import { ResultLoadMoreButton } from "./ResultLoadMoreButton";
6
6
  import { ResultPaginationNextPrev } from "./ResultPaginationNextPrev";
7
- import { ResultCombined, ReactivesearchError, ReactivesearchResultProps } from "../types";
8
- declare type ResultProps = ReactivesearchResultProps & {
9
- results: ResultCombined[];
10
- };
7
+ import { ReactivesearchError, ReactivesearchResultProps } from "../types/reactivesearch";
11
8
  declare type Props = {
12
9
  pageSize?: number;
13
10
  gridColumns?: number;
@@ -17,9 +14,9 @@ declare type Props = {
17
14
  renderResultCard?: Parameters<typeof ResultCard>[0]["render"];
18
15
  renderPagination?: Parameters<typeof ResultPagination>[0]["render"];
19
16
  renderResultCardCallout?: Parameters<typeof ResultCardCallout>[0]["render"];
20
- renderAfter?: (props: ResultProps) => JSX.Element | null;
21
- renderBefore?: (props: ResultProps) => JSX.Element | null;
22
- renderResults?: (props: ResultProps) => JSX.Element | null;
17
+ renderAfter?: (props: ReactivesearchResultProps) => JSX.Element | null;
18
+ renderBefore?: (props: ReactivesearchResultProps) => JSX.Element | null;
19
+ renderResults?: (props: ReactivesearchResultProps) => JSX.Element | null;
23
20
  renderError?: (props: {
24
21
  error: ReactivesearchError;
25
22
  }) => JSX.Element | null;
@@ -13,20 +13,16 @@ const ResultLoadMoreButton_1 = require("./ResultLoadMoreButton");
13
13
  const ResultPaginationNextPrev_1 = require("./ResultPaginationNextPrev");
14
14
  const provider_1 = require("../provider");
15
15
  const hooks_1 = require("../hooks");
16
+ const elastic_1 = require("../types/elastic");
16
17
  const ResultList = (props) => {
17
- var _a, _b;
18
18
  const { pageSize } = props;
19
- const curation = (0, hooks_1.useCuration)();
20
- const { enableCallouts } = (0, provider_1.useContext)();
21
19
  const reactiveResultListProps = (0, hooks_1.useReactiveResultListProps)({
22
20
  pageSize,
23
- pageSizeAdjust: enableCallouts ? (_b = (_a = curation === null || curation === void 0 ? void 0 : curation.callouts) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0,
24
21
  });
25
22
  return (react_1.default.createElement(ReactiveList_1.default, Object.assign({}, reactiveResultListProps, { renderPagination: (reactivesearchPaginationProps) => (react_1.default.createElement(ResultPaginationInner, Object.assign({}, props, reactivesearchPaginationProps))), render: (reactivesearchResultProps) => (react_1.default.createElement(ResultListInner, Object.assign({}, props, { reactivesearchResultProps: reactivesearchResultProps }))) })));
26
23
  };
27
24
  exports.ResultList = ResultList;
28
25
  const ResultListInner = (props) => {
29
- var _a;
30
26
  const { gridColumns, renderError, renderAfter, renderBefore, renderLoading, listClassName, renderResults, renderNoResults, renderResultCard, renderLoadMoreButton, renderResultCardCallout, reactivesearchResultProps, } = props;
31
27
  const curation = (0, hooks_1.useCuration)();
32
28
  const filterStack = (0, hooks_1.useFilterStack)();
@@ -34,13 +30,6 @@ const ResultListInner = (props) => {
34
30
  const { enableCallouts } = (0, provider_1.useContext)();
35
31
  const initialSearchHasRun = react_1.default.useMemo(() => "undefined" !==
36
32
  typeof reactivesearchResultProps.resultStats.numberOfResults, [reactivesearchResultProps]);
37
- const combinedResults = (0, hooks_1.useCombinedResults)({
38
- callouts: (_a = curation === null || curation === void 0 ? void 0 : curation.callouts) !== null && _a !== void 0 ? _a : [],
39
- products: reactivesearchResultProps.data,
40
- });
41
- const resultProps = react_1.default.useMemo(() => {
42
- return Object.assign(Object.assign({}, reactivesearchResultProps), { results: combinedResults });
43
- }, [combinedResults, reactivesearchResultProps]);
44
33
  const styleProp = react_1.default.useMemo(() => !!enableCallouts
45
34
  ? {
46
35
  display: "grid",
@@ -65,21 +54,22 @@ const ResultListInner = (props) => {
65
54
  return react_1.default.createElement("div", null, "No results");
66
55
  }
67
56
  if (renderResults) {
68
- return renderResults(resultProps);
57
+ return renderResults(reactivesearchResultProps);
69
58
  }
70
59
  return (react_1.default.createElement(react_1.default.Fragment, null,
71
- renderBefore && renderBefore(resultProps),
72
- react_1.default.createElement("section", { className: listClassName, style: styleProp }, combinedResults.map((result, key) => {
73
- if ("product" === result.type) {
74
- return (react_1.default.createElement(ResultCard_1.ResultCard, { product: result.data, pagePosition: key + 1, render: renderResultCard, key: `product-${result.data._id}` }));
60
+ renderBefore && renderBefore(reactivesearchResultProps),
61
+ react_1.default.createElement("section", { className: listClassName, style: styleProp }, reactivesearchResultProps.data.map((result, key) => {
62
+ // @todo result.type is missing in v1 indexes, this check ensures that they are assumed to be products
63
+ if (elastic_1.ElasticDocumentType.Product === result.type || !result.type) {
64
+ return (react_1.default.createElement(ResultCard_1.ResultCard, { key: result._id, product: result, document: result, pagePosition: key + 1, render: renderResultCard }));
75
65
  }
76
- if (!!enableCallouts && "callout" === result.type) {
77
- return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { callout: result.data, pagePosition: key + 1, render: renderResultCardCallout, key: `callout-${result.data.id}` }));
66
+ if (!!enableCallouts && elastic_1.ElasticDocumentType.Callout === result.type) {
67
+ return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { key: result._id, document: result, pagePosition: key + 1, callout: result.callout, render: renderResultCardCallout }));
78
68
  }
79
69
  return null;
80
70
  })),
81
71
  !instantSearch && "load_more" === (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) && (react_1.default.createElement(ResultLoadMoreButton_1.ResultLoadMoreButton, Object.assign({}, reactivesearchResultProps, { render: renderLoadMoreButton }))),
82
- renderAfter && renderAfter(resultProps)));
72
+ renderAfter && renderAfter(reactivesearchResultProps)));
83
73
  };
84
74
  const ResultPaginationInner = (props) => {
85
75
  const { renderPagination, renderPaginationNextPrev } = props;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ReactivesearchResultProps } from "../types";
2
+ import { ReactivesearchResultProps } from "../types/reactivesearch";
3
3
  declare type Props = ReactivesearchResultProps & {
4
4
  render?: (props: Omit<Props, "render"> & {
5
5
  hasMore: boolean;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { usePages } from "../hooks";
3
- import { ReactivesearchPaginationProps } from "../types";
3
+ import { ReactivesearchPaginationProps } from "../types/reactivesearch";
4
4
  declare type Props = ReactivesearchPaginationProps & {
5
5
  render?: (props: Omit<Props, "render"> & ReturnType<typeof usePages>) => JSX.Element;
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { usePages } from "../hooks";
3
- import { ReactivesearchPaginationProps } from "../types";
3
+ import { ReactivesearchPaginationProps } from "../types/reactivesearch";
4
4
  declare type Props = ReactivesearchPaginationProps & {
5
5
  render?: (props: Omit<Props, "render"> & ReturnType<typeof usePages>) => JSX.Element;
6
6
  };
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ReactivesearchSearchStatePage } from "../types";
2
+ import { ReactivesearchSearchStatePage } from "../types/reactivesearch";
3
3
  declare type Props = {
4
4
  render: (props: ReactivesearchSearchStatePage) => JSX.Element | null;
5
5
  };
@@ -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 = (config, curation, sortState) => {
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
- sortState,
45
+ sortOption,
44
46
  });
45
- // return default collection position if unset
46
- if (!sortState) {
47
- return [{ "collections.position": "asc" }];
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 (!["collections.position", "_score"].includes(sortState.field)) {
52
- return [{ [sortState.field]: sortState.direction }];
55
+ if (!["_score", "collections.position"].includes(sortOption.field)) {
56
+ return [{ [sortOption.field]: sortOption.direction }];
53
57
  }
54
- // no matching curation, return default sort order
58
+ // no matching curation, return default sort clause
55
59
  if (!curation) {
56
- return [{ [sortState.field]: sortState.direction }];
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)