Skip to content

Commit f58f13c

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
AI: clear any text input if the user deselects any context
Fixed: 408348505 Change-Id: I5f6ad055bff308db2b1b5e2518e48944cbb9dc8c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6433950 Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Ergün Erdoğmuş <ergunsh@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
1 parent c565fdd commit f58f13c

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,22 @@ describeWithMockConnection('AI Assistance Panel', () => {
310310
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, node);
311311
assert.isNull((await view.nextInput).selectedContext);
312312
});
313+
314+
it('should clear the text input when the context changes to null', async () => {
315+
const chatView = sinon.createStubInstance(AiAssistancePanel.ChatView);
316+
const {panel, view} = await createAiAssistancePanel({chatView});
317+
318+
// Firstly, start a conversation and set a context
319+
const context =
320+
new AiAssistanceModel.CallTreeContext(sinon.createStubInstance(TimelineUtils.AICallTree.AICallTree));
321+
UI.Context.Context.instance().setFlavor(TimelineUtils.AICallTree.AICallTree, context.getItem());
322+
panel.handleAction('drjones.performance-panel-context');
323+
await view.nextInput;
324+
325+
// Now clear the context and check we cleared out the text
326+
UI.Context.Context.instance().setFlavor(TimelineUtils.AICallTree.AICallTree, null);
327+
assert.strictEqual(chatView.clearTextInput.callCount, 1);
328+
});
313329
});
314330

315331
describe('toggle search element action', () => {

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ async function getEmptyStateSuggestions(
246246
'How can I reduce the time of this call tree?',
247247
];
248248
case AiAssistanceModel.ConversationType.PERFORMANCE_INSIGHT:
249-
// TODO(b/405925760): Define these.
250-
return ['Help me optimize my LCP', 'Help me optimize my INP', 'For now'];
249+
return ['Help me optimize my page load performance'];
251250
}
252251
}
253252

@@ -1199,18 +1198,21 @@ export class AiAssistancePanel extends UI.Panel.Panel {
11991198
this.#runAbortController = new AbortController();
12001199
}
12011200

1202-
#onContextSelectionChanged(contextToRestore?: AiAssistanceModel.ConversationContext<unknown>): void {
1201+
#onContextSelectionChanged(): void {
12031202
if (!this.#conversationAgent) {
12041203
this.#blockedByCrossOrigin = false;
12051204
return;
12061205
}
1207-
const currentContext = contextToRestore ?? this.#getConversationContext();
1208-
this.#selectedContext = currentContext;
1209-
if (!currentContext) {
1206+
this.#selectedContext = this.#getConversationContext();
1207+
if (!this.#selectedContext) {
12101208
this.#blockedByCrossOrigin = false;
1209+
1210+
// Clear out any text the user has entered into the input but never
1211+
// submitted now they have no active context
1212+
this.#viewOutput.chatView?.clearTextInput();
12111213
return;
12121214
}
1213-
this.#blockedByCrossOrigin = !currentContext.isOriginAllowed(this.#conversationAgent.origin);
1215+
this.#blockedByCrossOrigin = !this.#selectedContext.isOriginAllowed(this.#conversationAgent.origin);
12141216
}
12151217

12161218
#getConversationContext(): AiAssistanceModel.ConversationContext<unknown>|null {

front_end/panels/ai_assistance/components/ChatView.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ export class ChatView extends HTMLElement {
327327
this.#messagesContainerResizeObserver.disconnect();
328328
}
329329

330+
clearTextInput(): void {
331+
const textArea = this.#shadow.querySelector('.chat-input') as HTMLTextAreaElement;
332+
if (!textArea) {
333+
return;
334+
}
335+
textArea.value = '';
336+
}
337+
330338
focusTextInput(): void {
331339
const textArea = this.#shadow.querySelector('.chat-input') as HTMLTextAreaElement;
332340
if (!textArea) {

front_end/testing/AiAssistanceHelpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ export async function createAiAssistancePanel(options?: {
182182
aidaClient?: Host.AidaClient.AidaClient,
183183
aidaAvailability?: Host.AidaClient.AidaAccessPreconditions,
184184
syncInfo?: Host.InspectorFrontendHostAPI.SyncInformation,
185+
chatView?: AiAssistancePanel.ChatView,
185186
}) {
186187
let aidaAvailabilityForStub = options?.aidaAvailability ?? Host.AidaClient.AidaAccessPreconditions.AVAILABLE;
187188

188-
const view = createViewFunctionStub(AiAssistancePanel.AiAssistancePanel);
189+
const view = createViewFunctionStub(AiAssistancePanel.AiAssistancePanel, {chatView: options?.chatView});
189190
const aidaClient = options?.aidaClient ?? mockAidaClient();
190191
const checkAccessPreconditionsStub =
191192
sinon.stub(Host.AidaClient.AidaClient, 'checkAccessPreconditions').callsFake(() => {

0 commit comments

Comments
 (0)