Skip to content

Commit a215d0c

Browse files
samoussHaroenv
authored andcommitted
fix(configure): merge with the previous parameters (#4085)
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.
1 parent 571efeb commit a215d0c

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/connectors/configure/__tests__/connectConfigure-test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,40 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure/j
389389
);
390390
});
391391

392+
it('merges with the previous parameters', () => {
393+
const makeWidget = connectConfigure();
394+
const widget = makeWidget({
395+
searchParameters: {
396+
disjunctiveFacets: ['brand'],
397+
disjunctiveFacetsRefinements: {
398+
brand: ['Apple'],
399+
},
400+
},
401+
});
402+
403+
const sp = widget.getWidgetSearchParameters!(
404+
new SearchParameters({
405+
disjunctiveFacets: ['categories'],
406+
disjunctiveFacetsRefinements: {
407+
categories: ['Phone'],
408+
},
409+
}),
410+
{
411+
uiState: {},
412+
}
413+
);
414+
415+
expect(sp).toEqual(
416+
new SearchParameters({
417+
disjunctiveFacets: ['categories', 'brand'],
418+
disjunctiveFacetsRefinements: {
419+
brand: ['Apple'],
420+
categories: ['Phone'],
421+
},
422+
})
423+
);
424+
});
425+
392426
it('stores refined state', () => {
393427
const renderFn = jest.fn();
394428
const makeWidget = connectConfigure(renderFn);

src/connectors/configure/connectConfigure.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ const connectConfigure: ConfigureConnector = (
142142
},
143143

144144
getWidgetSearchParameters(state, { uiState }) {
145-
return state.setQueryParameters({
146-
...uiState.configure,
147-
...widgetParams.searchParameters,
148-
});
145+
return mergeSearchParameters(
146+
state,
147+
new algoliasearchHelper.SearchParameters({
148+
...uiState.configure,
149+
...widgetParams.searchParameters,
150+
})
151+
);
149152
},
150153

151154
getWidgetState(uiState) {

0 commit comments

Comments
 (0)