-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rangeSlider): allow passing min and max values
fixes #858
- Loading branch information
vvo
committed
Mar 3, 2016
1 parent
081d6a3
commit 409295c
Showing
3 changed files
with
133 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ let defaultTemplates = { | |
* @param {string|string[]} [options.cssClasses.footer] CSS class to add to the footer element | ||
* @param {object|boolean} [options.collapsible=false] Hide the widget body and footer when clicking on header | ||
* @param {boolean} [options.collapsible.collapsed] Initial collapsed state of a collapsible widget | ||
* @param {number} [options.min] Minimal slider value, default to automatically computed from the result set | ||
* @param {number} [options.max] Maximal slider value, defaults to automatically computed from the result set | ||
* @return {Object} | ||
*/ | ||
const usage = `Usage: | ||
|
@@ -50,7 +52,9 @@ rangeSlider({ | |
[ step=1 ], | ||
[ pips=true ], | ||
[ autoHideContainer=true ], | ||
[ collapsible=false ] | ||
[ collapsible=false ], | ||
[ min ], | ||
[ max ] | ||
}); | ||
`; | ||
function rangeSlider({ | ||
|
@@ -62,7 +66,9 @@ function rangeSlider({ | |
cssClasses: userCssClasses = {}, | ||
step = 1, | ||
pips = true, | ||
autoHideContainer = true | ||
autoHideContainer = true, | ||
min: userMin, | ||
max: userMax | ||
} = {}) { | ||
if (!container || !attributeName) { | ||
throw new Error(usage); | ||
|
@@ -82,9 +88,31 @@ function rangeSlider({ | |
}; | ||
|
||
return { | ||
getConfiguration: () => ({ | ||
disjunctiveFacets: [attributeName] | ||
}), | ||
getConfiguration: (originalConf) => { | ||
const conf = { | ||
disjunctiveFacets: [attributeName] | ||
}; | ||
|
||
if ( | ||
(userMin !== undefined || userMax !== undefined) | ||
&& | ||
(!originalConf || | ||
originalConf.numericRefinements && | ||
originalConf.numericRefinements[attributeName] === undefined) | ||
) { | ||
conf.numericRefinements = {[attributeName]: {}}; | ||
|
||
if (userMin !== undefined) { | ||
conf.numericRefinements[attributeName]['>='] = [userMin]; | ||
} | ||
|
||
if (userMax !== undefined) { | ||
conf.numericRefinements[attributeName]['<='] = [userMax]; | ||
} | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vvo
Contributor
|
||
|
||
return conf; | ||
}, | ||
_getCurrentRefinement(helper) { | ||
let min = helper.state.getNumericRefinement(attributeName, '>='); | ||
let max = helper.state.getNumericRefinement(attributeName, '<='); | ||
|
@@ -125,16 +153,27 @@ function rangeSlider({ | |
}, | ||
render({results, helper}) { | ||
let facet = find(results.disjunctiveFacets, {name: attributeName}); | ||
let stats = facet !== undefined ? facet.stats : undefined; | ||
let currentRefinement = this._getCurrentRefinement(helper); | ||
let stats; | ||
|
||
if (userMin !== undefined || userMax !== undefined) { | ||
stats = {}; | ||
|
||
if (userMin !== undefined) { | ||
stats.min = userMin; | ||
} | ||
|
||
if (stats === undefined) { | ||
stats = { | ||
if (userMax !== undefined) { | ||
stats.max = userMax; | ||
} | ||
} else { | ||
stats = facet !== undefined && facet.stats !== undefined ? facet.stats : { | ||
min: null, | ||
max: null | ||
}; | ||
} | ||
|
||
let currentRefinement = this._getCurrentRefinement(helper); | ||
|
||
if (tooltips.format !== undefined) { | ||
tooltips = [{to: tooltips.format}, {to: tooltips.format}]; | ||
} | ||
|
I always find it more convenient to do those initial refinements from the
init({helper})
function. Part of that, can it have any negative impact to it here @bobylito?I did https://github.com/instantsearch/instantsearch-ion.rangeSlider/blob/5acdf43f375c369a56f092fca33f0a3ba1daa6de/src/widget.js#L39-L48
cc @vvo