Skip to content

Commit

Permalink
feat(refinementList): Limits improvement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
redox committed Oct 9, 2015
1 parent 0352b22 commit ebcc8a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 1 addition & 5 deletions components/RefinementList.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ class RefinementList extends React.Component {
render() {
return (
<div className={cx(this.props.cssClasses.list)}>
{this.props.facetValues
.slice(0, this.props.limit)
.map(this._generateFacetItem, this)}
{this.props.facetValues.map(this._generateFacetItem, this)}
</div>
);
}
Expand All @@ -84,7 +82,6 @@ RefinementList.propTypes = {
React.PropTypes.arrayOf(React.PropTypes.string)
])
}),
limit: React.PropTypes.number,
facetValues: React.PropTypes.array,
Template: React.PropTypes.func,
toggleRefinement: React.PropTypes.func.isRequired,
Expand All @@ -96,7 +93,6 @@ RefinementList.defaultProps = {
item: null,
list: null
},
limit: 1000,
facetNameKey: 'name'
};

Expand Down
11 changes: 9 additions & 2 deletions widgets/refinement-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var defaultTemplates = {
* @param {String} options.facetName Name of the attribute for faceting
* @param {String} options.operator How to apply refinements. Possible values: `or`, `and`
* @param {String[]} [options.sortBy=['count:desc']] How to sort refinements. Possible values: `count|isRefined|name:asc|desc`
* @param {String} [options.limit=100] How much facet values to get
* @param {String} [options.limit=1000] How much facet values to get
* @param {Object} [options.cssClasses] CSS classes to add to the wrapping elements: root, list, item
* @param {String|String[]} [options.cssClasses.root] CSS class to add to the root element
* @param {String|String[]} [options.cssClasses.list] CSS class to add to the list element
Expand All @@ -44,7 +44,7 @@ function refinementList({
facetName = null,
operator = null,
sortBy = ['count:desc'],
limit = 100,
limit = 1000,
cssClasses = {
root: null,
list: null,
Expand Down Expand Up @@ -75,6 +75,13 @@ function refinementList({
}

return {
init: (state, helper) => {
// set the maxValuesPerFacet to max(limit, currentValue)
var maxValuesPerFacet = helper.getQueryParameter('maxValuesPerFacet');
if (!maxValuesPerFacet || limit > maxValuesPerFacet) {
helper.setQueryParameter('maxValuesPerFacet', limit);
}
},
getConfiguration: () => ({
[operator === 'and' ? 'facets' : 'disjunctiveFacets']: [facetName]
}),
Expand Down

0 comments on commit ebcc8a9

Please sign in to comment.