Skip to content

Commit 8e366cc

Browse files
authored
fix(sortby): Consistent across widget / connectors + migration
1 parent f8e6be4 commit 8e366cc

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

docgen/src/guides/migration.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,33 @@ var search = instantsearch({
2626
}
2727
});
2828
```
29+
30+
## The items are not sorted like before in the refinementList / menu
31+
32+
We changed the default sort order of those widgets. This might have impacted your implementation
33+
if you didn't specify them originally. To change back the order use the `sortBy` configuration
34+
key.
35+
36+
Here are examples of usage of `sortBy` using the previous sorting scheme:
37+
38+
```javascript
39+
search.addWidget(
40+
instantsearch.widgets.refinementList({
41+
container: '#brands',
42+
attributeName: 'brand',
43+
sortBy: ['count:desc', 'name:asc'],
44+
})
45+
);
46+
47+
search.addWidget(
48+
instantsearch.widgets.menu({
49+
container: '#categories',
50+
attributeName: 'categories',
51+
sortBy: ['count:desc', 'name:asc']
52+
})
53+
);
54+
```
55+
56+
If you want to learn more about sorting the values, check out the widget API to see what are
57+
the valid values for the `sortBy` option of [menu](../widgets/menu.html#struct-MenuWidgetOptions-sortBy) or
58+
[refinementList](../widgets/refinementList.html#struct-RefinementListWidgetOptions-sortBy)

src/connectors/hierarchical-menu/connectHierarchicalMenu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ search.addWidget(
1717
[ rootPath = null ],
1818
[ showParentLevel = true ],
1919
[ limit = 10 ],
20-
[ sortBy = ['isRefined', 'count:desc'] ],
20+
[ sortBy = ['name:asc'] ],
2121
})
2222
);
2323
Full documentation available at https://community.algolia.com/instantsearch.js/connectors/connectHierarchicalMenu.html
@@ -39,7 +39,7 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
3939
* @property {string} [rootPath] Prefix path to use if the first level is not the root level (default: `null`).
4040
* @property {string} [showParentLevel] Show the parent level of the current refined value (default: `true`).
4141
* @property {number} [limit] How much facet values to get (default: `10`).
42-
* @property {string[]|function} [sortBy] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
42+
* @property {string[]|function} [sortBy=['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
4343
*
4444
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
4545
*
@@ -73,7 +73,7 @@ export default function connectHierarchicalMenu(renderFn) {
7373
rootPath = null,
7474
showParentLevel = true,
7575
limit = 10,
76-
sortBy = ['isRefined', 'count:desc'],
76+
sortBy = ['name:asc'],
7777
} = widgetParams;
7878

7979
if (!attributes || !attributes.length) {

src/connectors/menu/connectMenu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ search.addWidget(
1818
attributeName,
1919
[ limit ],
2020
[ showMoreLimit ]
21-
[ sortBy = ['isRefined', 'count:desc'] ]
21+
[ sortBy = ['name:asc'] ]
2222
})
2323
);
2424
Full documentation available at https://community.algolia.com/instantsearch.js/connectors/connectMenu.html
@@ -37,7 +37,7 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
3737
* @property {string} attributeName Name of the attribute for faceting (eg. "free_shipping").
3838
* @property {number} [limit] How many facets values to retrieve [*] (default: `10`).
3939
* @property {number} [showMoreLimit] How many facets values to retrieve when `toggleShowMore` is called, this value is meant to be greater than `limit` option (default: `undefined`).
40-
* @property {string[]|function} [sortBy] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
40+
* @property {string[]|function} [sortBy = ['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
4141
*
4242
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax). [*]
4343
*
@@ -108,7 +108,7 @@ export default function connectMenu(renderFn) {
108108
const {
109109
attributeName,
110110
limit = 10,
111-
sortBy = ['isRefined', 'count:desc'],
111+
sortBy = ['name:asc'],
112112
showMoreLimit,
113113
} = widgetParams;
114114

src/connectors/refinement-list/connectRefinementList.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ search.addWidget(
1818
attributeName,
1919
[ operator = 'or' ],
2020
[ limit ],
21-
[ sortBy = ['isRefined', 'count:desc'] ],
21+
[ sortBy = ['isRefined', 'count:desc', 'name:asc']],
2222
})
2323
);
2424
Full documentation available at https://community.algolia.com/instantsearch.js/connectors/connectRefinementList.html
@@ -46,6 +46,7 @@ export const checkUsage = ({attributeName, operator, usageMessage}) => {
4646
* @property {string} attributeName The name of the attribute in the records.
4747
* @property {"and"|"or"} [operator] How the filters are combined together (default: `"or"`).
4848
* @property {number} [limit] The max number of items to display.
49+
* @property {string[]|function} [sortBy = ['isRefined', 'count:desc', 'name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
4950
* @property {string[]|function} [sortBy] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc` (default: `['isRefined', 'count:desc']`).
5051
*/
5152

