Skip to content

Commit ebcc8a9

Browse files
committed
feat(refinementList): Limits improvement
The default limit should be 1000 to fit the API's default configuration. Remove the limit option from the component itself, it's enough to have it in the widget. Set the maxValuesPerFacet if not set to optimize the JSON answer payload.
1 parent 0352b22 commit ebcc8a9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

components/RefinementList.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ class RefinementList extends React.Component {
6565
render() {
6666
return (
6767
<div className={cx(this.props.cssClasses.list)}>
68-
{this.props.facetValues
69-
.slice(0, this.props.limit)
70-
.map(this._generateFacetItem, this)}
68+
{this.props.facetValues.map(this._generateFacetItem, this)}
7169
</div>
7270
);
7371
}
@@ -84,7 +82,6 @@ RefinementList.propTypes = {
8482
React.PropTypes.arrayOf(React.PropTypes.string)
8583
])
8684
}),
87-
limit: React.PropTypes.number,
8885
facetValues: React.PropTypes.array,
8986
Template: React.PropTypes.func,
9087
toggleRefinement: React.PropTypes.func.isRequired,
@@ -96,7 +93,6 @@ RefinementList.defaultProps = {
9693
item: null,
9794
list: null
9895
},
99-
limit: 1000,
10096
facetNameKey: 'name'
10197
};
10298

widgets/refinement-list.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var defaultTemplates = {
2222
* @param {String} options.facetName Name of the attribute for faceting
2323
* @param {String} options.operator How to apply refinements. Possible values: `or`, `and`
2424
* @param {String[]} [options.sortBy=['count:desc']] How to sort refinements. Possible values: `count|isRefined|name:asc|desc`
25-
* @param {String} [options.limit=100] How much facet values to get
25+
* @param {String} [options.limit=1000] How much facet values to get
2626
* @param {Object} [options.cssClasses] CSS classes to add to the wrapping elements: root, list, item
2727
* @param {String|String[]} [options.cssClasses.root] CSS class to add to the root element
2828
* @param {String|String[]} [options.cssClasses.list] CSS class to add to the list element
@@ -44,7 +44,7 @@ function refinementList({
4444
facetName = null,
4545
operator = null,
4646
sortBy = ['count:desc'],
47-
limit = 100,
47+
limit = 1000,
4848
cssClasses = {
4949
root: null,
5050
list: null,
@@ -75,6 +75,13 @@ function refinementList({
7575
}
7676

7777
return {
78+
init: (state, helper) => {
79+
// set the maxValuesPerFacet to max(limit, currentValue)
80+
var maxValuesPerFacet = helper.getQueryParameter('maxValuesPerFacet');
81+
if (!maxValuesPerFacet || limit > maxValuesPerFacet) {
82+
helper.setQueryParameter('maxValuesPerFacet', limit);
83+
}
84+
},
7885
getConfiguration: () => ({
7986
[operator === 'and' ? 'facets' : 'disjunctiveFacets']: [facetName]
8087
}),

0 commit comments

Comments
 (0)