@sledge-app/react-instant-search 2.0.73 → 2.0.75

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.
@@ -2716,7 +2716,7 @@ const WidgetRoot = (props) => {
2716
2716
  }
2717
2717
  };
2718
2718
  const handleSetWishlistData = async (isLoadMore = false, init = false) => {
2719
- var _a2, _b2, _c2;
2719
+ var _a2, _b2;
2720
2720
  const searchParams = new URLSearchParams(document.location.search);
2721
2721
  const getShareId = (params == null ? void 0 : params.shareId) ? params.shareId : (searchParams == null ? void 0 : searchParams.get(queryShareId)) || "";
2722
2722
  setIsLoading(isRefreshWidgetList ? true : !isLoadMore);
@@ -2743,15 +2743,16 @@ const WidgetRoot = (props) => {
2743
2743
  response = propsData;
2744
2744
  } else
2745
2745
  response = await getWishlist(queryParam);
2746
+ const responseData = (response == null ? void 0 : response.data) ?? [];
2746
2747
  run = ((_a2 = response == null ? void 0 : response.status) == null ? void 0 : _a2.code) === 200 || false;
2747
- valueWishlistData = !((_b2 = response.data) == null ? void 0 : _b2.length) ? [] : (prevState) => (wishlistData == null ? void 0 : wishlistData.length) && isLoadMore ? [...prevState, ...response.data] : response.data;
2748
- valueTotalPage = ((_c2 = response == null ? void 0 : response.page) == null ? void 0 : _c2.total_page) || 1;
2748
+ valueWishlistData = !responseData.length ? [] : (prevState) => (wishlistData == null ? void 0 : wishlistData.length) && isLoadMore ? [...prevState, ...responseData] : responseData;
2749
+ valueTotalPage = ((_b2 = response == null ? void 0 : response.page) == null ? void 0 : _b2.total_page) || 1;
2749
2750
  if (run) {
2750
2751
  setWishlistData(valueWishlistData);
2751
2752
  setTotalPage(valueTotalPage);
2752
- setIsLoading(false);
2753
- setIsRefreshWidgetList(false);
2754
2753
  }
2754
+ setIsLoading(false);
2755
+ setIsRefreshWidgetList(false);
2755
2756
  };
2756
2757
  const handleShareData = async () => {
2757
2758
  var _a2, _b2, _c2, _d;
@@ -3184,7 +3185,8 @@ const Badge = (props) => {
3184
3185
  setOpen: setOpenFlyoutWishlistWidget,
3185
3186
  position: "right",
3186
3187
  className: "sledge-flyout-widget__wishlist",
3187
- withBlurEffect: true
3188
+ withBlurEffect: true,
3189
+ unmountContentOnLoading: false
3188
3190
  }
3189
3191
  ) : null,
3190
3192
  isFirstLoading ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: position === "none" ? /* @__PURE__ */ jsxRuntimeExports.jsx(HeaderMenu, {}) : String(position).includes("bottom") ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingIcon, {}) : /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingFull, {}) })
@@ -5866,7 +5868,18 @@ const DotButton = (props) => {
5866
5868
  return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { type: "button", ...restProps, children });
5867
5869
  };
5868
5870
  const FlyoutSidebar$1 = "";
