@usereactify/search 3.10.1 → 3.10.4-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
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __rest = (this && this.__rest) || function (s, e) {
3
22
  var t = {};
4
23
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -16,6 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
35
  Object.defineProperty(exports, "__esModule", { value: true });
17
36
  exports.useContext = exports.ConfiguredProvider = exports.Provider = void 0;
18
37
  const react_1 = __importDefault(require("react"));
38
+ const Sentry = __importStar(require("@sentry/react"));
19
39
  const hooks_1 = require("./hooks");
20
40
  const UtilityAuthenticatedReactiveBase_1 = require("./utility/UtilityAuthenticatedReactiveBase");
21
41
  const debug = require("debug")("reactify-search:Provider");
@@ -25,6 +45,9 @@ const defaultCredentials = {
25
45
  password: "password",
26
46
  endpoint: "https://api.search.reactify.app",
27
47
  };
48
+ Sentry.init({
49
+ dsn: "https://f591e13196ad4d6bbcd8abbeb2e023db@o1280055.ingest.sentry.io/6482743",
50
+ });
28
51
  const Provider = (_a) => {
29
52
  var { renderBooting } = _a, props = __rest(_a, ["renderBooting"]);
30
53
  const { config } = (0, hooks_1.useLiveConfig)(props.shopifyPermanentDomain);
@@ -33,7 +56,17 @@ const Provider = (_a) => {
33
56
  return renderBooting();
34
57
  return null;
35
58
  }
36
- return react_1.default.createElement(exports.ConfiguredProvider, Object.assign({}, props, { config: config }));
59
+ return (react_1.default.createElement(Sentry.ErrorBoundary, { fallback: react_1.default.createElement("p", null, "An error has occurred"), beforeCapture: (scope) => {
60
+ scope.setTag("index", props.index);
61
+ scope.setTag("shop", props.shopifyPermanentDomain);
62
+ if (!!props.collection)
63
+ scope.setTag("collection", props.collection.handle);
64
+ if (!!props.filterStackId)
65
+ scope.setTag("filterStackId", props.filterStackId);
66
+ if (!!props.instantSearch)
67
+ scope.setTag("instantSearch", true);
68
+ } },
69
+ react_1.default.createElement(exports.ConfiguredProvider, Object.assign({}, props, { config: config }))));
37
70
  };
38
71
  exports.Provider = Provider;
39
72
  const ConfiguredProvider = (props) => {
@@ -63,11 +96,29 @@ const ConfiguredProvider = (props) => {
63
96
  const urlParams = new URLSearchParams(window.location.search);
64
97
  return (_a = urlParams.get("q")) !== null && _a !== void 0 ? _a : undefined;
65
98
  }, [window.location.search]);
99
+ const searchSortFromURL = react_1.default.useMemo(() => {
100
+ var _a;
101
+ if (typeof window === "undefined")
102
+ return undefined;
103
+ const urlParams = new URLSearchParams(window.location.search);
104
+ return (_a = urlParams.get("sort")) !== null && _a !== void 0 ? _a : undefined;
105
+ }, [window.location.search]);
66
106
  const [searchQuery, setSearchQuery] = react_1.default.useState(searchQueryFromURL);
107
+ const { sortOption, sortOptions, setSortOption } = useSortState(config, collection);
67
108
  react_1.default.useEffect(() => {
68
- if (searchQuery !== searchQueryFromURL)
109
+ if (searchQueryFromURL && searchQuery !== searchQueryFromURL)
69
110
  setSearchQuery(searchQueryFromURL);
70
111
  }, [searchQueryFromURL]);
112
+ react_1.default.useEffect(() => {
113
+ if (searchSortFromURL && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.id) !== searchSortFromURL) {
114
+ setSortOption(searchSortFromURL, true);
115
+ }
116
+ }, [searchSortFromURL]);
117
+ react_1.default.useEffect(() => {
118
+ if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.id)) {
119
+ setSortOption(sortOptions[0].id, true);
120
+ }
121
+ }, [window.location.href]);
71
122
  const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
