Skip to content

Commit 6e9bb7c

Browse files
committed
feat(hierarchical): expose rootPath and showParentLevel
1 parent 93ee0eb commit 6e9bb7c

File tree

5 files changed

+53
-131
lines changed

5 files changed

+53
-131
lines changed

docs/_includes/widget-jsdoc/hierarchicalMenu.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
| <span class='attr-required'>`options.container`</span><span class="attr-infos">Type: <code>string</code> &#124; <code>DOMElement</code></span> | CSS Selector or DOMElement to insert the widget |
44
| <span class='attr-required'>`options.attributes`</span><span class="attr-infos">Type: <code>Array.&lt;string&gt;</code></span> | Array of attributes to use to generate the hierarchy of the menu. Refer to [the readme](https://github.com/algolia/algoliasearch-helper-js#hierarchical-facets) for the convention to follow. |
55
| <span class='attr-optional'>`options.separator`</span><span class="attr-infos">Default:<code class="attr-default">&#x27; &gt; &#x27;</code><br />Type: <code>string</code></span> | Separator used in the attributes to separate level values. |
6+
| <span class='attr-optional'>`options.rootPath`</span><span class="attr-infos">Type: <code>string</code></span> | Prefix path to use if the first level is not the root level. |
7+
| <span class='attr-optional'>`options.showParentLevel`</span><span class="attr-infos">Default:<code class="attr-default">false</code><br />Type: <code>string</code></span> | Show the parent level of the current refined value |
68
| <span class='attr-optional'>`options.limit`</span><span class="attr-infos">Default:<code class="attr-default">100</code><br />Type: <code>number</code></span> | How much facet values to get |
79
| <span class='attr-optional'>`options.sortBy`</span><span class="attr-infos">Default:<code class="attr-default">[&#x27;name:asc&#x27;]</code><br />Type: <code>Array.&lt;string&gt;</code></span> | How to sort refinements. Possible values: `count|isRefined|name:asc|desc` |
810
| <span class='attr-optional'>`options.templates`</span><span class="attr-infos">Type: <code>Object</code></span> | Templates to use for the widget |

npm-shrinkwrap.json

+7-127
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"dependencies": {
7373
"algoliasearch": "^3.9.1",
74-
"algoliasearch-helper": "^2.6.7",
74+
"algoliasearch-helper": "^2.6.9",
7575
"classnames": "^2.2.0",
7676
"events": "^1.1.0",
7777
"hogan.js": "^3.0.2",

src/widgets/hierarchical-menu/__tests__/hierarchical-menu-test.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ describe('hierarchicalMenu()', () => {
8080
).toEqual({
8181
hierarchicalFacets: [{
8282
name: 'hello',
83+
rootPath: null,
8384
attributes: ['hello', 'world'],
84-
separator: ' > '
85+
separator: ' > ',
86+
showParentLevel: true
8587
}]
8688
});
8789
});
@@ -92,8 +94,38 @@ describe('hierarchicalMenu()', () => {
9294
).toEqual({
9395
hierarchicalFacets: [{
9496
name: 'hello',
97+
rootPath: null,
9598
attributes: ['hello', 'world'],
96-
separator: ' ? '
99+
separator: ' ? ',
100+
showParentLevel: true
101+
}]
102+
});
103+
});
104+
105+
it('understand the showParentLevel option', () => {
106+
expect(
107+
hierarchicalMenu({showParentLevel: false, ...options}).getConfiguration()
108+
).toEqual({
109+
hierarchicalFacets: [{
110+
name: 'hello',
111+
rootPath: null,
112+
attributes: ['hello', 'world'],
113+
separator: ' > ',
114+
showParentLevel: false
115+
}]
116+
});
117+
});
118+
119+
it('understand the rootPath option', () => {
120+
expect(
121+
hierarchicalMenu({rootPath: 'Beer', ...options}).getConfiguration()
122+
).toEqual({
123+
hierarchicalFacets: [{
124+
name: 'hello',
125+
rootPath: 'Beer',
126+
attributes: ['hello', 'world'],
127+
separator: ' > ',
128+
showParentLevel: true
97129
}]
98130
});
99131
});

src/widgets/hierarchical-menu/hierarchical-menu.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ let defaultTemplates = require('./defaultTemplates.js');
1616
* @param {string[]} options.attributes Array of attributes to use to generate the hierarchy of the menu.
1717
* Refer to [the readme](https://github.com/algolia/algoliasearch-helper-js#hierarchical-facets) for the convention to follow.
1818
* @param {string} [options.separator=' > '] Separator used in the attributes to separate level values.
19+
* @param {string} [options.rootPath] Prefix path to use if the first level is not the root level.
20+
* @param {string} [options.showParentLevel=false] Show the parent level of the current refined value
1921
* @param {number} [options.limit=100] How much facet values to get
2022
* @param {string[]} [options.sortBy=['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|desc`
2123
* @param {Object} [options.templates] Templates to use for the widget
@@ -42,6 +44,8 @@ hierarchicalMenu({
4244
container,
4345
attributes,
4446
[ separator=' > ' ],
47+
[ rootPath ],
48+
[ showParentLevel=true ],
4549
[ limit=1000 ],
4650
[ sortBy=['name:asc'] ],
4751
[ cssClasses.{root , header, body, footer, list, depth, item, active, link}={} ],
@@ -53,6 +57,8 @@ function hierarchicalMenu({
5357
container,
5458
attributes,
5559
separator = ' > ',
60+
rootPath = null,
61+
showParentLevel = true,
5662
limit = 1000,
5763
sortBy = ['name:asc'],
5864
cssClasses: userCssClasses = {},
@@ -81,7 +87,9 @@ function hierarchicalMenu({
8187
hierarchicalFacets: [{
8288
name: hierarchicalFacetName,
8389
attributes,
84-
separator
90+
separator,
91+
rootPath,
92+
showParentLevel
8593
}]
8694
}),
8795
render: function({results, helper, templatesConfig, createURL, state}) {

0 commit comments

Comments
 (0)