5869
- const FlyoutSidebar = ({ title, content, footer = null, open, setOpen, position = "left", className = "", withBlurEffect = false, flyoutInfoContent = null }) => {
5871
+ const FlyoutSidebar = ({
5872
+ title,
5873
+ content,
5874
+ footer = null,
5875
+ open,
5876
+ setOpen,
5877
+ position = "left",
5878
+ className = "",
5879
+ withBlurEffect = false,
5880
+ flyoutInfoContent = null,
5881
+ unmountContentOnLoading = true
5882
+ }) => {
5870
5883
  const [isLoading, setIsLoading] = React__default.useState(false);
5871
5884
  const [isScrollAtBottom, setIsScrollAtBottom] = React__default.useState(false);
5872
5885
  const contentContainerRef = React__default.useRef(null);
@@ -5915,11 +5928,11 @@ const FlyoutSidebar = ({ title, content, footer = null, open, setOpen, position
5915
5928
  {
5916
5929
  ref: contentContainerRef,
5917
5930
  className: `sledge__flyout-mobile-content ${showBlurEffect ? "sledge__flyout-mobile-content-blur-effect" : ""}`,
5918
- style: isLoading ? { display: "none" } : void 0,
5919
- children: content
5931
+ style: unmountContentOnLoading && isLoading ? { display: "none" } : void 0,
5932
+ children: unmountContentOnLoading && isLoading ? null : content
5920
5933
  }
5921
5934
  ),
5922
- footer ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__flyout-mobile-footer", style: isLoading ? { display: "none" } : void 0, children: footer }) : null
5935
+ footer ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__flyout-mobile-footer", style: unmountContentOnLoading && isLoading ? { display: "none" } : void 0, children: unmountContentOnLoading && isLoading ? null : footer }) : null
5923
5936
  ] })
5924
5937
  ] }),
5925
5938
  document.body
