Skip to content

Commit

Permalink
fix(configure): merge with the previous parameters (#4085)
Browse files Browse the repository at this point in the history
This PR uses the `mergeSearchParameters` for `getWidgetSearchParameters` within `configure`. With the changes introduced recently, we don't merge the parameters auto-magically. This logic is now managed by each widget itself. For `configure` this behavior was handy because it allowed us to use it for initial refinement. 

It's not possible anymore because we use `setQueryParameters` which overrides the previous parameters. The facets configuration of the current widget is erased and we're not able to refine anymore. To ease the transition between the two versions and keep the widget powerful enough we'll mimic the previous implementation.
  • Loading branch information
samouss authored and Haroenv committed Oct 23, 2019
1 parent 571efeb commit a215d0c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/connectors/configure/__tests__/connectConfigure-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,40 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure/j
);
});

it('merges with the previous parameters', () => {
const makeWidget = connectConfigure();
const widget = makeWidget({
searchParameters: {
disjunctiveFacets: ['brand'],
disjunctiveFacetsRefinements: {
brand: ['Apple'],
},
},
});

const sp = widget.getWidgetSearchParameters!(
new SearchParameters({
disjunctiveFacets: ['categories'],
disjunctiveFacetsRefinements: {
categories: ['Phone'],
},
}),
{
uiState: {},
}
);

expect(sp).toEqual(
new SearchParameters({
disjunctiveFacets: ['categories', 'brand'],
disjunctiveFacetsRefinements: {
brand: ['Apple'],
categories: ['Phone'],
},
})
);
});

it('stores refined state', () => {
const renderFn = jest.fn();
const makeWidget = connectConfigure(renderFn);
Expand Down
11 changes: 7 additions & 4 deletions src/connectors/configure/connectConfigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ const connectConfigure: ConfigureConnector = (
},

getWidgetSearchParameters(state, { uiState }) {
return state.setQueryParameters({
...uiState.configure,
...widgetParams.searchParameters,
});
return mergeSearchParameters(
state,
new algoliasearchHelper.SearchParameters({
...uiState.configure,
...widgetParams.searchParameters,
})
);
},

getWidgetState(uiState) {
Expand Down

0 comments on commit a215d0c

Please sign in to comment.