Skip to content

Commit

Permalink
Merge branch 'master' into KIT-3394
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar authored Aug 9, 2024
2 parents 56b207a + 54948d8 commit ffafff0
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -671,14 +671,14 @@ export declare interface AtomicFrequentlyBoughtTogether extends Components.Atomi


@ProxyCmp({
inputs: ['answerStyle', 'collapsible', 'withToggle']
inputs: ['answerStyle', 'collapsible', 'withRephraseButtons', 'withToggle']
})
@Component({
selector: 'atomic-generated-answer',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['answerStyle', 'collapsible', 'withToggle'],
inputs: ['answerStyle', 'collapsible', 'withRephraseButtons', 'withToggle'],
})
export class AtomicGeneratedAnswer {
protected el: HTMLElement;
Expand Down
2 changes: 0 additions & 2 deletions packages/atomic/cypress/e2e/generated-answer-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const GeneratedAnswerSelectors = {
GeneratedAnswerSelectors.shadow().find('[part="citations-label"]'),
citationTitle: () =>
GeneratedAnswerSelectors.citation().find('.citation-title'),
citationIndex: () =>
GeneratedAnswerSelectors.citation().find('[part="citation-index"]'),
citationCard: () =>
GeneratedAnswerSelectors.shadow().find('[part="citation-popover"]'),
loader: () => GeneratedAnswerSelectors.shadow().find('.typing-indicator'),
Expand Down
6 changes: 4 additions & 2 deletions packages/atomic/cypress/e2e/generated-answer.cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('Generated Answer Test Suites', () => {
mockStreamResponse(streamId, testMessagePayload);
setupGeneratedAnswerWithoutFirstIntercept(streamId, {
'answer-style': answerStyle.value,
'with-rephrase-buttons': true,
});
});

Expand Down Expand Up @@ -344,7 +345,9 @@ describe('Generated Answer Test Suites', () => {

beforeEach(() => {
mockStreamResponse(streamId, testMessagePayload);
setupGeneratedAnswer(streamId);
setupGeneratedAnswer(streamId, {
'with-rephrase-buttons': true,
});
cy.wait(getStreamInterceptAlias(streamId));
});

Expand Down Expand Up @@ -461,7 +464,6 @@ describe('Generated Answer Test Suites', () => {
'have.text',
testCitation.title
);
GeneratedAnswerSelectors.citationIndex().should('have.text', '1');
GeneratedAnswerSelectors.citation().should(
'have.attr',
'href',
Expand Down
20 changes: 20 additions & 0 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,11 @@ export namespace Components {
* @default false
*/
"collapsible"?: boolean;
/**
* Whether to render the rephrase buttons that lets the user rephrase the answer.
* @default false
*/
"withRephraseButtons"?: boolean;
/**
* Whether to render a toggle button that lets the user hide or show the answer.
* @default false
Expand Down Expand Up @@ -1198,6 +1203,11 @@ export namespace Components {
* @default false
*/
"collapsible"?: boolean;
/**
* Whether to render the rephrase buttons that lets the user rephrase the answer.
* @default false
*/
"withRephraseButtons"?: boolean;
/**
* Whether to render a toggle button that lets the user hide or show the answer.
* @default false
Expand Down Expand Up @@ -6711,6 +6721,11 @@ declare namespace LocalJSX {
* @default false
*/
"collapsible"?: boolean;
/**
* Whether to render the rephrase buttons that lets the user rephrase the answer.
* @default false
*/
"withRephraseButtons"?: boolean;
/**
* Whether to render a toggle button that lets the user hide or show the answer.
* @default false
Expand Down Expand Up @@ -6849,6 +6864,11 @@ declare namespace LocalJSX {
* @default false
*/
"collapsible"?: boolean;
/**
* Whether to render the rephrase buttons that lets the user rephrase the answer.
* @default false
*/
"withRephraseButtons"?: boolean;
/**
* Whether to render a toggle button that lets the user hide or show the answer.
* @default false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
height: var(--height);
}

[part='citation-index'] {
height: var(--index-height);
width: var(--index-height);
}

[part='citation-popover'] {
--popover-width: 350px;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ export class AtomicCitation {
onFocus={this.openPopover}
onBlur={this.closePopover}
>
<div
part="citation-index"
class="text-bg-primary flex shrink-0 items-center rounded-full font-medium"
>
<div class="mx-auto">{this.index + 1}</div>
</div>
<span class="citation-title mx-1 truncate">
{this.citation.title}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface GeneratedAnswerCommonOptions {
host: HTMLElement;
withToggle?: boolean;
collapsible?: boolean;
withRephraseButtons?: boolean;
getGeneratedAnswer: () => GeneratedAnswer | undefined;
getGeneratedAnswerState: () => GeneratedAnswerState | undefined;
getSearchStatusState: () => SearchStatusState | undefined;
Expand Down Expand Up @@ -311,12 +312,14 @@ export class GeneratedAnswerCommon {
}

private renderRephraseButtons() {
const {getGeneratedAnswerState, getBindings} = this.props;
const {getGeneratedAnswerState, getBindings, withRephraseButtons} =
this.props;
const {i18n} = getBindings();
const {isStreaming, responseFormat} = getGeneratedAnswerState() ?? {};
const {answerStyle} = responseFormat ?? {};
const canRender = withRephraseButtons && !isStreaming;

if (isStreaming) {
if (!canRender) {
return null;
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import {InsightBindings} from '../atomic-insight-interface/atomic-insight-interf
*
* @part citation - The link that allows the user to navigate to the item.
* @part citation-popover - The pop-up that shows an item preview when the user hovers over the citation.
* @part citation-index - The content of the citation item.
*/
@Component({
tag: 'atomic-insight-generated-answer',
Expand Down Expand Up @@ -118,6 +117,12 @@ export class AtomicInsightGeneratedAnswer
*/
@Prop() collapsible?: boolean;

/**
* Whether to render the rephrase buttons that lets the user rephrase the answer.
* @default false
*/
@Prop() withRephraseButtons?: boolean;

@AriaLiveRegion('generated-answer')
protected ariaMessage!: string;

Expand All @@ -130,6 +135,7 @@ export class AtomicInsightGeneratedAnswer
host: this.host,
withToggle: this.withToggle,
collapsible: this.collapsible,
withRephraseButtons: this.withRephraseButtons,
getGeneratedAnswer: () => this.generatedAnswer,
getGeneratedAnswerState: () => this.generatedAnswerState,
getSearchStatusState: () => this.searchStatusState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {Bindings} from '../atomic-search-interface/atomic-search-interface';
*
* @part citation - The link that allows the user to navigate to the item.
* @part citation-popover - The pop-up that shows an item preview when the user hovers over the citation.
* @part citation-index - The content of the citation item.
*/
@Component({
tag: 'atomic-generated-answer',
Expand Down Expand Up @@ -115,6 +114,12 @@ export class AtomicGeneratedAnswer implements InitializableComponent {
*/
@Prop() collapsible?: boolean;

/**
* Whether to render the rephrase buttons that lets the user rephrase the answer.
* @default false
*/
@Prop() withRephraseButtons?: boolean;

/**
* @internal
* The unique identifier of the answer configuration to use to generate the answer.
Expand All @@ -133,6 +138,7 @@ export class AtomicGeneratedAnswer implements InitializableComponent {
host: this.host,
withToggle: this.withToggle,
collapsible: this.collapsible,
withRephraseButtons: this.withRephraseButtons,
getGeneratedAnswer: () => this.generatedAnswer,
getGeneratedAnswerState: () => this.generatedAnswerState,
getSearchStatusState: () => this.searchStatusState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('generated answer slice', () => {
const newCitations = [
buildMockCitation({
id: 'some-other-id',
uri: 'my-uri',
}),
];
const finalState = generatedAnswerReducer(
Expand All @@ -95,6 +96,30 @@ describe('generated answer slice', () => {
...newCitations,
]);
});

it('Shows only citations that have different Uris', () => {
const existingCitations = [
buildMockCitation({
id: 'current-id',
uri: 'my-uri',
}),
];
const newCitations = [
buildMockCitation({
id: 'some-other-id',
uri: 'my-uri',
}),
];
const finalState = generatedAnswerReducer(
{
...getGeneratedAnswerInitialState(),
citations: existingCitations,
},
updateCitations({citations: newCitations})
);

expect(finalState.citations).toEqual([...newCitations]);
});
});

describe('#updateError', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {createReducer} from '@reduxjs/toolkit';
import {RETRYABLE_STREAM_ERROR_CODE} from '../../api/generated-answer/generated-answer-client';
import {GeneratedAnswerCitation} from '../../api/generated-answer/generated-answer-event-payload';
import {
closeGeneratedAnswerFeedbackModal,
dislikeGeneratedAnswer,
Expand Down Expand Up @@ -47,7 +48,13 @@ export const generatedAnswerReducer = createReducer(
.addCase(updateCitations, (state, {payload}) => {
state.isLoading = false;
state.isStreaming = true;
state.citations = state.citations.concat(payload.citations);
const citationMap = new Map<string, GeneratedAnswerCitation>();
for (const citationCollection of [state.citations, payload.citations]) {
for (const citation of citationCollection) {
citationMap.set(citation.uri, citation);
}
}
state.citations = Array.from(citationMap.values());
delete state.error;
})
.addCase(updateError, (state, {payload}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,15 @@ describe('quantic-generated-answer', () => {
const firstTestCitation = {
id: 'some-id-1',
title: 'Some Title 1',
uri: 'https://www.coveo.com',
uri: 'https://www.coveo1.com',
permanentid: 'some-permanent-id-1',
clickUri: exampleLinkUrl,
text: 'example text 1',
};
const secondTestCitation = {
id: 'some-id-2',
title: 'Some Title 2',
uri: 'https://www.coveo.com',
uri: 'https://www.coveo2.com',
permanentid: 'some-permanent-id-2',
clickUri: exampleLinkUrl,
text: 'example text 2',
Expand Down

0 comments on commit ffafff0

Please sign in to comment.