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

Commit

Permalink
fix(MultiIndex): reset page to 1 when share widgets refine (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthuret authored Sep 7, 2017
1 parent 2a65ef1 commit c85a7bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/react-instantsearch/src/core/indexUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ export function refineValue(
)
: refineMultiIndex(searchState, nextRefinement, context, resetPage);
} else {
/*
If we have a multi index page with shared widgets we should also reset their page to 1
see: https://github.com/algolia/react-instantsearch/issues/310
*/
if (searchState.indices) {
Object.keys(searchState.indices).forEach(targetedIndex => {
searchState = refineValue(
searchState,
{ page: 1 },
{ multiIndexContext: { targetedIndex } },
true,
namespace
);
});
}
return namespace
? refineSingleIndexWithNamespace(
searchState,
Expand Down
17 changes: 16 additions & 1 deletion packages/react-instantsearch/src/core/indexUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('utility method for manipulating the search state', () => {
});
});
describe('when there are multiple index', () => {
const context = { multiIndexContext: { targetedIndex: 'first' } };
let context = { multiIndexContext: { targetedIndex: 'first' } };
it('refine with no namespace', () => {
let searchState = {};
let nextRefinement = { refinement: 'refinement' };
Expand Down Expand Up @@ -516,5 +516,20 @@ describe('utility method for manipulating the search state', () => {

expect(results).toEqual({ some: 'results' });
});

it('refine shared widgets should reset indices page to 1', () => {
context = {};
let searchState = {
indices: { first: { page: 3 }, second: { page: 3 } },
};
const nextRefinement = { query: 'new' };

searchState = refineValue(searchState, nextRefinement, context);

expect(searchState).toEqual({
query: 'new',
indices: { first: { page: 1 }, second: { page: 1 } },
});
});
});
});

0 comments on commit c85a7bf

Please sign in to comment.