Skip to content

Commit 4cfd093

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Implement start new chat button
Bug: 377227220 Change-Id: Iccda3f41b3422a1773ce3add6a5b45beaf6c44f0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5999711 Auto-Submit: Alex Rudenko <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent c6d74b8 commit 4cfd093

File tree

6 files changed

+70
-31
lines changed

6 files changed

+70
-31
lines changed

front_end/panels/freestyler/FreestylerPanel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export class FreestylerPanel extends UI.Panel.Panel {
211211
onFeedbackSubmit: this.#handleFeedbackSubmit.bind(this),
212212
onCancelClick: this.#cancel.bind(this),
213213
onContextClick: this.#handleContextClick.bind(this),
214+
onNewConversation: this.#clearMessages.bind(this),
214215
canShowFeedbackForm: this.#serverSideLoggingEnabled,
215216
userInfo: {
216217
accountImage: syncInfo.accountImage,

front_end/panels/freestyler/components/FreestylerChatUi.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ css
4646
onFeedbackSubmit: noop,
4747
onCancelClick: noop,
4848
onContextClick: noop,
49+
onNewConversation: noop,
4950
inspectElementToggled: false,
5051
state: Freestyler.State.CHAT_VIEW,
5152
agentType: Freestyler.AgentType.FREESTYLER,

front_end/panels/freestyler/components/FreestylerChatUi.ts

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ const UIStringsNotTranslate = {
119119
*@description Title for the send icon button.
120120
*/
121121
sendButtonTitle: 'Send',
122+
/**
123+
*@description Title for the start new chat
124+
*/
125+
startNewChatButtonTitle: 'Start new chat',
122126
/**
123127
*@description Title for the cancel icon button.
124128
*/
@@ -292,6 +296,7 @@ export interface Props {
292296
onFeedbackSubmit: (rpcId: number, rate: Host.AidaClient.Rating, feedback?: string) => void;
293297
onCancelClick: () => void;
294298
onContextClick: () => void | Promise<void>;
299+
onNewConversation: () => void;
295300
inspectElementToggled: boolean;
296301
state: State;
297302
aidaAvailability: Host.AidaClient.AidaAccessPreconditions;
@@ -874,6 +879,10 @@ export class FreestylerChatUi extends HTMLElement {
874879
// clang-format on
875880
};
876881

882+
#onNewConversation(): void {
883+
this.#props.onNewConversation();
884+
}
885+
877886
#getEmptyStateSuggestions = (): string[] => {
878887
if (!this.#props.agentType) {
879888
return [];
@@ -927,6 +936,61 @@ export class FreestylerChatUi extends HTMLElement {
927936
}
928937
}
929938

939+
#renderChatInputButton(): LitHtml.TemplateResult {
940+
if (this.#props.isLoading) {
941+
// clang-format off
942+
return html`<devtools-button
943+
class="chat-input-button"
944+
aria-label=${lockedString(UIStringsNotTranslate.cancelButtonTitle)}
945+
@click=${this.#handleCancel}
946+
.data=${
947+
{
948+
variant: Buttons.Button.Variant.ICON,
949+
size: Buttons.Button.Size.REGULAR,
950+
iconName: 'record-stop',
951+
title: lockedString(UIStringsNotTranslate.cancelButtonTitle),
952+
jslogContext: 'stop',
953+
} as Buttons.Button.ButtonData
954+
}
955+
></devtools-button>`;
956+
// clang-format on
957+
}
958+
if (this.#props.blockedByCrossOrigin) {
959+
// clang-format off
960+
return html`<devtools-button
961+
class="chat-input-button"
962+
aria-label=${lockedString(UIStringsNotTranslate.startNewChatButtonTitle)}
963+
@click=${this.#onNewConversation}
964+
.data=${
965+
{
966+
variant: Buttons.Button.Variant.PRIMARY,
967+
size: Buttons.Button.Size.REGULAR,
968+
title: lockedString(UIStringsNotTranslate.startNewChatButtonTitle),
969+
jslogContext: 'start-new-chat',
970+
} as Buttons.Button.ButtonData
971+
}
972+
>${lockedString(UIStringsNotTranslate.startNewChatButtonTitle)}</devtools-button>`;
973+
// clang-format on
974+
}
975+
// clang-format off
976+
return html`<devtools-button
977+
class="chat-input-button"
978+
aria-label=${lockedString(UIStringsNotTranslate.sendButtonTitle)}
979+
.data=${
980+
{
981+
type: 'submit',
982+
variant: Buttons.Button.Variant.ICON,
983+
size: Buttons.Button.Size.REGULAR,
984+
disabled: this.#isTextInputDisabled(),
985+
iconName: 'send',
986+
title: lockedString(UIStringsNotTranslate.sendButtonTitle),
987+
jslogContext: 'send',
988+
} as Buttons.Button.ButtonData
989+
}
990+
></devtools-button>`;
991+
// clang-format on
992+
}
993+
930994
#renderChatInput = (): LitHtml.TemplateResult => {
931995
// clang-format off
932996
return html`
@@ -937,37 +1001,7 @@ export class FreestylerChatUi extends HTMLElement {
9371001
@keydown=${this.#handleTextAreaKeyDown}
9381002
placeholder=${this.#getInputPlaceholderString()}
9391003
jslog=${VisualLogging.textField('query').track({ keydown: 'Enter' })}></textarea>
940-
${this.#props.isLoading
941-
? html`<devtools-button
942-
class="chat-input-button"
943-
aria-label=${lockedString(UIStringsNotTranslate.cancelButtonTitle)}
944-
@click=${this.#handleCancel}
945-
.data=${
946-
{
947-
variant: Buttons.Button.Variant.ICON,
948-
size: Buttons.Button.Size.REGULAR,
949-
disabled: this.#isTextInputDisabled(),
950-
iconName: 'record-stop',
951-
title: lockedString(UIStringsNotTranslate.cancelButtonTitle),
952-
jslogContext: 'stop',
953-
} as Buttons.Button.ButtonData
954-
}
955-
></devtools-button>`
956-
: html`<devtools-button
957-
class="chat-input-button"
958-
aria-label=${lockedString(UIStringsNotTranslate.sendButtonTitle)}
959-
.data=${
960-
{
961-
type: 'submit',
962-
variant: Buttons.Button.Variant.ICON,
963-
size: Buttons.Button.Size.REGULAR,
964-
disabled: this.#isTextInputDisabled(),
965-
iconName: 'send',
966-
title: lockedString(UIStringsNotTranslate.sendButtonTitle),
967-
jslogContext: 'send',
968-
} as Buttons.Button.ButtonData
969-
}
970-
></devtools-button>`}
1004+
${this.#renderChatInputButton()}
9711005
</div>`;
9721006
// clang-format on
9731007
};

front_end/ui/components/docs/freestyler/basic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const component = new Freestyler.FreestylerChatUi({
4444
onFeedbackSubmit: noop,
4545
onCancelClick: noop,
4646
onContextClick: noop,
47+
onNewConversation: noop,
4748
inspectElementToggled: false,
4849
state: Freestyler.State.CHAT_VIEW,
4950
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,

front_end/ui/components/docs/freestyler/empty_state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const component = new Freestyler.FreestylerChatUi({
1919
onFeedbackSubmit: noop,
2020
onCancelClick: noop,
2121
onContextClick: noop,
22+
onNewConversation: noop,
2223
inspectElementToggled: false,
2324
state: Freestyler.State.CHAT_VIEW,
2425
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,7 @@ export const knownContextValues = new Set([
28882888
'stalled',
28892889
'standard-emulated-device-list',
28902890
'start',
2891+
'start-new-chat',
28912892
'start-time',
28922893
'start-url',
28932894
'start-view',

0 commit comments

Comments
 (0)