@@ -6207,7 +6220,7 @@ const SearchIconWidgetPopup = () => {
6207
6220
  let response;
6208
6221
  let body = {
6209
6222
  queries: tabs.map((tab) => {
6210
- var _a3, _b3, _c3;
6223
+ var _a3, _b3, _c3, _d3;
6211
6224
  const { index } = tab;
6212
6225
  let isProductIndex = index.includes(index_product);
6213
6226
  let additionalFilter = DEFAULT_QUERY_PRODUCT_MEILISEARCH;
@@ -6242,12 +6255,13 @@ const SearchIconWidgetPopup = () => {
6242
6255
  let filterProduct = additionalFilter;
6243
6256
  if (containsFilter)
6244
6257
  filterProduct = filterProduct.concat(containsFilter);
6258
+ let hiddenCollectionsFilter = index === (instantSearchSettings == null ? void 0 : instantSearchSettings.index_collection) && ((_d3 = instantSearchSettings == null ? void 0 : instantSearchSettings.hidden_collections) == null ? void 0 : _d3.length) ? `'id' NOT IN ${JSON.stringify(instantSearchSettings.hidden_collections)}` : null;
6245
6259
  return {
6246
6260
  indexUid: index,
6247
6261
  q: valueKeyword,
6248
6262
  sort,
6249
6263
  hitsPerPage: isProductIndex ? instantSearchLimit : 4,
6250
- filter: isProductIndex ? [...new Set(filterProduct)].join(" AND ") : "",
6264
+ filter: isProductIndex ? [...new Set(filterProduct)].join(" AND ") : [hiddenCollectionsFilter].filter(Boolean).join(" AND "),
6251
6265
  attributesToRetrieve: attributes_to_retrieve
6252
6266
  };
6253
6267
  })
@@ -7010,7 +7024,7 @@ const keyOpenFilters = ({ items = [] }) => {
7010
7024
  }).filter((item) => item) : [];
7011
7025
  };
7012
7026
  const handleSearchResponse = async (props) => {
7013
- var _a, _b, _c, _d;
7027
+ var _a, _b, _c, _d, _e;
7014
7028
  let {
7015
7029
  layoutType = "default",
7016
7030
  clickedTabIndexId,
@@ -7100,6 +7114,10 @@ const handleSearchResponse = async (props) => {
7100
7114
  if (isTypeCategoryHasPublished({ usePublishedFilter, type: clickedTabIndexType })) {
7101
7115
  filterCategory = DEFAULT_QUERY_PUBLISHED_FILTER;
7102
7116
  }
7117
+ let hiddenCollectionsCategoryFilter = String(clickedTabIndexId) === (instantSearchSettings == null ? void 0 : instantSearchSettings.index_collection) && ((_e = instantSearchSettings == null ? void 0 : instantSearchSettings.hidden_collections) == null ? void 0 : _e.length) ? `'id' NOT IN ${JSON.stringify(instantSearchSettings.hidden_collections)}` : null;
7118
+ if (hiddenCollectionsCategoryFilter) {
7119
+ filterCategory = [filterCategory, hiddenCollectionsCategoryFilter].filter(Boolean).join(" AND ");
7120
+ }
7103
7121
  let bodyProductOrCategory = isResultForProduct ? {
7104
7122
  q: keyword,
7105
7123
  sort,
@@ -7124,15 +7142,20 @@ const handleSearchResponse = async (props) => {
7124
7142
  let getTabs = isUseMultiSearch ? tabs : tabs.filter(({ index }) => index == null ? void 0 : index.includes(clickedTabIndexId));
7125
7143
  let body = {
7126
7144
  queries: getTabs.map((tab) => {
7145
+ var _a2;
7127
7146
  const { index, type } = tab;
7128
7147
  let isCurrentIndex = index.includes(clickedTabIndexId);
7129
7148
  let isProductIndex = type === "product";
7149
+ let hiddenCollectionsFilter = index === (instantSearchSettings == null ? void 0 : instantSearchSettings.index_collection) && ((_a2 = instantSearchSettings == null ? void 0 : instantSearchSettings.hidden_collections) == null ? void 0 : _a2.length) ? `'id' NOT IN ${JSON.stringify(instantSearchSettings.hidden_collections)}` : null;
7130
7150
  return {
7131
7151
  indexUid: index,
7132
7152
  ...isCurrentIndex ? bodyProductOrCategory : {
7133
7153
  q: keyword || "",
7134
7154
  hitsPerPage: 1,
7135
- filter: isTypeCategoryHasPublished({ usePublishedFilter, type }) ? DEFAULT_QUERY_PUBLISHED_FILTER : isProductIndex ? filterProduct : "",
7155
+ filter: [
7156
+ isTypeCategoryHasPublished({ usePublishedFilter, type }) ? DEFAULT_QUERY_PUBLISHED_FILTER : isProductIndex ? filterProduct : "",
7157
+ hiddenCollectionsFilter
7158
+ ].filter(Boolean).join(" AND "),
7136
7159
  attributesToRetrieve: [],
7137
7160
  limit: 0,
7138
7161
  page: 0,
@@ -9701,9 +9724,9 @@ const SearchResultWidget = (props) => {
9701
9724
  valueHierarchicalFacetAliases
9702
9725
  };
9703
9726
  };
9704
- const handleSetInitStates = ({ results = {}, data = {}, callback, isUpdateFilter = false }) => {
9727
+ const handleSetInitStates = ({ results = {}, data, callback, isUpdateFilter = false }) => {
9705
9728
  var _a2, _b2, _c2;
9706
- const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
9729
+ const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data ?? {};
9707
9730
  const {
9708
9731
  facetStats,
9709
9732
  totalHits: totalHitsResult,
@@ -9778,15 +9801,16 @@ const SearchResultWidget = (props) => {
9778
9801
  });
9779
9802
  };
9780
9803
  const handleInitStates = async (data) => {
9781
- const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
9782
- let getTabs = layoutType === "product-filter" ? tabs2.filter(({ index }) => index == null ? void 0 : index.includes(index_product)) : tabs2;
9783
- getTabs.map((tab) => {
9784
- var _a2, _b2, _c2, _d2, _e2, _f2;
9804
+ var _a2, _b2;
9805
+ const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data ?? {};
9806
+ const getTabs = layoutType === "product-filter" ? (_a2 = tabs2 == null ? void 0 : tabs2.filter) == null ? void 0 : _a2.call(tabs2, ({ index }) => index == null ? void 0 : index.includes(index_product)) : tabs2;
9807
+ (_b2 = getTabs == null ? void 0 : getTabs.map) == null ? void 0 : _b2.call(getTabs, (tab) => {
9808
+ var _a3, _b3, _c2, _d2, _e2, _f2;
9785
9809
  const { index } = tab;
9786
9810
  let isSetFilter2 = false;
9787
9811
  let getFacets = [];
9788
9812
  if (!isSetFilter2) {
9789
- let allowedFiltersCollectionId = (_c2 = (_b2 = (_a2 = filters == null ? void 0 : filters.map) == null ? void 0 : _a2.call(filters, (filter) => {
9813
+ let allowedFiltersCollectionId = (_c2 = (_b3 = (_a3 = filters == null ? void 0 : filters.map) == null ? void 0 : _a3.call(filters, (filter) => {
9790
9814
  const { active, collections, items } = filter;
9791
9815
  if (!active)
9792
9816
  return;
@@ -9796,7 +9820,7 @@ const SearchResultWidget = (props) => {
9796
9820
  } else {
9797
9821
  return;
9798
9822
  }
9799
- })) == null ? void 0 : _b2.filter) == null ? void 0 : _c2.call(_b2, (item) => item);
9823
+ })) == null ? void 0 : _b3.filter) == null ? void 0 : _c2.call(_b3, (item) => item);
9800
9824
  let allowedFiltersCollectionAll = (_f2 = (_e2 = (_d2 = filters == null ? void 0 : filters.map) == null ? void 0 : _d2.call(filters, (filter) => {
9801
9825
  const { active, collections, items } = filter;
9802
9826
  if (!active)
@@ -10754,8 +10778,8 @@ const ResultProduct = React__default.memo((props) => {
10754
10778
  let isCurrentIndex = index.includes(clickedTabIndexId);
10755
10779
  let tabTotal = isCurrentIndex ? totalHits : total;
10756
10780
  if (layoutType === "default" && ((_a3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _a3.length)) {
10757
- const { totalHits: totalHits2 } = (_c2 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c2.call(_b3, ({ indexUid }) => indexUid.includes(index));
10758
- tabTotal = totalHits2 || tabTotal;
10781
+ const { totalHits: totalHitsFromIndex } = ((_c2 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c2.call(_b3, ({ indexUid }) => indexUid.includes(index))) || {};
10782
+ tabTotal = totalHitsFromIndex ?? tabTotal;
10759
10783
  }
10760
10784
  return {
10761
10785
  ...tab,
@@ -11689,7 +11713,7 @@ const SearchWidget = (props) => {
11689
11713
  let response;
11690
11714
  let body = {
11691
11715
  queries: tabs.map((tab) => {
11692
- var _a3, _b3, _c3;
11716
+ var _a3, _b3, _c3, _d3;
11693
11717
  const { index } = tab;
11694
11718
  let isProductIndex = index.includes(index_product);
11695
11719
  let additionalFilter = DEFAULT_QUERY_PRODUCT_MEILISEARCH;
@@ -11724,12 +11748,13 @@ const SearchWidget = (props) => {
11724
11748
  let filterProduct = additionalFilter;
11725
11749
  if (containsFilter)
11726
11750
  filterProduct = filterProduct.concat(containsFilter);
11751
+ let hiddenCollectionsFilter = index === (instantSearchSettings == null ? void 0 : instantSearchSettings.index_collection) && ((_d3 = instantSearchSettings == null ? void 0 : instantSearchSettings.hidden_collections) == null ? void 0 : _d3.length) ? `'id' NOT IN ${JSON.stringify(instantSearchSettings.hidden_collections)}` : null;
11727
11752
  return {
11728
11753
  indexUid: index,
11729
11754
  q: valueKeyword,
11730
11755
  sort,
11731
11756
  hitsPerPage: isProductIndex ? instantSearchLimit : 4,
11732
- filter: isProductIndex ? [...new Set(filterProduct)].join(" AND ") : "",
11757
+ filter: isProductIndex ? [...new Set(filterProduct)].join(" AND ") : [hiddenCollectionsFilter].filter(Boolean).join(" AND "),
11733
11758
  attributesToRetrieve: attributes_to_retrieve
11734
11759
  };
11735
11760
  })