Skip to content

Commit 8d5fffb

Browse files
wolfibDevtools-frontend LUCI CQ
authored andcommitted
[Conversation History] Fix history context menu
Compare IDs instead of the conversation objects when determining which conversation should be checked and when switching to a historic conversation. Fixed: 462384422 Change-Id: I3c018498dbf95cb65ba298bcec4f3a7343b41e1d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7185564 Commit-Queue: Nikolay Vitkov <[email protected]> Commit-Queue: Wolfgang Beyer <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Auto-Submit: Wolfgang Beyer <[email protected]>
1 parent c5b0eee commit 8d5fffb

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,66 @@ describeWithMockConnection('AI Assistance Panel', () => {
752752
]);
753753
});
754754

755+
it('allows continuing the active conversation if re-opened via history context menu', async () => {
756+
updateHostConfig({
757+
devToolsFreestyler: {
758+
enabled: true,
759+
},
760+
});
761+
const {panel, view} = await createAiAssistancePanel(
762+
{
763+
aidaClient: mockAidaClient(
764+
[
765+
[{explanation: 'test'}],
766+
[{explanation: 'test2'}],
767+
],
768+
),
769+
},
770+
);
771+
void panel.handleAction('freestyler.elements-floating-button');
772+
let nextInput = await view.nextInput;
773+
assert(nextInput.state === AiAssistancePanel.ViewState.CHAT_VIEW);
774+
nextInput.props.onTextSubmit('User question to Freestyler?');
775+
nextInput = await view.nextInput;
776+
assert(nextInput.state === AiAssistancePanel.ViewState.CHAT_VIEW);
777+
778+
const {contextMenu, id, entry} = openHistoryContextMenu(nextInput, 'User question to Freestyler?');
779+
assert.isTrue(entry?.buildDescriptor().checked);
780+
781+
assert.isDefined(id);
782+
contextMenu.invokeHandler(id);
783+
784+
nextInput.props.onTextSubmit('Second question to Freestyler?');
785+
nextInput = await view.nextInput;
786+
assert(nextInput.state === AiAssistancePanel.ViewState.CHAT_VIEW);
787+
assert.deepEqual(nextInput.props.messages, [
788+
{
789+
entity: AiAssistancePanel.ChatMessageEntity.USER,
790+
text: 'User question to Freestyler?',
791+
imageInput: undefined,
792+
},
793+
{
794+
answer: 'test',
795+
entity: AiAssistancePanel.ChatMessageEntity.MODEL,
796+
rpcId: undefined,
797+
suggestions: undefined,
798+
steps: [],
799+
},
800+
{
801+
entity: AiAssistancePanel.ChatMessageEntity.USER,
802+
text: 'Second question to Freestyler?',
803+
imageInput: undefined,
804+
},
805+
{
806+
answer: 'test2',
807+
entity: AiAssistancePanel.ChatMessageEntity.MODEL,
808+
rpcId: undefined,
809+
suggestions: undefined,
810+
steps: [],
811+
},
812+
]);
813+
});
814+
755815
describe('action-triggered prompts', () => {
756816
it('runs action-triggered prompts when the user can execute a prompt', async () => {
757817
updateHostConfig({

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
11661166

11671167
contextMenu.defaultSection().appendCheckboxItem(conversation.title, () => {
11681168
void this.#openHistoricConversation(conversation);
1169-
}, {checked: (this.#conversation === conversation), jslogContext: 'freestyler.history-item'});
1169+
}, {checked: (this.#conversation?.id === conversation.id), jslogContext: 'freestyler.history-item'});
11701170
}
11711171

11721172
const historyEmpty = contextMenu.defaultSection().items.length === 0;
@@ -1224,7 +1224,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
12241224
}
12251225

12261226
async #openHistoricConversation(conversation: AiAssistanceModel.AiConversation.AiConversation): Promise<void> {
1227-
if (this.#conversation === conversation) {
1227+
if (this.#conversation?.id === conversation.id) {
12281228
return;
12291229
}
12301230

front_end/testing/AiAssistanceHelpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,11 @@ export function openHistoryContextMenu(
314314
const contextMenu = new UI.ContextMenu.ContextMenu(new MouseEvent('click'));
315315
lastUpdate.populateHistoryMenu(contextMenu);
316316

317-
const freestylerEntry = findMenuItemWithLabel(contextMenu.defaultSection(), item);
317+
const entry = findMenuItemWithLabel(contextMenu.defaultSection(), item);
318318
return {
319319
contextMenu,
320-
id: freestylerEntry?.id(),
320+
id: entry?.id(),
321+
entry,
321322
};
322323
}
323324

0 commit comments

Comments
 (0)