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(quantic): Allow RGA component to provide a custom "no answer" message when no answer is shown #4919

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import errorTemplate from './templates/errorTemplate.html';
import generatedAnswerTemplate from './templates/generatedAnswer.html';
// @ts-ignore
import retryPromptTemplate from './templates/retryPrompt.html';
// @ts-ignore
import noGeneratedAnswerTemplate from './templates/noGeneratedAnswer.html';

/** @typedef {import("coveo").SearchEngine} SearchEngine */
/** @typedef {import("coveo").GeneratedAnswer} GeneratedAnswer */
Expand All @@ -48,9 +50,13 @@ const GENERATED_ANSWER_DATA_KEY = 'coveo-generated-answer-data';

/**
* The `QuanticGeneratedAnswer` component automatically generates an answer using Coveo machine learning models to answer the query executed by the user.
* This component includes a slot, "no-answer-message", which allows for rendering a custom message when no answer is generated.
* @category Search
* @slot no-answer-message - Slot that allows the rendering of a custom message when no answer is generated.
* @example
* <c-quantic-generated-answer engine-id={engineId} with-toggle collapsible></c-quantic-generated-answer>
* <c-quantic-generated-answer engine-id={engineId} with-toggle collapsible>
* <div slot="no-answer-message">No answer was generated.</div>
* </c-quantic-generated-answer>
*/
export default class QuanticGeneratedAnswer extends LightningElement {
/**
Expand Down Expand Up @@ -546,6 +552,16 @@ export default class QuanticGeneratedAnswer extends LightningElement {
return this.state?.expanded;
}

/**
* Returns whether the component has a custom message to display when no answer is generated.
* @returns {boolean}
*/
get hasCustomNoAnswerMessage() {
/** @type {HTMLSlotElement} */
const slot = this.template.querySelector('slot[name="no-answer-message"]');
return !!slot?.assignedNodes()?.length;
}

/**
* Sets the component in the initialization error state.
*/
Expand All @@ -560,6 +576,10 @@ export default class QuanticGeneratedAnswer extends LightningElement {
if (this.hasRetryableError) {
return retryPromptTemplate;
}
if (!this.shouldDisplayGeneratedAnswer && this.hasCustomNoAnswerMessage) {
return noGeneratedAnswerTemplate;
}

return generatedAnswerTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import '../quanticGeneratedAnswer.css';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<div data-testid="generated-answer__card" class="slds-box">
<div class="generated-answer__card-header slds-grid">
<span
data-testid="generated-answer__badge"
class="generated-answer__badge slds-var-p-around_x-small slds-text-title_bold"
>{labels.generatedAnswerForYou}</span
>
</div>
<div
data-cy="generated-answer__content"
class="generated-answer__content slds-var-m-top_medium"
>
<div data-cy="generated-answer__answer" class={generatedAnswerClass}>
<slot name="no-answer-message"></slot>
</div>
</div>
</div>
</template>
Loading