72
123
  const submitSearch = react_1.default.useCallback((localSearchQuery) => {
73
124
  const actualSearchQuery = localSearchQuery !== null && localSearchQuery !== void 0 ? localSearchQuery : searchQuery;
@@ -86,7 +137,6 @@ const ConfiguredProvider = (props) => {
86
137
  window.location.href = `/search?q=${actualSearchQuery}`;
87
138
  }
88
139
  }, [searchQuery]);
89
- const { sortOption, sortOptions, setSortOption } = useSortState(config, collection);
90
140
  // do not attempt to resolve a filter stack if in instantSearch mode
91
141
  const filterStack = instantSearch
92
142
  ? undefined
@@ -152,9 +202,16 @@ const useSortState = (config, collection) => {
152
202
  }, [config, collection]);
153
203
  const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.id);
154
204
  const sortOption = react_1.default.useMemo(() => sortOptions.find(({ id }) => id === sortOptionState) || sortOptions[0], [sortOptions, sortOptionState]);
155
- const setSortOption = react_1.default.useCallback((sortOptionId) => {
205
+ const setSortOption = react_1.default.useCallback((sortOptionId, ignoreHistoryState = false) => {
156
206
  setSortOptionState(sortOptionId);
157
- }, []);
207
+ if (!ignoreHistoryState) {
208
+ const url = new URL(window.location.href);
209
+ url.searchParams.has("sort")
210
+ ? url.searchParams.set("sort", sortOptionId)
211
+ : url.searchParams.append("sort", sortOptionId);
212
+ window.history.pushState({}, "", url.toString());
213
+ }
214
+ }, [window.location.href]);
158
215
  return react_1.default.useMemo(() => ({ sortOptions, sortOption, setSortOption }), [sortOption, sortOptions, setSortOption]);
159
216
  };
160
217
  // resolve the "filter" in use for this view
@@ -171,6 +228,12 @@ const useFilterStack = (config, collection, filterStackId) => react_1.default.us
171
228
  if (filterStack)
172
229
  return filterStack;
173
230
  }
231
+ // automatically select filter stack by collection if provided
232
+ if (collection === null || collection === void 0 ? void 0 : collection.handle) {
233
+ const filterStack = config.filters.find((filter) => { var _a; return (_a = filter.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
234
+ if (filterStack)
235
+ return filterStack;
236
+ }
174
237
  const type = !!collection ? "collection" : "search";
175
238
  return ((_a = config.filters.find((filter) => type === filter.type)) !== null && _a !== void 0 ? _a : config.filters[0]);
176
239
  }, [config, collection]);
@@ -120,6 +120,7 @@ export interface Filter {
120
120
  pageSize: number;
121
121
  keywords: string[];
122
122
  defaultSort: string;
123
+ collections: string[];
123
124
  type: "search" | "collection";
124
125
  paginationType: "pagination" | "load_more" | "next_prev" | "infinite_scroll";
125
126
  inventoryVisibility: "show_all" | "hide_products" | "hide_variants" | "hide_all";
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.10.1",
4
+ "version": "3.10.4-0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -12,7 +12,8 @@
12
12
  "scripts": {
13
13
  "watch": "tsc --watch",
14
14
  "release": "standard-version",
15
- "patch": "standard-version -r patch",
15
+ "release:patch": "standard-version --release-as patch",
16
+ "release:beta": "standard-version --prerelease",
16
17
  "build": "rimraf dist && tsc",
17
18
  "prettier": "prettier --write .",
18
19
  "storybook": "start-storybook -p 6006",
@@ -30,6 +31,7 @@
30
31
  ]
31
32
  },
32
33
  "dependencies": {
34
+ "@sentry/react": "7.1.1",
33
35
  "ahooks": "2.10.11",
34
36
  "axios": "0.26.1",
35
37
  "currency.js": "2.0.4",