Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: drop support of searchParameters for initialUiState #4081

Merged
merged 10 commits into from
Aug 30, 2019
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports = {
'error',
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'@typescript-eslint/camelcase': [
'error',
{ allow: ['instant_search', 'instant_search_movies'] },
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
],
},
overrides: [
{
Expand Down
15 changes: 8 additions & 7 deletions .storybook/decorators/withHits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const withHits = (
appId = 'latency',
apiKey = '6be0576ff61c053d5f9a3225e2a90f76',
indexName = 'instant_search',
searchParameters = {},
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
playground = defaultPlayground,
...instantsearchOptions
} = searchOptions || {};
Expand All @@ -28,12 +27,6 @@ export const withHits = (
const search = instantsearch({
indexName,
searchClient: algoliasearch(appId, apiKey),
searchParameters: {
hitsPerPage: 4,
attributesToSnippet: ['description:15'],
snippetEllipsisText: '[…]',
...searchParameters,
},
routing: {
router: {
write: (routeState: object) => {
Expand Down Expand Up @@ -67,6 +60,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
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,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 @@ -144,7 +138,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 @@ -158,7 +151,6 @@ class InstantSearch extends EventEmitter {
const {
indexName = null,
numberLocale,
searchParameters = {},
initialUiState = {},
routing = null,
searchFunction,
Expand Down Expand Up @@ -226,10 +218,6 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
this._searchStalledTimer = null;
this._isSearchStalled = false;
this._initialUiState = initialUiState;
this._searchParameters = {
...searchParameters,
index: indexName,
};

if (searchFunction) {
this._searchFunction = searchFunction;
Expand Down
65 changes: 5 additions & 60 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,6 @@ describe('InstantSearch', () => {

expect(search.insightsClient).toBe(insightsClient);
});

// https://github.com/algolia/instantsearch.js/pull/1148
it('does not mutate the provided `searchParameters`', () => {
const disjunctiveFacetsRefinements = { fruits: ['apple'] };
const facetsRefinements = disjunctiveFacetsRefinements;

const search = new InstantSearch({
indexName: 'indexName',
searchClient: createSearchClient(),
searchParameters: {
disjunctiveFacetsRefinements,
facetsRefinements,
},
});

search.addWidget(
createWidget({
getConfiguration: () => ({
disjunctiveFacetsRefinements: {
fruits: ['orange'],
},
}),
})
);

search.start();

expect(search.mainIndex.getHelper().state.facetsRefinements).toEqual({
fruits: ['apple'],
});
});
});

describe('addWidget(s)', () => {
Expand Down Expand Up @@ -392,12 +361,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();
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand All @@ -406,29 +374,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading