Skip to content

Commit

Permalink
fix(hierarchicalFacets): use a real attribute name for the hierarchic…
Browse files Browse the repository at this point in the history
…alFacet name

To avoid collisions when reordering widgets.
  • Loading branch information
vvo committed Oct 7, 2015
1 parent 7a7c638 commit 0d2a455
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions widgets/hierarchicalMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var headerFooter = require('../decorators/headerFooter');
var RefinementList = autoHide(headerFooter(require('../components/RefinementList')));
var Template = require('../components/Template');

var hierarchicalCounter = 0;
var defaultTemplates = {
header: '',
item: '<a href="{{href}}">{{name}}</a> {{count}}',
Expand Down Expand Up @@ -48,16 +47,17 @@ function hierarchicalMenu({
templates = defaultTemplates,
transformData
}) {
hierarchicalCounter++;

var containerNode = utils.getContainerNode(container);
var usage = 'Usage: hierarchicalMenu({container, attributes, [separator, sortBy, limit, cssClasses.{root, list, item}, templates.{header, item, footer}, transformData]})';

if (!container || !attributes || !attributes.length) {
throw new Error(usage);
}

var hierarchicalFacetName = 'instantsearch.js-hierarchicalMenu' + hierarchicalCounter;
// we need to provide a hierarchicalFacet name for the search state
// so that we can always map $hierarchicalFacetName => real attributes
// we use the first attribute name
var hierarchicalFacetName = attributes[0];

return {
getConfiguration: () => ({
Expand Down
7 changes: 3 additions & 4 deletions widgets/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var headerFooter = require('../decorators/headerFooter');
var RefinementList = autoHide(headerFooter(require('../components/RefinementList')));
var Template = require('../components/Template');

var hierarchicalCounter = 0;
var defaultTemplates = {
header: '',
item: '<a href="{{href}}">{{name}}</a> {{count}}',
Expand Down Expand Up @@ -46,16 +45,16 @@ function menu({
transformData,
hideWhenNoResults = true
}) {
hierarchicalCounter++;

var containerNode = utils.getContainerNode(container);
var usage = 'Usage: menu({container, facetName, [sortBy, limit, cssClasses.{root,list,item}, templates.{header,item,footer}, transformData, hideWhenResults]})';

if (container === null || facetName === null) {
throw new Error(usage);
}

var hierarchicalFacetName = 'instantsearch.js-menu' + hierarchicalCounter;
// we use a hierarchicalFacet for the menu because that's one of the use cases
// of hierarchicalFacet: a flat menu
var hierarchicalFacetName = facetName;

return {
getConfiguration: () => ({
Expand Down

0 comments on commit 0d2a455

Please sign in to comment.