@@ -119,7 +120,7 @@ export default function connectRefinementList(renderFn) {
119120
attributeName,
120121
operator = 'or',
121122
limit,
122-
sortBy = ['isRefined', 'count:desc'],
123+
sortBy = ['isRefined', 'count:desc', 'name:asc'],
123124
} = widgetParams;
124125

125126
checkUsage({attributeName, operator, usage});

src/widgets/menu/menu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const usage = `Usage:
6868
menu({
6969
container,
7070
attributeName,
71-
[ sortBy=['count:desc', 'name:asc'] ],
71+
[ sortBy=['name:asc'] ],
7272
[ limit=10 ],
7373
[ cssClasses.{root,list,item} ],
7474
[ templates.{header,item,footer} ],
@@ -119,7 +119,7 @@ menu({
119119
* @typedef {Object} MenuWidgetOptions
120120
* @property {string|DOMElement} container CSS Selector or DOMElement to insert the widget
121121
* @property {string} attributeName Name of the attribute for faceting
122-
* @property {string[]|function} [sortBy=['count:desc', 'name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
122+
* @property {string[]|function} [sortBy=['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
123123
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax). [*]
124124
* @property {string} [limit=10] How many facets values to retrieve [*]
125125
* @property {boolean|MenuShowMoreOptions} [showMore=false] Limit the number of results and display a showMore button
@@ -150,7 +150,7 @@ menu({
150150
export default function menu({
151151
container,
152152
attributeName,
153-
sortBy = ['count:desc', 'name:asc'],
153+
sortBy = ['name:asc'],
154154
limit = 10,
155155
cssClasses: userCssClasses = {},
156156
templates = defaultTemplates,

src/widgets/refinement-list/refinement-list.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ refinementList({
7979
container,
8080
attributeName,
8181
[ operator='or' ],
82-
[ sortBy=['count:desc', 'name:asc'] ],
82+
[ sortBy=['isRefined', 'count:desc', 'name:asc'] ],
8383
[ limit=10 ],
8484
[ cssClasses.{root, header, body, footer, list, item, active, label, checkbox, count}],
8585
[ templates.{header,item,footer} ],
@@ -161,8 +161,8 @@ refinementList({
161161
* @property {string|DOMElement} container CSS Selector or DOMElement to insert the widget
162162
* @property {string} attributeName Name of the attribute for faceting
163163
* @property {"and"|"or"} [operator="or"] How to apply refinements. Possible values: `or`, `and`
164-
* @property {("isRefined"|"count:asc"|"count:desc"|"name:asc"|"name:desc")[]|function} [sortBy=["count:desc", "name:asc"]] How to sort refinements. Possible values: `count:asc` `count:desc` `name:asc` `name:desc` `isRefined`.
165-
* You can lso use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
164+
* @property {string[]|function} [sortBy=["isRefined", "count:desc", "name:asc"]] How to sort refinements. Possible values: `count:asc` `count:desc` `name:asc` `name:desc` `isRefined`.
165+
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
166166
* @property {number} [limit=10] How much facet values to get. When the show more feature is activated this is the minimum number of facets requested (the show more button is not in active state).
167167
* @property {SearchForFacetOptions|boolean} [searchForFacetValues=false] Add a search input to let the user search for more facet values
168168
* @property {RefinementListShowMoreOptions|boolean} [showMore=false] Limit the number of results and display a showMore button
@@ -203,7 +203,7 @@ export default function refinementList({
203203
container,
204204
attributeName,
205205
operator = 'or',
206-
sortBy = ['count:desc', 'name:asc'],
206+
sortBy = ['isRefined', 'count:desc', 'name:asc'],
207207
limit = 10,
208208
cssClasses: userCssClasses = {},
209209
templates = defaultTemplates,

0 commit comments

Comments
 (0)