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(SFINT-5504): new methods to expand and collapse generated answer added to search and insight client #456

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/insight/insightClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,24 @@ describe('InsightClient', () => {
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, exampleGeneratedAnswerMetadata);
});

it('should send proper payload for #expandGeneratedAnswer', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
};

await client.logExpandGeneratedAnswer(exampleGeneratedAnswerMetadata);
expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, exampleGeneratedAnswerMetadata);
});

it('should send proper payload for #collapseGeneratedAnswer', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
};

await client.logCollapseGeneratedAnswer(exampleGeneratedAnswerMetadata);
expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, exampleGeneratedAnswerMetadata);
});

it('should send proper payload for #generatedAnswerFeedbackSubmit', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
Expand Down Expand Up @@ -1340,6 +1358,32 @@ describe('InsightClient', () => {
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, expectedMetadata);
});

it('should send proper payload for #expandGeneratedAnswer', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
};
const expectedMetadata = {
...exampleGeneratedAnswerMetadata,
...expectedBaseCaseMetadata,
};

await client.logExpandGeneratedAnswer(exampleGeneratedAnswerMetadata, baseCaseMetadata);
expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, expectedMetadata);
});

it('should send proper payload for #collapseGeneratedAnswer', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
};
const expectedMetadata = {
...exampleGeneratedAnswerMetadata,
...expectedBaseCaseMetadata,
};

await client.logCollapseGeneratedAnswer(exampleGeneratedAnswerMetadata, baseCaseMetadata);
expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, expectedMetadata);
});

it('should send proper payload for #generatedAnswerFeedbackSubmit', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
Expand Down
18 changes: 18 additions & 0 deletions src/insight/insightClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,24 @@ export class CoveoInsightClient {
);
}

public logExpandGeneratedAnswer(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) {
return this.logCustomEvent(
SearchPageEvents.expandGeneratedAnswer,
metadata
? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata}
: generatedAnswerMetadata
);
}

public logCollapseGeneratedAnswer(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) {
return this.logCustomEvent(
SearchPageEvents.collapseGeneratedAnswer,
metadata
? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata}
: generatedAnswerMetadata
);
}

public logGeneratedAnswerFeedbackSubmit(
generatedAnswerFeedbackMetadata: GeneratedAnswerFeedbackMeta,
metadata?: CaseMetadata
Expand Down
28 changes: 28 additions & 0 deletions src/searchPage/searchPageClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,34 @@ describe('SearchPageClient', () => {
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerShowAnswers, meta);
});

it('should send proper payload for #logExpandGeneratedAnswer', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
await client.logExpandGeneratedAnswer(meta);
expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, meta);
});

it('should send proper payload for #makeExpandGeneratedAnswer', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
const built = await client.makeExpandGeneratedAnswer(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, meta);
expectMatchDescription(built.description, SearchPageEvents.expandGeneratedAnswer, meta);
});

it('should send proper payload for #logCollapseGeneratedAnswer', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
await client.logCollapseGeneratedAnswer(meta);
expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, meta);
});

it('should send proper payload for #makeCollapseGeneratedAnswer', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
const built = await client.makeCollapseGeneratedAnswer(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, meta);
expectMatchDescription(built.description, SearchPageEvents.collapseGeneratedAnswer, meta);
});

it('should send proper payload for #logGeneratedAnswerFeedbackSubmit', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
Expand Down
16 changes: 16 additions & 0 deletions src/searchPage/searchPageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,22 @@ export class CoveoSearchPageClient {
});
}

public makeExpandGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.expandGeneratedAnswer, metadata);
}

public async logExpandGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeExpandGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()});
mmitiche marked this conversation as resolved.
Show resolved Hide resolved
}

public makeCollapseGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.collapseGeneratedAnswer, metadata);
}

public async logCollapseGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeCollapseGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()});
}

public makeGeneratedAnswerFeedbackSubmit(meta: GeneratedAnswerFeedbackMeta) {
return this.makeCustomEvent(SearchPageEvents.generatedAnswerFeedbackSubmit, meta);
}
Expand Down
10 changes: 10 additions & 0 deletions src/searchPage/searchPageEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ export enum SearchPageEvents {
* Identifies the custom event that gets logged when a user activates the genQA feature.
*/
generatedAnswerShowAnswers = 'generatedAnswerShowAnswers',
/**
* Identifies the custom event that gets logged when a user expand a generated answer.
*/
expandGeneratedAnswer = 'expandGeneratedAnswer',
mmitiche marked this conversation as resolved.
Show resolved Hide resolved
/**
* Identifies the custom event that gets logged when a user collapse a generated answer.
*/
collapseGeneratedAnswer = 'collapseGeneratedAnswer',
/**
* Identifies the custom event that gets logged when a user submits a feedback of a generated answer.
*/
Expand Down Expand Up @@ -382,6 +390,8 @@ export const CustomEventsTypes: Partial<Record<SearchPageEvents | InsightEvents,
[SearchPageEvents.generatedAnswerCopyToClipboard]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerHideAnswers]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerShowAnswers]: 'generatedAnswer',
[SearchPageEvents.expandGeneratedAnswer]: 'generatedAnswer',
[SearchPageEvents.collapseGeneratedAnswer]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerFeedbackSubmit]: 'generatedAnswer',
[InsightEvents.expandToFullUI]: 'interface',
[InsightEvents.openUserActions]: 'User Actions',
Expand Down
Loading