@sledge-app/react-instant-search 1.0.99 → 1.0.100

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.
@@ -1016,6 +1016,15 @@ const FilterIcon = ({ width, height, color }) => {
1016
1016
  )
1017
1017
  ] }) });
1018
1018
  };
1019
+ const InfoCircleIcon = ({ width, height, color }) => {
1020
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-icon__info-circle", children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width, height, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1021
+ "path",
1022
+ {
1023
+ d: "M12 2.00293C6.49 2.00293 2 6.49293 2 12.0029C2 17.5129 6.49 22.0029 12 22.0029C17.51 22.0029 22 17.5129 22 12.0029C22 6.49293 17.51 2.00293 12 2.00293ZM11.25 8.00293C11.25 7.59293 11.59 7.25293 12 7.25293C12.41 7.25293 12.75 7.59293 12.75 8.00293V13.0029C12.75 13.4129 12.41 13.7529 12 13.7529C11.59 13.7529 11.25 13.4129 11.25 13.0029V8.00293ZM12.92 16.3829C12.87 16.5129 12.8 16.6129 12.71 16.7129C12.61 16.8029 12.5 16.8729 12.38 16.9229C12.26 16.9729 12.13 17.0029 12 17.0029C11.87 17.0029 11.74 16.9729 11.62 16.9229C11.5 16.8729 11.39 16.8029 11.29 16.7129C11.2 16.6129 11.13 16.5129 11.08 16.3829C11.03 16.2629 11 16.1329 11 16.0029C11 15.8729 11.03 15.7429 11.08 15.6229C11.13 15.5029 11.2 15.3929 11.29 15.2929C11.39 15.2029 11.5 15.1329 11.62 15.0829C11.86 14.9829 12.14 14.9829 12.38 15.0829C12.5 15.1329 12.61 15.2029 12.71 15.2929C12.8 15.3929 12.87 15.5029 12.92 15.6229C12.97 15.7429 13 15.8729 13 16.0029C13 16.1329 12.97 16.2629 12.92 16.3829Z",
1024
+ fill: color
1025
+ }
1026
+ ) }) });
1027
+ };
1019
1028
  const Button$1 = "";
1020
1029
  const Button = React__default.forwardRef((props, buttonRef) => {
1021
1030
  const { className = "", children, colorType = "light", fullWidth = false, elementType = "button", link = "", isActive, ...otherProps } = props;
@@ -3935,6 +3944,13 @@ const VirtualizedList = ({ scrollElement, rowCount, rowRenderer: rowRenderer2, s
3935
3944
  }
3936
3945
  );
3937
3946
  };
3947
+ const Alert$1 = "";
3948
+ const Alert = ({ children, className = "", type, icon = null }) => {
3949
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `sledge__alert ${className}`, "data-alert-type": type, children: [
3950
+ icon && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: icon }),
3951
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children })
3952
+ ] });
3953
+ };
3938
3954
  const SearchIconWidget = (props) => {
3939
3955
  const { isRenderApp, isJsVersion, componentRef } = React__default.useContext(SledgeContext);
3940
3956
  const { instantSearch: isRenderAppInstantSearch } = isRenderApp || {};
@@ -4134,11 +4150,13 @@ const SearchIconWidgetPopup = () => {
4134
4150
  searchViewMoreResultComponent: null,
4135
4151
  query: {}
4136
4152
  });
4153
+ const [totalHitsProduct, setTotalHitsProduct] = React__default.useState(0);
4154
+ const [instantSearchSettings, setInstantSearchSettings] = React__default.useState({});
4137
4155
  const searchFieldRef = React__default.useRef(null);
4138
4156
  const previousState = usePrevious({ keyword });
4139
4157
  const { direction: redirectObjectDirection } = redirectObject || {};
