Skip to content

Commit

Permalink
fix(frontend): hidding logic wasn't working for hierachicalFacets pan…
Browse files Browse the repository at this point in the history
…el (#209)

InstantSearch panel permits to implement a `hidden` function to
determine if the panel should be hidden.

It wasn't working for hierarchicalFacets, and a workaround had been done
in #146 to try to replicate the logic.
The problem is that when the panel is hidden by this workaround, if the
selected filters are later reset, **it's not becoming visible anymore**.

### Changes

- fix the `hidden` function: the hierarchicalFacets are always present
  in `options.results.hierarchicalFacets`. But when there are no results matching,
  the `data` field is `null`. Checking the presence of `data` fixes the behaviour
- remove the workaround

---
SFCC-410
  • Loading branch information
sbellone authored Dec 9, 2024
1 parent c36808c commit 9973065
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,6 @@ function enableInstantSearch(config) {

search.start();

search.on('render', function () {
var emptyFacetSelector = '.ais-HierarchicalMenu--noRefinement';
$(emptyFacetSelector).each(function () {
$(this).parents().eq(2).hide();
});
});

/**
* Generates a menu with the Panel widget
* @param {Object} options Options object
Expand Down Expand Up @@ -369,8 +362,8 @@ function enableInstantSearch(config) {
return instantsearch.widgets.panel({
hidden: function(options) {
var facets = [].concat(options.results.disjunctiveFacets, options.results.hierarchicalFacets)
var facet = facets.find(function(facet) { return facet.name === attribute }); // eslint-disable-line no-shadow
var facetExists = !!facet;
var attributeFacet = facets.find(function(facet) { return facet.name === attribute });
var facetExists = attributeFacet && attributeFacet.data;
return !facetExists; // hides panel if not facets selectable
},
templates: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,6 @@ function enableInstantSearch(config) {
updateAllProductPrices();
});
}

var emptyFacetSelector = '.ais-HierarchicalMenu--noRefinement';
$(emptyFacetSelector).each(function () {
$(this).parents().eq(2).hide();
});
});

/**
Expand Down Expand Up @@ -600,8 +595,8 @@ function enableInstantSearch(config) {
return instantsearch.widgets.panel({
hidden: function(options) {
var facets = [].concat(options.results.disjunctiveFacets, options.results.hierarchicalFacets)
var facet = facets.find(function(facet) { return facet.name === attribute }); // eslint-disable-line no-shadow
var facetExists = !!facet;
var attributeFacet = facets.find(function(facet) { return facet.name === attribute });
var facetExists = attributeFacet && attributeFacet.data;
return !facetExists; // hides panel if not facets selectable
},
templates: {
Expand Down

0 comments on commit 9973065

Please sign in to comment.