Skip to content

Commit

Permalink
refactor(headless): migrate didYouMeanAutomatic (#3485)
Browse files Browse the repository at this point in the history
* migrate searchBox/submit

https://coveord.atlassian.net/browse/KIT-2933

* revert optional legacy analytics

https://coveord.atlassian.net/browse/KIT-2933

* insight case not using the right interface..

https://coveord.atlassian.net/browse/KIT-2933

* beter interfaces

https://coveord.atlassian.net/browse/KIT-2933

* never use coreSearchBox

https://coveord.atlassian.net/browse/KIT-2933

* fix test

https://coveord.atlassian.net/browse/KIT-2933

* migrate didyoumeanautomatic

https://coveord.atlassian.net/browse/KIT-2943

* add tests

https://coveord.atlassian.net/browse/KIT-2943

* refactor(headless): migrate searchboxAsYouType event (#3472)

refactor(headless): migrate searchboxAsYouType

https://coveord.atlassian.net/browse/KIT-2942

* Update mock-search.ts

https://coveord.atlassian.net/browse/KIT-2943
  • Loading branch information
alexprudhomme authored Dec 15, 2023
1 parent fdc2c60 commit 1b5dd02
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const logDidYouMeanClick = (): LegacySearchAction =>
client.makeDidYouMeanClick()
);

//TODO: KIT-2859
export const logDidYouMeanAutomatic = (): LegacySearchAction =>
makeAnalyticsAction('analytics/didyoumean/automatic', (client) =>
client.makeDidYouMeanAutomatic()
Expand All @@ -24,3 +25,11 @@ export const didYouMeanClick = (): SearchAction => {
new SearchAnalyticsProvider(() => state).getBaseMetadata(),
};
};

export const didYouMeanAutomatic = (): SearchAction => {
return {
actionCause: SearchPageEvents.didyoumeanAutomatic,
getEventExtraPayload: (state) =>
new SearchAnalyticsProvider(() => state).getBaseMetadata(),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import {
SortSection,
TriggerSection,
} from '../../state/state-sections';
import {makeBasicNewSearchAnalyticsAction} from '../analytics/analytics-utils';
import {SearchPageEvents} from '../analytics/search-action-cause';
import {applyDidYouMeanCorrection} from '../did-you-mean/did-you-mean-actions';
import {didYouMeanAutomatic} from '../did-you-mean/did-you-mean-analytics-actions';
import {snapshot} from '../history/history-actions';
import {extractHistory} from '../history/history-state';
import {updateQuery} from '../query/query-actions';
Expand Down Expand Up @@ -202,10 +201,6 @@ export class AsyncSearchThunkProcessor<RejectionType> {
},
automaticallyCorrected: true,
originalQuery,
analyticsAction: makeBasicNewSearchAnalyticsAction(
SearchPageEvents.didyoumeanAutomatic,
this.getState
),
};
}

Expand Down Expand Up @@ -248,10 +243,6 @@ export class AsyncSearchThunkProcessor<RejectionType> {
},
automaticallyCorrected: false,
originalQuery,
analyticsAction: makeBasicNewSearchAnalyticsAction(
SearchPageEvents.triggerQuery,
this.getState
),
};
}

Expand All @@ -264,7 +255,6 @@ export class AsyncSearchThunkProcessor<RejectionType> {
response: this.getSuccessResponse(fetched)!,
automaticallyCorrected: false,
originalQuery: this.getCurrentQuery(),
analyticsAction: this.analyticsAction!,
};
}

Expand All @@ -277,8 +267,14 @@ export class AsyncSearchThunkProcessor<RejectionType> {

private async automaticallyRetryQueryWithCorrection(correction: string) {
this.onUpdateQueryForCorrection(correction);
const state = this.getState();
const {actionCause, getEventExtraPayload} = didYouMeanAutomatic();

const fetched = await this.fetchFromAPI(
await buildSearchRequest(this.getState()),
await buildSearchRequest(state, {
actionCause,
customData: getEventExtraPayload(state),
}),
{origin: 'mainSearch'}
);
this.dispatch(applyDidYouMeanCorrection(correction));
Expand Down Expand Up @@ -320,10 +316,6 @@ export class AsyncSearchThunkProcessor<RejectionType> {
return this.config.dispatch;
}

private get analyticsAction() {
return this.config.analyticsAction;
}

private get rejectWithValue() {
return this.config.rejectWithValue;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/headless/src/features/search/search-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
legacyFetchPage,
} from './legacy/search-actions';
import {
AnalyticsAction,
AsyncSearchThunkProcessor,
StateNeededByExecuteSearch,
} from './search-actions-thunk-processor';
Expand Down Expand Up @@ -100,8 +99,6 @@ export interface ExecuteSearchThunkReturn {
automaticallyCorrected: boolean;
/** The original query that was performed when an automatic correction is executed.*/
originalQuery: string;
/** The analytics action to log after the query. */
analyticsAction: AnalyticsAction;
}

interface PrepareForSearchWithQueryOptions {
Expand Down Expand Up @@ -305,7 +302,6 @@ export const fetchInstantResults = createAsyncThunk<
return {
results: processed.response.results,
searchUid: processed.response.searchUid,
analyticsAction: processed.analyticsAction,
totalCountFiltered: processed.response.totalCountFiltered,
duration: processed.duration,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
} from '../features/analytics/analytics-actions';
import {LegacySearchAction} from '../features/analytics/analytics-utils';
import {
didYouMeanAutomatic,
didYouMeanClick,
logDidYouMeanAutomatic,
logDidYouMeanClick,
} from '../features/did-you-mean/did-you-mean-analytics-actions';
import {registerCategoryFacet} from '../features/facets/category-facet-set/category-facet-set-actions';
Expand Down Expand Up @@ -930,6 +932,18 @@ describe('Analytics Search Migration', () => {
assertNextEqualsLegacy(callSpy);
});

it('analytics/didyoumean/automatic', async () => {
const action = executeSearch({
legacy: logDidYouMeanAutomatic(),
next: didYouMeanAutomatic(),
});
legacySearchEngine.dispatch(action);
nextSearchEngine.dispatch(action);
await wait();

assertNextEqualsLegacy(callSpy);
});

it('analytics/instantResult/searchboxAsYouType', async () => {
const action = executeSearch({
legacy: logInstantResultsSearch() as LegacySearchAction,
Expand Down
4 changes: 0 additions & 4 deletions packages/headless/src/test/mock-search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {SearchPageEvents} from '../features/analytics/search-action-cause';
import {logSearchboxSubmit} from '../features/query/query-analytics-actions';
import {ExecuteSearchThunkReturn as LegacyExecuteSearchThunkReturn} from '../features/search/legacy/search-actions';
import {ExecuteSearchThunkReturn} from '../features/search/search-actions';
Expand All @@ -15,9 +14,6 @@ export function buildMockSearch(
error: null,
automaticallyCorrected: false,
originalQuery: '',
analyticsAction: {
actionCause: SearchPageEvents.searchboxSubmit,
},
...config,
};
}
Expand Down

0 comments on commit 1b5dd02

Please sign in to comment.