Skip to content

Commit 571efeb

Browse files
samoussHaroenv
authored andcommitted
feat: drop support of searchParameters for initialUiState (#4081)
This PR drops the support of `searchParameters` for `initialUiState`. Here is the changes: - `InstantSearch`: remove the support of the option - `index`: remove the logic for the option - `stories`: replace the usage of `searchParamters` by `initialUiState` when applicable - `stories`: replace the usage of `searchParamters` by `configure` when applicable
1 parent 9e7d3d8 commit 571efeb

15 files changed

+494
-592
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module.exports = {
1010
'error',
1111
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
1212
],
13+
'@typescript-eslint/camelcase': [
14+
'error',
15+
{ allow: ['instant_search', 'instant_search_movies'] },
16+
],
1317
},
1418
overrides: [
1519
{

.storybook/decorators/withHits.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const withHits = (
1919
appId = 'latency',
2020
apiKey = '6be0576ff61c053d5f9a3225e2a90f76',
2121
indexName = 'instant_search',
22-
searchParameters = {},
2322
playground = defaultPlayground,
2423
...instantsearchOptions
2524
} = searchOptions || {};
@@ -70,6 +69,14 @@ export const withHits = (
7069
rightPanelPlaygroundElement.classList.add('panel-right');
7170
playgroundElement.appendChild(rightPanelPlaygroundElement);
7271

72+
search.addWidget(
73+
instantsearch.widgets.configure({
74+
hitsPerPage: 4,
75+
attributesToSnippet: ['description:15'],
76+
snippetEllipsisText: '[…]',
77+
})
78+
);
79+
7380
playground({
7481
search,
7582
leftPanel: leftPanelPlaygroundElement,

src/lib/InstantSearch.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ export type InstantSearchOptions<TRouteState = UiState> = {
9797
*/
9898
searchFunction?: (helper: AlgoliaSearchHelper) => void;
9999

100-
/**
101-
* Additional parameters to unconditionally pass to the Algolia API. See also
102-
* the `configure` widget for dynamically passing search parameters.
103-
*/
104-
searchParameters?: PlainSearchParameters;
105-
106100
/**
107101
* Injects a `uiState` to the `instantsearch` instance. You can use this option
108102
* to provide an initial state to a widget. Note that the state is only used
@@ -146,7 +140,6 @@ class InstantSearch extends EventEmitter {
146140
public _stalledSearchDelay: number;
147141
public _searchStalledTimer: any;
148142
public _isSearchStalled: boolean;
149-
public _searchParameters: PlainSearchParameters;
150143
public _initialUiState: UiState;
151144
public _searchFunction?: InstantSearchOptions['searchFunction'];
152145
public _createURL?: (params: SearchParameters) => string;
@@ -160,7 +153,6 @@ class InstantSearch extends EventEmitter {
160153
const {
161154
indexName = null,
162155
numberLocale,
163-
searchParameters = {},
164156
initialUiState = {},
165157
routing = null,
166158
searchFunction,
@@ -245,10 +237,6 @@ See ${createDocumentationLink({
245237
this._searchStalledTimer = null;
246238
this._isSearchStalled = false;
247239
this._initialUiState = initialUiState;
248-
this._searchParameters = {
249-
...searchParameters,
250-
index: indexName,
251-
};
252240

253241
if (searchFunction) {
254242
this._searchFunction = searchFunction;

src/lib/__tests__/InstantSearch-test.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,11 @@ describe('start', () => {
400400
indexName: 'indexName',
401401
searchClient,
402402
searchFunction(helper) {
403-
helper.addDisjunctiveFacetRefinement('brand', 'Apple');
404-
helper.search();
405-
},
406-
searchParameters: {
407-
disjunctiveFacetsRefinements: { brand: ['Apple'] },
408-
disjunctiveFacets: ['brand'],
403+
const nextState = helper.state
404+
.addDisjunctiveFacet('brand')
405+
.addDisjunctiveFacetRefinement('brand', 'Apple');
406+
407+
helper.setState(nextState).search();
409408
},
410409
});
411410

@@ -414,29 +413,6 @@ describe('start', () => {
414413
}).not.toThrow();
415414
});
416415

417-
it('forwards the `searchParameters` to the main index', () => {
418-
const search = new InstantSearch({
419-
indexName: 'indexName',
420-
searchClient: createSearchClient(),
421-
searchParameters: {
422-
hitsPerPage: 5,
423-
disjunctiveFacetsRefinements: { brand: ['Apple'] },
424-
disjunctiveFacets: ['brand'],
425-
},
426-
});
427-
428-
search.start();
429-
430-
expect(search.mainIndex.getHelper().state).toEqual(
431-
algoliasearchHelper.SearchParameters.make({
432-
index: 'indexName',
433-
hitsPerPage: 5,
434-
disjunctiveFacetsRefinements: { brand: ['Apple'] },
435-
disjunctiveFacets: ['brand'],
436-
})
437-
);
438-
});
439-
440416
it('forwards the `initialUiState` to the main index', () => {
441417
const search = new InstantSearch({
442418
indexName: 'indexName',

src/widgets/index/__tests__/index-test.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -595,57 +595,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index/js/"
595595
);
596596
});
597597

598-
it('uses `searchParameters` for the top level index', () => {
599-
const instance = index({ indexName: 'indexName' });
600-
const instantSearchInstance = createInstantSearch({
601-
_searchParameters: {
602-
hitsPerPage: 5,
603-
disjunctiveFacetsRefinements: { brand: ['Apple'] },
604-
disjunctiveFacets: ['brand'],
605-
},
606-
});
607-
608-
instance.init(
609-
createInitOptions({
610-
instantSearchInstance,
611-
})
612-
);
613-
614-
expect(instance.getHelper()!.state).toEqual(
615-
new SearchParameters({
616-
index: 'indexName',
617-
hitsPerPage: 5,
618-
disjunctiveFacetsRefinements: { brand: ['Apple'] },
619-
disjunctiveFacets: ['brand'],
620-
})
621-
);
622-
});
623-
624-
it('does not use `searchParameters` for sub level indices ', () => {
625-
const topLevelInstance = index({ indexName: 'topLevelIndexName' });
626-
const subLevelInstance = index({ indexName: 'subLevelIndexName' });
627-
const instantSearchInstance = createInstantSearch({
628-
_searchParameters: {
629-
hitsPerPage: 5,
630-
disjunctiveFacetsRefinements: { brand: ['Apple'] },
631-
disjunctiveFacets: ['brand'],
632-
},
633-
});
634-
635-
subLevelInstance.init(
636-
createInitOptions({
637-
instantSearchInstance,
638-
parent: topLevelInstance,
639-
})
640-
);
641-
642-
expect(subLevelInstance.getHelper()!.state).toEqual(
643-
new SearchParameters({
644-
index: 'subLevelIndexName',
645-
})
646-
);
647-
});
648-
649598
it('uses the internal state for the queries', () => {
650599
const instance = index({ indexName: 'indexName' });
651600
const searchClient = createSearchClient();

src/widgets/index/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,6 @@ const index = (props: IndexProps): Index => {
287287
// step.
288288
const mainHelper = instantSearchInstance.mainHelper!;
289289

290-
const initialSearchParameters = new algoliasearchHelper.SearchParameters(
291-
// Uses the `searchParameters` for the top level index only, it allows
292-
// us to have the exact same behaviour than before for the mono-index.
293-
parent === null ? instantSearchInstance._searchParameters : {}
294-
);
295-
296290
// This Helper is only used for state management we do not care about the
297291
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
298292
// level is aware of the client.
@@ -301,7 +295,7 @@ const index = (props: IndexProps): Index => {
301295
indexName,
302296
getLocalWidgetsSearchParameters(localWidgets, {
303297
uiState: localUiState,
304-
initialSearchParameters,
298+
initialSearchParameters: new algoliasearchHelper.SearchParameters(),
305299
})
306300
);
307301

0 commit comments

Comments
 (0)