From db9c1de99fa0a7589c7001cbce837fabb009c0e1 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Thu, 5 Dec 2024 15:45:49 +0100 Subject: [PATCH 1/2] refactor: remove insightsClient prop The `insightsClient` prop is a remnant of an older implementation of insights, and no longer is needed. In this PR it's removed. BREAKING CHANGE: use `insights` prop of instantsearch instead of `insightsClient` --- .../instantsearch-core/src/instantsearch.ts | 17 ------- .../src/types/instantsearch.ts | 12 +---- .../test/createInstantSearch.ts | 1 - .../src/lib/__tests__/InstantSearch-test.tsx | 51 ------------------- .../test/createInstantSearch.ts | 1 - .../src/components/InstantSearch.js | 5 -- .../src/components/__tests__/InstantSearch.js | 3 -- .../vue-instantsearch/stories/Hits.stories.js | 7 +-- .../stories/InfiniteHits.stories.js | 7 +-- packages/vue-instantsearch/stories/utils.js | 3 -- 10 files changed, 3 insertions(+), 104 deletions(-) diff --git a/packages/instantsearch-core/src/instantsearch.ts b/packages/instantsearch-core/src/instantsearch.ts index 08d270b42a..a0f2a14c64 100644 --- a/packages/instantsearch-core/src/instantsearch.ts +++ b/packages/instantsearch-core/src/instantsearch.ts @@ -24,7 +24,6 @@ import version from './version'; import { index } from './widgets/index-widget'; import type { - InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, IndexWidget, @@ -67,7 +66,6 @@ export class InstantSearch< > extends EventEmitter { client: InstantSearchOptions['searchClient']; indexName: string; - insightsClient: AlgoliaInsightsClient | null; onStateChange: InstantSearchOptions['onStateChange'] | null = null; future: NonNullable['future']>; helper: AlgoliaSearchHelper | null; @@ -114,7 +112,6 @@ export class InstantSearch< searchFunction, stalledSearchDelay = 200, searchClient = null, - insightsClient = null, onStateChange = null, future = { ...INSTANTSEARCH_FUTURE_DEFAULTS, @@ -138,19 +135,6 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend searchClient.addAlgoliaAgent(`instantsearch-core (${version})`); } - warning( - insightsClient === null, - `\`insightsClient\` property has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the \`insights\` middleware. - -For more information, visit https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/how-to/send-click-and-conversion-events-with-instantsearch/js/` - ); - - if (insightsClient && typeof insightsClient !== 'function') { - throw new Error( - withUsage('The `insightsClient` option should be a function.') - ); - } - warning( !(options as any).searchParameters, `The \`searchParameters\` option is deprecated and will not be supported in InstantSearch.js 4.x. @@ -183,7 +167,6 @@ See documentation: ${createDocumentationLink({ this.client = searchClient; this.future = future; - this.insightsClient = insightsClient; this.indexName = indexName; this.helper = null; this.mainHelper = null; diff --git a/packages/instantsearch-core/src/types/instantsearch.ts b/packages/instantsearch-core/src/types/instantsearch.ts index 3a9d7a2ca9..bbca3bfbbe 100644 --- a/packages/instantsearch-core/src/types/instantsearch.ts +++ b/packages/instantsearch-core/src/types/instantsearch.ts @@ -1,8 +1,5 @@ import type { SearchClient } from './algoliasearch'; -import type { - InsightsClient as AlgoliaInsightsClient, - InsightsProps, -} from './insights'; +import type { InsightsProps } from './insights'; import type { RouterProps } from './router'; import type { UiState } from './ui-state'; import type { AlgoliaSearchHelper } from 'algoliasearch-helper'; @@ -93,13 +90,6 @@ export type InstantSearchOptions< * @default false */ insights?: InsightsProps | boolean; - /** - * the instance of search-insights to use for sending insights events inside - * widgets like `hits`. - * - * @deprecated This property will be still supported in 4.x releases, but not further. It is replaced by the `insights` middleware. For more information, visit https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/how-to/send-click-and-conversion-events-with-instantsearch/js/ - */ - insightsClient?: AlgoliaInsightsClient; future?: { /** * Changes the way `dispose` is used in InstantSearch lifecycle. diff --git a/packages/instantsearch-core/test/createInstantSearch.ts b/packages/instantsearch-core/test/createInstantSearch.ts index e1271d43fa..c306695b06 100644 --- a/packages/instantsearch-core/test/createInstantSearch.ts +++ b/packages/instantsearch-core/test/createInstantSearch.ts @@ -28,7 +28,6 @@ export const createInstantSearch = ( }, refresh: jest.fn(), helper: mainHelper, // @TODO: use the Helper from the index once the RoutingManger uses the index - insightsClient: null, middleware: [], renderState: {}, scheduleStalledRender: defer(jest.fn()), diff --git a/packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx b/packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx index 69e5191e39..1193b0349c 100644 --- a/packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx +++ b/packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx @@ -156,25 +156,6 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend }); }); - it('throws if insightsClient is not a function', () => { - const warn = jest.spyOn(global.console, 'warn'); - warn.mockImplementation(() => {}); - - expect(() => { - // eslint-disable-next-line no-new - new InstantSearch({ - indexName: 'indexName', - searchClient: createSearchClient(), - // @ts-expect-error - insightsClient: 'insights', - }); - }).toThrowErrorMatchingInlineSnapshot(` -"The \`insightsClient\` option should be a function. - -See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/" -`); - }); - it('throws if addWidgets is called with a single widget', () => { expect(() => { const search = new InstantSearch({ @@ -310,27 +291,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsear }).not.toWarnDev(); }); - it('warns dev when insightsClient is given', () => { - const searchClient = createSearchClient({ - addAlgoliaAgent: jest.fn(), - }); - const warn = jest.spyOn(global.console, 'warn'); - warn.mockImplementation(() => {}); - - expect(() => { - // eslint-disable-next-line no-new - new InstantSearch({ - indexName: 'indexName', - searchClient, - insightsClient: () => {}, - }); - }).toWarnDev( - `[InstantSearch]: \`insightsClient\` property has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the \`insights\` middleware. - -For more information, visit https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/how-to/send-click-and-conversion-events-with-instantsearch/js/` - ); - }); - it('accepts middleware with partial methods', () => { const search = new InstantSearch({ indexName: 'indexName', @@ -417,17 +377,6 @@ search.addWidgets([ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`); }); - it('does store insightsClient on the instance', () => { - const insightsClient = () => {}; - const search = new InstantSearch({ - indexName: 'indexName', - searchClient: createSearchClient(), - insightsClient, - }); - - expect(search.insightsClient).toBe(insightsClient); - }); - it("exposes helper's last results", async () => { const searchClient = createSearchClient(); diff --git a/packages/instantsearch.js/test/createInstantSearch.ts b/packages/instantsearch.js/test/createInstantSearch.ts index 43bfa16caa..258711c43d 100644 --- a/packages/instantsearch.js/test/createInstantSearch.ts +++ b/packages/instantsearch.js/test/createInstantSearch.ts @@ -30,7 +30,6 @@ export const createInstantSearch = ( }, refresh: jest.fn(), helper: mainHelper, // @TODO: use the Helper from the index once the RoutingManger uses the index - insightsClient: null, middleware: [], renderState: {}, scheduleStalledRender: defer(jest.fn()), diff --git a/packages/vue-instantsearch/src/components/InstantSearch.js b/packages/vue-instantsearch/src/components/InstantSearch.js index 472e76c303..43eb3c55c5 100644 --- a/packages/vue-instantsearch/src/components/InstantSearch.js +++ b/packages/vue-instantsearch/src/components/InstantSearch.js @@ -16,10 +16,6 @@ export default createInstantSearchComponent({ type: Object, required: true, }, - insightsClient: { - type: Function, - default: undefined, - }, indexName: { type: String, required: true, @@ -98,7 +94,6 @@ export default createInstantSearchComponent({ return { instantSearchInstance: instantsearch({ searchClient: this.searchClient, - insightsClient: this.insightsClient, insights: this.insights, indexName: this.indexName, routing: this.routing, diff --git a/packages/vue-instantsearch/src/components/__tests__/InstantSearch.js b/packages/vue-instantsearch/src/components/__tests__/InstantSearch.js index 878aa52630..df55ed7f57 100644 --- a/packages/vue-instantsearch/src/components/__tests__/InstantSearch.js +++ b/packages/vue-instantsearch/src/components/__tests__/InstantSearch.js @@ -42,7 +42,6 @@ beforeEach(() => { it('passes props to InstantSearch.js', () => { const searchClient = createSearchClient(); - const insightsClient = jest.fn(); const searchFunction = (helper) => helper.search(); const routing = { router: historyRouter(), @@ -52,7 +51,6 @@ it('passes props to InstantSearch.js', () => { mount(InstantSearch, { propsData: { searchClient, - insightsClient, indexName: 'something', routing, stalledSearchDelay: 250, @@ -64,7 +62,6 @@ it('passes props to InstantSearch.js', () => { indexName: 'something', routing, searchClient, - insightsClient, searchFunction, stalledSearchDelay: 250, }); diff --git a/packages/vue-instantsearch/stories/Hits.stories.js b/packages/vue-instantsearch/stories/Hits.stories.js index 7c18dfa300..5de4309cc5 100644 --- a/packages/vue-instantsearch/stories/Hits.stories.js +++ b/packages/vue-instantsearch/stories/Hits.stories.js @@ -68,12 +68,7 @@ storiesOf('ais-hits', module) })); storiesOf('ais-hits', module) - .addDecorator( - previewWrapper({ - insightsClient: (method, payload) => - action(`[InsightsClient] sent ${method} with payload`)(payload), - }) - ) + .addDecorator(previewWrapper({})) .add('with insights default slot', () => ({ template: `
diff --git a/packages/vue-instantsearch/stories/InfiniteHits.stories.js b/packages/vue-instantsearch/stories/InfiniteHits.stories.js index e3690d3c82..b0af450a25 100644 --- a/packages/vue-instantsearch/stories/InfiniteHits.stories.js +++ b/packages/vue-instantsearch/stories/InfiniteHits.stories.js @@ -139,12 +139,7 @@ storiesOf('ais-infinite-hits', module) })); storiesOf('ais-infinite-hits', module) - .addDecorator( - previewWrapper({ - insightsClient: (method, payload) => - action(`[InsightsClient] sent ${method} with payload`)(payload), - }) - ) + .addDecorator(previewWrapper({})) .add('with insights on default slot', () => ({ template: `
diff --git a/packages/vue-instantsearch/stories/utils.js b/packages/vue-instantsearch/stories/utils.js index 08d0ee5154..886bc7ba26 100644 --- a/packages/vue-instantsearch/stories/utils.js +++ b/packages/vue-instantsearch/stories/utils.js @@ -3,7 +3,6 @@ import algoliasearch from 'algoliasearch/lite'; export const previewWrapper = ({ searchClient = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76'), - insightsClient, indexName = 'instant_search', hits = `