Skip to content

Commit f28d306

Browse files
committed
refactor: remove insightsClient prop (#6462)
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`
1 parent 6a564ed commit f28d306

File tree

13 files changed

+54
-184
lines changed

13 files changed

+54
-184
lines changed

packages/instantsearch-core/src/__tests__/instantsearch.test.tsx

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,6 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
157157
});
158158
});
159159

160-
it('throws if insightsClient is not a function', () => {
161-
const warn = jest.spyOn(global.console, 'warn');
162-
warn.mockImplementation(() => {});
163-
164-
expect(() => {
165-
// eslint-disable-next-line no-new
166-
new InstantSearch({
167-
indexName: 'indexName',
168-
searchClient: createSearchClient(),
169-
// @ts-expect-error
170-
insightsClient: 'insights',
171-
});
172-
}).toThrowErrorMatchingInlineSnapshot(`
173-
"The \`insightsClient\` option should be a function.
174-
175-
See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/"
176-
`);
177-
});
178-
179160
it('throws if addWidgets is called with a single widget', () => {
180161
expect(() => {
181162
const search = new InstantSearch({
@@ -311,27 +292,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsear
311292
}).not.toWarnDev();
312293
});
313294

314-
it('warns dev when insightsClient is given', () => {
315-
const searchClient = createSearchClient({
316-
addAlgoliaAgent: jest.fn(),
317-
});
318-
const warn = jest.spyOn(global.console, 'warn');
319-
warn.mockImplementation(() => {});
320-
321-
expect(() => {
322-
// eslint-disable-next-line no-new
323-
new InstantSearch({
324-
indexName: 'indexName',
325-
searchClient,
326-
insightsClient: () => {},
327-
});
328-
}).toWarnDev(
329-
`[InstantSearch]: \`insightsClient\` property has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the \`insights\` middleware.
330-
331-
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/`
332-
);
333-
});
334-
335295
it('accepts middleware with partial methods', () => {
336296
const search = new InstantSearch({
337297
indexName: 'indexName',
@@ -415,17 +375,6 @@ search.addWidgets([
415375
See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
416376
});
417377

418-
it('does store insightsClient on the instance', () => {
419-
const insightsClient = () => {};
420-
const search = new InstantSearch({
421-
indexName: 'indexName',
422-
searchClient: createSearchClient(),
423-
insightsClient,
424-
});
425-
426-
expect(search.insightsClient).toBe(insightsClient);
427-
});
428-
429378
it("exposes helper's last results", async () => {
430379
const searchClient = createSearchClient();
431380

packages/instantsearch-core/src/instantsearch.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import version from './version';
2424
import { index } from './widgets/index-widget';
2525

2626
import type {
27-
InsightsClient as AlgoliaInsightsClient,
2827
SearchClient,
2928
Widget,
3029
IndexWidget,
@@ -67,7 +66,6 @@ export class InstantSearch<
6766
> extends EventEmitter {
6867
client: InstantSearchOptions['searchClient'];
6968
indexName: string;
70-
insightsClient: AlgoliaInsightsClient | null;
7169
onStateChange: InstantSearchOptions<TUiState>['onStateChange'] | null = null;
7270
future: NonNullable<InstantSearchOptions<TUiState>['future']>;
7371
helper: AlgoliaSearchHelper | null;
@@ -114,7 +112,6 @@ export class InstantSearch<
114112
searchFunction,
115113
stalledSearchDelay = 200,
116114
searchClient = null,
117-
insightsClient = null,
118115
onStateChange = null,
119116
future = {
120117
...INSTANTSEARCH_FUTURE_DEFAULTS,
@@ -138,19 +135,6 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
138135
searchClient.addAlgoliaAgent(`instantsearch-core (${version})`);
139136
}
140137

141-
warning(
142-
insightsClient === null,
143-
`\`insightsClient\` property has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the \`insights\` middleware.
144-
145-
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/`
146-
);
147-
148-
if (insightsClient && typeof insightsClient !== 'function') {
149-
throw new Error(
150-
withUsage('The `insightsClient` option should be a function.')
151-
);
152-
}
153-
154138
warning(
155139
!(options as any).searchParameters,
156140
`The \`searchParameters\` option is deprecated and will not be supported in InstantSearch.js 4.x.
@@ -183,7 +167,6 @@ See documentation: ${createDocumentationLink({
183167

184168
this.client = searchClient;
185169
this.future = future;
186-
this.insightsClient = insightsClient;
187170
this.indexName = indexName;
188171
this.helper = null;
189172
this.mainHelper = null;

packages/instantsearch-core/src/types/instantsearch.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { SearchClient } from './algoliasearch';
2-
import type {
3-
InsightsClient as AlgoliaInsightsClient,
4-
InsightsProps,
5-
} from './insights';
2+
import type { InsightsProps } from './insights';
63
import type { RouterProps } from './router';
74
import type { UiState } from './ui-state';
85
import type { AlgoliaSearchHelper } from 'algoliasearch-helper';
@@ -93,13 +90,6 @@ export type InstantSearchOptions<
9390
* @default false
9491
*/
9592
insights?: InsightsProps | boolean;
96-
/**
97-
* the instance of search-insights to use for sending insights events inside
98-
* widgets like `hits`.
99-
*
100-
* @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/
101-
*/
102-
insightsClient?: AlgoliaInsightsClient;
10393
future?: {
10494
/**
10595
* Changes the way `dispose` is used in InstantSearch lifecycle.

packages/instantsearch-core/test/createInstantSearch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const createInstantSearch = (
2828
},
2929
refresh: jest.fn(),
3030
helper: mainHelper, // @TODO: use the Helper from the index once the RoutingManger uses the index
31-
insightsClient: null,
3231
middleware: [],
3332
renderState: {},
3433
scheduleStalledRender: defer(jest.fn()),

packages/instantsearch.js/stories/hits.stories.ts

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { action } from '@storybook/addon-actions';
21
import { storiesOf } from '@storybook/html';
32

43
import { withHits } from '../.storybook/decorators';
54

6-
import type { InsightsClient } from '../src/types';
7-
8-
const fakeInsightsClient: InsightsClient = (method, ...payloads) => {
9-
const [payload] = payloads;
10-
action(`[InsightsClient] sent ${method} with payload`)(payload);
11-
};
12-
135
storiesOf('Results/Hits', module)
146
.add(
157
'default',
@@ -138,33 +130,28 @@ storiesOf('Results/Hits', module)
138130
)
139131
.add(
140132
'with insights function',
141-
withHits(
142-
({ search, container, instantsearch }) => {
143-
search.addWidgets([
144-
instantsearch.widgets.configure({
145-
attributesToSnippet: ['name', 'description'],
146-
clickAnalytics: true,
147-
}),
148-
]);
133+
withHits(({ search, container, instantsearch }) => {
134+
search.addWidgets([
135+
instantsearch.widgets.configure({
136+
attributesToSnippet: ['name', 'description'],
137+
clickAnalytics: true,
138+
}),
139+
]);
149140

150-
search.addWidgets([
151-
instantsearch.widgets.hits({
152-
container,
153-
templates: {
154-
item: (item, { html, sendEvent }) => html`
155-
<h4>${item.name}</h4>
156-
<button
157-
onClick=${() => sendEvent('click', [item], 'Add to cart')}
158-
>
159-
Add to cart
160-
</button>
161-
`,
162-
},
163-
}),
164-
]);
165-
},
166-
{
167-
insightsClient: fakeInsightsClient,
168-
}
169-
)
141+
search.addWidgets([
142+
instantsearch.widgets.hits({
143+
container,
144+
templates: {
145+
item: (item, { html, sendEvent }) => html`
146+
<h4>${item.name}</h4>
147+
<button
148+
onClick=${() => sendEvent('click', [item], 'Add to cart')}
149+
>
150+
Add to cart
151+
</button>
152+
`,
153+
},
154+
}),
155+
]);
156+
})
170157
);

packages/instantsearch.js/stories/infinite-hits.stories.ts

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import { action } from '@storybook/addon-actions';
21
import { storiesOf } from '@storybook/html';
32

43
import { withHits } from '../.storybook/decorators';
54
import { createInfiniteHitsSessionStorageCache } from '../src/lib/infiniteHitsCache';
65

7-
import type { InsightsClient } from '../src/types';
8-
9-
const fakeInsightsClient: InsightsClient = (method, ...payloads) => {
10-
const [payload] = payloads;
11-
action(`[InsightsClient] sent ${method} with payload`)(payload);
12-
};
13-
146
storiesOf('Results/InfiniteHits', module)
157
.add(
168
'default',
@@ -59,40 +51,35 @@ storiesOf('Results/InfiniteHits', module)
5951
)
6052
.add(
6153
'with insights helper',
62-
withHits(
63-
({ search, container, instantsearch }) => {
64-
search.addWidgets([
65-
instantsearch.widgets.configure({
66-
attributesToSnippet: ['name', 'description'],
67-
clickAnalytics: true,
68-
}),
69-
]);
54+
withHits(({ search, container, instantsearch }) => {
55+
search.addWidgets([
56+
instantsearch.widgets.configure({
57+
attributesToSnippet: ['name', 'description'],
58+
clickAnalytics: true,
59+
}),
60+
]);
7061

71-
search.addWidgets([
72-
instantsearch.widgets.infiniteHits({
73-
container,
74-
templates: {
75-
item: (item, { html, sendEvent }) => html`
76-
<h4>${item.name}</h4>
77-
<button
78-
onClick=${() =>
79-
sendEvent(
80-
'clickedObjectIDsAfterSearch',
81-
[item],
82-
'Add to cart'
83-
)}
84-
>
85-
Add to cart
86-
</button>
87-
`,
88-
},
89-
}),
90-
]);
91-
},
92-
{
93-
insightsClient: fakeInsightsClient,
94-
}
95-
)
62+
search.addWidgets([
63+
instantsearch.widgets.infiniteHits({
64+
container,
65+
templates: {
66+
item: (item, { html, sendEvent }) => html`
67+
<h4>${item.name}</h4>
68+
<button
69+
onClick=${() =>
70+
sendEvent(
71+
'clickedObjectIDsAfterSearch',
72+
[item],
73+
'Add to cart'
74+
)}
75+
>
76+
Add to cart
77+
</button>
78+
`,
79+
},
80+
}),
81+
]);
82+
})
9683
)
9784
.add(
9885
'with previous button enabled',

packages/instantsearch.js/test/createInstantSearch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const createInstantSearch = (
3030
},
3131
refresh: jest.fn(),
3232
helper: mainHelper, // @TODO: use the Helper from the index once the RoutingManger uses the index
33-
insightsClient: null,
3433
middleware: [],
3534
renderState: {},
3635
scheduleStalledRender: defer(jest.fn()),
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import '@storybook/addon-knobs/register';
22
import '@storybook/addon-options/register';
3-
import '@storybook/addon-actions/register';

packages/vue-instantsearch/src/components/InstantSearch.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ export default createInstantSearchComponent({
1616
type: Object,
1717
required: true,
1818
},
19-
insightsClient: {
20-
type: Function,
21-
default: undefined,
22-
},
2319
indexName: {
2420
type: String,
2521
required: true,
@@ -98,7 +94,6 @@ export default createInstantSearchComponent({
9894
return {
9995
instantSearchInstance: instantsearch({
10096
searchClient: this.searchClient,
101-
insightsClient: this.insightsClient,
10297
insights: this.insights,
10398
indexName: this.indexName,
10499
routing: this.routing,

packages/vue-instantsearch/src/components/__tests__/InstantSearch.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ beforeEach(() => {
4242

4343
it('passes props to InstantSearch.js', () => {
4444
const searchClient = createSearchClient();
45-
const insightsClient = jest.fn();
4645
const searchFunction = (helper) => helper.search();
4746
const routing = {
4847
router: historyRouter(),
@@ -52,7 +51,6 @@ it('passes props to InstantSearch.js', () => {
5251
mount(InstantSearch, {
5352
propsData: {
5453
searchClient,
55-
insightsClient,
5654
indexName: 'something',
5755
routing,
5856
stalledSearchDelay: 250,
@@ -64,7 +62,6 @@ it('passes props to InstantSearch.js', () => {
6462
indexName: 'something',
6563
routing,
6664
searchClient,
67-
insightsClient,
6865
searchFunction,
6966
stalledSearchDelay: 250,
7067
});

0 commit comments

Comments
 (0)