Skip to content

Commit

Permalink
feat: drop support of searchParameters for initialUiState (#4081)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
samouss authored and Haroenv committed Oct 23, 2019
1 parent 9e7d3d8 commit 571efeb
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 592 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Expand Up @@ -10,6 +10,10 @@ module.exports = {
'error',
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'@typescript-eslint/camelcase': [
'error',
{ allow: ['instant_search', 'instant_search_movies'] },
],
},
overrides: [
{
Expand Down
9 changes: 8 additions & 1 deletion .storybook/decorators/withHits.ts
Expand Up @@ -19,7 +19,6 @@ export const withHits = (
appId = 'latency',
apiKey = '6be0576ff61c053d5f9a3225e2a90f76',
indexName = 'instant_search',
searchParameters = {},
playground = defaultPlayground,
...instantsearchOptions
} = searchOptions || {};
Expand Down Expand Up @@ -70,6 +69,14 @@ export const withHits = (
rightPanelPlaygroundElement.classList.add('panel-right');
playgroundElement.appendChild(rightPanelPlaygroundElement);

search.addWidget(
instantsearch.widgets.configure({
hitsPerPage: 4,
attributesToSnippet: ['description:15'],
snippetEllipsisText: '[…]',
})
);

playground({
search,
leftPanel: leftPanelPlaygroundElement,
Expand Down
12 changes: 0 additions & 12 deletions src/lib/InstantSearch.ts
Expand Up @@ -97,12 +97,6 @@ export type InstantSearchOptions<TRouteState = UiState> = {
*/
searchFunction?: (helper: AlgoliaSearchHelper) => void;

/**
* Additional parameters to unconditionally pass to the Algolia API. See also
* the `configure` widget for dynamically passing search parameters.
*/
searchParameters?: PlainSearchParameters;

/**
* Injects a `uiState` to the `instantsearch` instance. You can use this option
* to provide an initial state to a widget. Note that the state is only used
Expand Down Expand Up @@ -146,7 +140,6 @@ class InstantSearch extends EventEmitter {
public _stalledSearchDelay: number;
public _searchStalledTimer: any;
public _isSearchStalled: boolean;
public _searchParameters: PlainSearchParameters;
public _initialUiState: UiState;
public _searchFunction?: InstantSearchOptions['searchFunction'];
public _createURL?: (params: SearchParameters) => string;
Expand All @@ -160,7 +153,6 @@ class InstantSearch extends EventEmitter {
const {
indexName = null,
numberLocale,
searchParameters = {},
initialUiState = {},
routing = null,
searchFunction,
Expand Down Expand Up @@ -245,10 +237,6 @@ See ${createDocumentationLink({
this._searchStalledTimer = null;
this._isSearchStalled = false;
this._initialUiState = initialUiState;
this._searchParameters = {
...searchParameters,
index: indexName,
};

if (searchFunction) {
this._searchFunction = searchFunction;
Expand Down
34 changes: 5 additions & 29 deletions src/lib/__tests__/InstantSearch-test.js
Expand Up @@ -400,12 +400,11 @@ describe('start', () => {
indexName: 'indexName',
searchClient,
searchFunction(helper) {
helper.addDisjunctiveFacetRefinement('brand', 'Apple');
helper.search();
},
searchParameters: {
disjunctiveFacetsRefinements: { brand: ['Apple'] },
disjunctiveFacets: ['brand'],
const nextState = helper.state
.addDisjunctiveFacet('brand')
.addDisjunctiveFacetRefinement('brand', 'Apple');

helper.setState(nextState).search();
},
});

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

it('forwards the `searchParameters` to the main index', () => {
const search = new InstantSearch({
indexName: 'indexName',
searchClient: createSearchClient(),
searchParameters: {
hitsPerPage: 5,
disjunctiveFacetsRefinements: { brand: ['Apple'] },
disjunctiveFacets: ['brand'],
},
});

search.start();

expect(search.mainIndex.getHelper().state).toEqual(
algoliasearchHelper.SearchParameters.make({
index: 'indexName',
hitsPerPage: 5,
disjunctiveFacetsRefinements: { brand: ['Apple'] },
disjunctiveFacets: ['brand'],
})
);
});

it('forwards the `initialUiState` to the main index', () => {
const search = new InstantSearch({
indexName: 'indexName',
Expand Down
51 changes: 0 additions & 51 deletions src/widgets/index/__tests__/index-test.ts
Expand Up @@ -595,57 +595,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index/js/"
);
});

it('uses `searchParameters` for the top level index', () => {
const instance = index({ indexName: 'indexName' });
const instantSearchInstance = createInstantSearch({
_searchParameters: {
hitsPerPage: 5,
disjunctiveFacetsRefinements: { brand: ['Apple'] },
disjunctiveFacets: ['brand'],
},
});

instance.init(
createInitOptions({
instantSearchInstance,
})
);

expect(instance.getHelper()!.state).toEqual(
new SearchParameters({
index: 'indexName',
hitsPerPage: 5,
disjunctiveFacetsRefinements: { brand: ['Apple'] },
disjunctiveFacets: ['brand'],
})
);
});

it('does not use `searchParameters` for sub level indices ', () => {
const topLevelInstance = index({ indexName: 'topLevelIndexName' });
const subLevelInstance = index({ indexName: 'subLevelIndexName' });
const instantSearchInstance = createInstantSearch({
_searchParameters: {
hitsPerPage: 5,
disjunctiveFacetsRefinements: { brand: ['Apple'] },
disjunctiveFacets: ['brand'],
},
});

subLevelInstance.init(
createInitOptions({
instantSearchInstance,
parent: topLevelInstance,
})
);

expect(subLevelInstance.getHelper()!.state).toEqual(
new SearchParameters({
index: 'subLevelIndexName',
})
);
});

it('uses the internal state for the queries', () => {
const instance = index({ indexName: 'indexName' });
const searchClient = createSearchClient();
Expand Down
8 changes: 1 addition & 7 deletions src/widgets/index/index.ts
Expand Up @@ -287,12 +287,6 @@ const index = (props: IndexProps): Index => {
// step.
const mainHelper = instantSearchInstance.mainHelper!;

const initialSearchParameters = new algoliasearchHelper.SearchParameters(
// Uses the `searchParameters` for the top level index only, it allows
// us to have the exact same behaviour than before for the mono-index.
parent === null ? instantSearchInstance._searchParameters : {}
);

// This Helper is only used for state management we do not care about the
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
// level is aware of the client.
Expand All @@ -301,7 +295,7 @@ const index = (props: IndexProps): Index => {
indexName,
getLocalWidgetsSearchParameters(localWidgets, {
uiState: localUiState,
initialSearchParameters,
initialSearchParameters: new algoliasearchHelper.SearchParameters(),
})
);

Expand Down

0 comments on commit 571efeb

Please sign in to comment.