Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(connectRange): use the same behaviour for currentRefinement in ge…
Browse files Browse the repository at this point in the history
…tMetadata (#923)
  • Loading branch information
samouss committed Feb 5, 2018
1 parent 8442cbf commit 08917b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
25 changes: 16 additions & 9 deletions packages/react-instantsearch/src/connectors/connectRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ function getCurrentRefinement(props, searchState, currentRange, context) {
return refinement;
}

function getCurrentRefinementWithRange(refinement, range) {
return {
min: refinement.min !== undefined ? refinement.min : range.min,
max: refinement.max !== undefined ? refinement.max : range.max,
};
}

function nextValueForRefinement(hasBound, isReset, range, value) {
let next;
if (!hasBound && range === value) {
Expand Down Expand Up @@ -217,7 +224,7 @@ export default createConnector({
max: rangeMax,
};

const { min: valueMin, max: valueMax } = getCurrentRefinement(
const currentRefinement = getCurrentRefinement(
props,
searchState,
this._currentRange,
Expand All @@ -228,10 +235,10 @@ export default createConnector({
min: rangeMin,
max: rangeMax,
canRefine: count.length > 0,
currentRefinement: {
min: valueMin === undefined ? rangeMin : valueMin,
max: valueMax === undefined ? rangeMax : valueMax,
},
currentRefinement: getCurrentRefinementWithRange(
currentRefinement,
this._currentRange
),
count,
precision,
};
Expand Down Expand Up @@ -300,10 +307,10 @@ export default createConnector({
attributeName: props.attributeName,
value: nextState =>
refine(props, nextState, {}, this._currentRange, this.context),
currentRefinement: {
min: minValue,
max: maxValue,
},
currentRefinement: getCurrentRefinementWithRange(
{ min: minValue, max: maxValue },
{ min: minRange, max: maxRange }
),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ describe('connectRange', () => {
{
label: '5 <= wot',
attributeName: 'wot',
currentRefinement: { min: 5, max: undefined },
currentRefinement: { min: 5, max: 100 },
// Ignore clear, we test it later
value: metadata.items[0].value,
},
Expand Down Expand Up @@ -505,7 +505,7 @@ describe('connectRange', () => {
{
label: 'wot <= 10',
attributeName: 'wot',
currentRefinement: { min: undefined, max: 10 },
currentRefinement: { min: 0, max: 10 },
value: metadata.items[0].value,
},
],
Expand Down Expand Up @@ -753,7 +753,7 @@ describe('connectRange', () => {
{
label: '5 <= wot',
attributeName: 'wot',
currentRefinement: { min: 5, max: undefined },
currentRefinement: { min: 5, max: 100 },
// Ignore clear, we test it later
value: metadata.items[0].value,
},
Expand Down Expand Up @@ -792,7 +792,7 @@ describe('connectRange', () => {
{
label: 'wot <= 10',
attributeName: 'wot',
currentRefinement: { min: undefined, max: 10 },
currentRefinement: { min: 0, max: 10 },
value: metadata.items[0].value,
},
],
Expand Down

0 comments on commit 08917b6

Please sign in to comment.