4140
4158
  const handleMultiSearch = async (params) => {
4141
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2;
4159
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
4142
4160
  const { data, onSearch = false, withFetchReviewInfo = false } = params;
4143
4161
  const valueRedirectObject = redirectsSettings.find(({ keyword: redirectKeyword }) => {
4144
4162
  var _a3;
@@ -4174,13 +4192,14 @@ const SearchIconWidgetPopup = () => {
4174
4192
  return;
4175
4193
  const { results } = response;
4176
4194
  let valueSearchResultProduct = results == null ? void 0 : results.filter(({ indexUid }) => indexUid == null ? void 0 : indexUid.includes(index_product));
4195
+ setTotalHitsProduct(((_c2 = valueSearchResultProduct[0]) == null ? void 0 : _c2.totalHits) || 0);
4177
4196
  if (onSearch && (keyword == null ? void 0 : keyword.length)) {
4178
4197
  searchTrigger({
4179
4198
  keyword,
4180
- resultCount: ((_c2 = valueSearchResultProduct[0]) == null ? void 0 : _c2.totalHits) || 0
4199
+ resultCount: ((_d2 = valueSearchResultProduct[0]) == null ? void 0 : _d2.totalHits) || 0
4181
4200
  });
4182
4201
  }
4183
- let valueSearchResultOther = ((_d2 = results == null ? void 0 : results.filter(({ indexUid }) => !(indexUid == null ? void 0 : indexUid.includes(index_product)))) == null ? void 0 : _d2.map((result) => {
4202
+ let valueSearchResultOther = ((_e2 = results == null ? void 0 : results.filter(({ indexUid }) => !(indexUid == null ? void 0 : indexUid.includes(index_product)))) == null ? void 0 : _e2.map((result) => {
4184
4203
  const { indexUid } = result;
4185
4204
  const { name, type } = tabs == null ? void 0 : tabs.find(({ index }) => index.includes(indexUid));
4186
4205
  return {
@@ -4191,16 +4210,16 @@ const SearchIconWidgetPopup = () => {
4191
4210
  }
4192
4211
  };
4193
4212
  })) || [];
4194
- let getValueSearchResultProduct = (valueSearchResultProduct == null ? void 0 : valueSearchResultProduct.length) ? (_e2 = valueSearchResultProduct[0]) == null ? void 0 : _e2.hits : [];
4213
+ let getValueSearchResultProduct = (valueSearchResultProduct == null ? void 0 : valueSearchResultProduct.length) ? (_f2 = valueSearchResultProduct[0]) == null ? void 0 : _f2.hits : [];
4195
4214
  let valueSuggestionIndex = !keyword.length ? "zero_character" : !(getValueSearchResultProduct == null ? void 0 : getValueSearchResultProduct.length) ? "no_result" : "";
4196
4215
  let isPriorityZeroCharacter = Boolean(
4197
- !keyword.length && Object.keys(suggestion).length && ((_g2 = (_f2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _f2.products) == null ? void 0 : _g2.active) && ((_j2 = (_i2 = (_h2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _h2.products) == null ? void 0 : _i2.list) == null ? void 0 : _j2.length)
4216
+ !keyword.length && Object.keys(suggestion).length && ((_h2 = (_g2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _g2.products) == null ? void 0 : _h2.active) && ((_k2 = (_j2 = (_i2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _i2.products) == null ? void 0 : _j2.list) == null ? void 0 : _k2.length)
4198
4217
  );
4199
- let dataSearchResultProduct = isPriorityZeroCharacter ? (_l2 = (_k2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _k2.products) == null ? void 0 : _l2.list : getValueSearchResultProduct;
4218
+ let dataSearchResultProduct = isPriorityZeroCharacter ? (_m2 = (_l2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _l2.products) == null ? void 0 : _m2.list : getValueSearchResultProduct;
4200
4219
  if (withFetchReviewInfo) {
4201
4220
  let searchResultProductIds = dataSearchResultProduct.map(({ id }) => id);
4202
4221
  let valueDataReviews = await getProductsReviewInfo(searchResultProductIds);
4203
- if (((_m2 = valueDataReviews == null ? void 0 : valueDataReviews.status) == null ? void 0 : _m2.code) === 200)
4222
+ if (((_n2 = valueDataReviews == null ? void 0 : valueDataReviews.status) == null ? void 0 : _n2.code) === 200)
4204
4223
  setDataReviews(valueDataReviews == null ? void 0 : valueDataReviews.data);
4205
4224
  } else {
4206
4225
  setDataReviews({});
@@ -4216,6 +4235,7 @@ const SearchIconWidgetPopup = () => {
4216
4235
  response = JSON.parse(LOCAL_STORAGE_INSTANT_SEARCH_SETTING);
4217
4236
  if (!response)
4218
4237
  return;
4238
+ setInstantSearchSettings(response);
4219
4239
  const { display, languages, redirects } = response;
4220
4240
  setDisplaySettings(display);
4221
4241
  setSuggestionSettings((_a2 = display == null ? void 0 : display.search) == null ? void 0 : _a2.suggestion);
@@ -4285,10 +4305,16 @@ const SearchIconWidgetPopup = () => {
4285
4305
  return () => clearTimeout(delayDebounceFn);
4286
4306
  }
4287
4307
  }, [keyword]);
4308
+ const alertFirstSyncComponent = !isLoading && !totalHitsProduct && (instantSearchSettings == null ? void 0 : instantSearchSettings.first_sync) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { className: "sledge-instant-search__icon-widget-popup-alert-first-sync", type: "info", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(InfoCircleIcon, { width: 24, height: 24, color: "#003a5a" }), children: [
4309
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Products and Collections indexing is in progress. Product Filter and Instant Search widgets may appear empty during this process." }),
4310
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", {}),
4311
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "The products and collections will become visible in the widgets once indexing is complete." })
4312
+ ] }) : null;
4288
4313
  return /* @__PURE__ */ jsxRuntimeExports.jsx($5d3850c4d0b4e6c7$export$be92b6f5f03c0fe9, { open: showInfo, onOpenChange: setShowInfo, children: /* @__PURE__ */ jsxRuntimeExports.jsxs($5d3850c4d0b4e6c7$export$602eac185826482c, { children: [
4289
4314
  /* @__PURE__ */ jsxRuntimeExports.jsx($5d3850c4d0b4e6c7$export$c6fdb837b070b4ff, { className: "sledge__popup-overlay" }),
4290
4315
  /* @__PURE__ */ jsxRuntimeExports.jsx($5d3850c4d0b4e6c7$export$c6fdb837b070b4ff, { className: "sledge__popup-overlay-blur" }),
4291
4316
  /* @__PURE__ */ jsxRuntimeExports.jsxs($5d3850c4d0b4e6c7$export$7c6e2c02157bb7d2, { className: "sledge-instant-search__icon-widget-popup-detail-content", "data-layout-type": ((_a = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _a.layout) || "", children: [
4317
+ alertFirstSyncComponent,
4292
4318
  /* @__PURE__ */ jsxRuntimeExports.jsx(
4293
4319
  SearchInputField,
4294
4320
  {
@@ -5307,6 +5333,7 @@ const SearchResultWidget = (props) => {
5307
5333
  const [isReplaceWidgetList, setIsReplaceWidgetList] = React__default.useState(false);
5308
5334
  const [searchResultFacets, setSearchResultFacets] = React__default.useState({});
5309
5335
  const [generalDataSettings, setGeneralDataSettings] = React__default.useState((sledgeSettings == null ? void 0 : sledgeSettings.general) || {});
5336
+ const [instantSearchSettings, setInstantSearchSettings] = React__default.useState((sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) || {});
5310
5337
  const [clickedFacets, setClickedFacets] = React__default.useState({});
5311
5338
  const [clickedOpenFilterHorizontalId, setClickedOpenFilterHorizontalId] = React__default.useState(null);
5312
5339
  const [clickedOpenFilterHorizontalMobileId, setClickedOpenFilterHorizontalMobileId] = React__default.useState(null);
@@ -5315,6 +5342,7 @@ const SearchResultWidget = (props) => {
5315
5342
  const [mobileShowSelectedSort, setMobileShowSelectedSort] = React__default.useState(true);
5316
5343
  const [soldProductAtEnd, setSoldProductAtEnd] = React__default.useState(false);
5317
5344
  const [attributesToRetrieve, setAttributesToRetrieve] = React__default.useState(((_k = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _k.attributes_to_retrieve) || []);
5345
+ const [totalHitsProduct, setTotalHitsProduct] = React__default.useState(0);
5318
5346
  const debouncedKeyword = useDebounce(keyword, 500);
5319
5347
  let productCardsComponent = null;
5320
5348
  let collectionCardsComponent = null;
@@ -5408,6 +5436,7 @@ const SearchResultWidget = (props) => {
5408
5436
  setIsFirstLoading(false);
5409
5437
  setIsLoading(false);
5410
5438
  const { facetStats, totalHits, facetDistribution } = (results == null ? void 0 : results.find(({ indexUid }) => indexUid.includes(index_product))) || {};
5439
+ setTotalHitsProduct(totalHits || 0);
5411
5440
  let valueHideFilterWhenOneValue = ((_a2 = display == null ? void 0 : display.filter) == null ? void 0 : _a2.hide_when_one_value) && totalHits <= 1;
5412
5441
  let valueSearchResultFacets = facetDistribution ? Object.fromEntries(
5413
5442
  Object.entries(facetDistribution).map((facet) => {
@@ -5519,6 +5548,7 @@ const SearchResultWidget = (props) => {
5519
5548
  responseGeneral = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5520
5549
  if (!response)
5521
5550
  return;
5551
+ setInstantSearchSettings(response);
5522
5552
  if (responseGeneral)
5523
5553
  setGeneralDataSettings(responseGeneral);
5524
5554
  const {
@@ -5856,7 +5886,13 @@ const SearchResultWidget = (props) => {
5856
5886
  const containerStyle = {
5857
5887
  maxWidth: width
5858
5888
  };
5889
+ const alertFirstSyncComponent = !isFirstLoading && !totalHitsProduct && (instantSearchSettings == null ? void 0 : instantSearchSettings.first_sync) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { className: "sledge-instant-search__alert-first-sync-product", type: "info", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(InfoCircleIcon, { width: 24, height: 24, color: "#003a5a" }), children: [
5890
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Products and Collections indexing is in progress. Product Filter and Instant Search widgets may appear empty during this process." }),
5891
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", {}),
5892
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "The products and collections will become visible in the widgets once indexing is complete." })
5893
+ ] }) : null;
5859
5894
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-container", ref: searchResultContainerRef, style: containerStyle, children: [
5895
+ alertFirstSyncComponent,
5860
5896
  isFirstLoading ? tabSkeleton : layoutType === "default" && (allowedTabs == null ? void 0 : allowedTabs.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${layoutType === "default" && (allowedTabs == null ? void 0 : allowedTabs.length) ? "sledge-instant-search__result-tab" : "sledge-instant-search__result-tab-no-index"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__result-tab-list", children: allowedTabs.map((item) => {
5861
5897
  const { name, index, type, total } = item;
5862
5898
  let isActive = clickedTabIndexId === index;