@sledge-app/react-instant-search 2.0.37 → 2.0.38

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.
@@ -6346,10 +6346,10 @@ const detectQueryStringFilter = ({ facets, facetsQueryStringObject, callback })
6346
6346
  const searchParamsObject = Object.fromEntries(searchParams);
6347
6347
  for (const searchParamsKey in searchParamsObject) {
6348
6348
  let ifFacetsQueryStringObject = (facets == null ? void 0 : facets.length) && facets.includes(searchParamsKey);
6349
- if (ifFacetsQueryStringObject)
6349
+ if (ifFacetsQueryStringObject && typeof facetsQueryStringObject === "object")
6350
6350
  facetsQueryStringObject[searchParamsKey] = (_b = (_a = searchParamsObject[searchParamsKey].split(",")) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (item) => decodeURIComponent(item));
6351
6351
  }
6352
- if (Object.keys(facetsQueryStringObject).length)
6352
+ if (facetsQueryStringObject && Object.keys(facetsQueryStringObject).length)
6353
6353
  callback(facetsQueryStringObject);
6354
6354
  return facetsQueryStringObject;
6355
6355
  };
@@ -6366,19 +6366,21 @@ const detectArrFacetHierarchical = ({
6366
6366
  }
6367
6367
  return { ...item, [key]: defaultLevelHierarchical };
6368
6368
  }, {});
6369
- Object.entries(clickedFacetsObject).map((facet) => {
6370
- var _a, _b;
6371
- if ((facet == null ? void 0 : facet.length) && facet[1].length) {
6372
- const isCollection = (_a = String(facet[0])) == null ? void 0 : _a.includes(HIERARCHICAL_FACET_OBJECT_ALIASES.collections);
6373
- let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(facet[0]);
6374
- if (isHierarchical)
6375
- (_b = facet[1]) == null ? void 0 : _b.map((item) => {
6376
- const arrItem = String(item).split(isCollection ? separatorCollection : separator);
6377
- if ((arrItem == null ? void 0 : arrItem.length) && Object.hasOwn(facetHierarchical[facet[0]], `lvl${arrItem.length - 1}`))
6378
- facetHierarchical[facet[0]][`lvl${arrItem.length - 1}`].push(item);
6379
- });
6380
- }
6381
- });
6369
+ if (clickedFacetsObject && Object.keys(clickedFacetsObject).length) {
6370
+ Object.entries(clickedFacetsObject).map((facet) => {
6371
+ var _a, _b;
6372
+ if ((facet == null ? void 0 : facet.length) && facet[1].length) {
6373
+ const isCollection = (_a = String(facet[0])) == null ? void 0 : _a.includes(HIERARCHICAL_FACET_OBJECT_ALIASES.collections);
6374
+ let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(facet[0]);
6375
+ if (isHierarchical)
6376
+ (_b = facet[1]) == null ? void 0 : _b.map((item) => {
6377
+ const arrItem = String(item).split(isCollection ? separatorCollection : separator);
6378
+ if ((arrItem == null ? void 0 : arrItem.length) && Object.hasOwn(facetHierarchical[facet[0]], `lvl${arrItem.length - 1}`))
6379
+ facetHierarchical[facet[0]][`lvl${arrItem.length - 1}`].push(item);
6380
+ });
6381
+ }
6382
+ });
6383
+ }
6382
6384
  return facetHierarchical;
6383
6385
  };
6384
6386
  const createQueryFilter = ({
@@ -6405,7 +6407,7 @@ const createQueryFilter = ({
6405
6407
  separatorCollection,
6406
6408
  hierarchicalFacetAliases
6407
6409
  });
6408
- const facetEntries = Object.entries(detectClickedFacets) || [];
6410
+ const facetEntries = detectClickedFacets && Object.keys(detectClickedFacets).length ? Object.entries(detectClickedFacets) : [];
6409
6411
  let filterCustomByObject = [];
6410
6412
  for (const facetEntry of facetEntries) {
6411
6413
  const detectClickedFacet = facetEntry;
@@ -10358,14 +10360,14 @@ const ResultProduct = React__default.memo((props) => {
10358
10360
  });
10359
10361
  return dataClickedFacets2;
10360
10362
  };
10361
- const handleSearchResultData = (props2) => {
10363
+ const handleSearchResultData = async (props2) => {
10362
10364
  var _a2, _b2;
10363
10365
  const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
10364
10366
  const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
10365
10367
  const { index_product } = INSTANT_SEARCH_SETTING || {};
10366
10368
  const isNoneFacetSelected = Boolean(!((_a2 = handleDataClickedFacets()) == null ? void 0 : _a2.length));
10367
10369
  const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
10368
- const resultData = layoutType === "default" && isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
10370
+ let resultData = layoutType === "default" && isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
10369
10371
  const result = layoutType === "default" && isFirstTimeOrOnSearch ? (_b2 = resultData == null ? void 0 : resultData.find) == null ? void 0 : _b2.call(resultData, ({ indexUid }) => indexUid.includes(index_product)) : resultData;
10370
10372
  if (!result)
10371
10373
  return;
@@ -10396,6 +10398,30 @@ const ResultProduct = React__default.memo((props) => {
10396
10398
  if (objectPresent(previewSettings))
10397
10399
  updateTabs();
10398
10400
  if (isFirstTimeOrOnSearch || isNoneFacetSelected) {
10401
+ if (handleSearchResultFirstTime && initStatesFirstTime && clickedFacets && Object.keys(clickedFacets).length) {
10402
+ const initData = await handleSearchResponse({
10403
+ layoutType,
10404
+ clickedTabIndexId,
10405
+ clickedTabIndexType,
10406
+ page: 0,
10407
+ limit: 0,
10408
+ isUseMultiSearch: handleSearchResultFirstTime && initStatesFirstTime || onSearch,
10409
+ facets,
10410
+ attributesToRetrieve,
10411
+ allowedFilterSlider,
10412
+ hierarchicalFacetAliases,
10413
+ defaultFilterItems,
10414
+ collectionId,
10415
+ hiddenTags,
10416
+ showOutOfStock,
10417
+ hierarchicalProductTypeSettings,
10418
+ hierarchicalCollectionsSettings,
10419
+ usePublishedFilter,
10420
+ tabs,
10421
+ instantSearchSettings
10422
+ });
10423
+ resultData = layoutType === "default" && isFirstTimeOrOnSearch ? initData == null ? void 0 : initData.results : initData;
10424
+ }
10399
10425
  handleSetInitStates == null ? void 0 : handleSetInitStates({
10400
10426
  results: resultData,
10401
10427
  data: INSTANT_SEARCH_SETTING,
@@ -10491,7 +10517,7 @@ const ResultProduct = React__default.memo((props) => {
10491
10517
  }
10492
10518
  setHandleSearchResultFirstTime(false);
10493
10519
  setInitStatesFirstTime == null ? void 0 : setInitStatesFirstTime(false);
10494
- handleSearchResultData({
10520
+ await handleSearchResultData({
10495
10521
  result: response,
10496
10522
  ...props2
10497
10523
  });