Skip to content

Commit 1b9024a

Browse files
Samiya CaurDevtools-frontend LUCI CQ
Samiya Caur
authored and
Devtools-frontend LUCI CQ
committed
"History" & "New Chat" shouldn't be visible if AI Assistance is not available
This includes user being signed out, user being blocked due to age restriction or setting for AI Assistance not being enabled Bug: 398877860 Change-Id: I78da8397eaa5e350dc84e020226f0b0f0210f32f Fixed: 398877860 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6438414 Auto-Submit: Samiya Caur <samiyac@chromium.org> Reviewed-by: Ergün Erdoğmuş <ergunsh@chromium.org> Commit-Queue: Samiya Caur <samiyac@chromium.org>
1 parent b14c8ae commit 1b9024a

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,49 @@ describeWithMockConnection('AI Assistance Panel', () => {
373373
view.input.onSettingsClick();
374374
assert.isTrue(stub.calledWith('chrome-ai'));
375375
});
376+
377+
it('should not show chat and delete history actions when ai assistance enabled setting is disabled', async () => {
378+
Common.Settings.moduleSetting('ai-assistance-enabled').setDisabled(true);
379+
380+
const {view} = await createAiAssistancePanel();
381+
382+
assert.isFalse(view.input.showChatActions);
383+
assert.isFalse(view.input.showDeleteHistoryAction);
384+
});
385+
386+
it('should not show chat and delete history actions when ai assistance setting is marked as false', async () => {
387+
Common.Settings.moduleSetting('ai-assistance-enabled').set(false);
388+
389+
const {view} = await createAiAssistancePanel();
390+
391+
assert.isFalse(view.input.showChatActions);
392+
assert.isFalse(view.input.showDeleteHistoryAction);
393+
});
394+
395+
it('should not show chat and delete history actions when the user is blocked by age', async () => {
396+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
397+
updateHostConfig({
398+
aidaAvailability: {
399+
blockedByAge: true,
400+
},
401+
});
402+
403+
const {view} = await createAiAssistancePanel();
404+
405+
assert.isFalse(view.input.showChatActions);
406+
assert.isFalse(view.input.showDeleteHistoryAction);
407+
});
408+
409+
it('should not show chat and delete history actions when Aida availability status is SYNC IS PAUSED', async () => {
410+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
411+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
412+
413+
const {view} =
414+
await createAiAssistancePanel({aidaAvailability: Host.AidaClient.AidaAccessPreconditions.SYNC_IS_PAUSED});
415+
416+
assert.isFalse(view.input.showChatActions);
417+
assert.isFalse(view.input.showDeleteHistoryAction);
418+
});
376419
});
377420

378421
describe('history interactions', () => {

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ interface ToolbarViewInput {
256256
onDeleteClick: () => void;
257257
onHelpClick: () => void;
258258
onSettingsClick: () => void;
259-
isDeleteHistoryButtonVisible: boolean;
259+
showDeleteHistoryAction: boolean;
260+
showChatActions: boolean;
260261
}
261262

262263
export type ViewInput = ChatViewProps&ToolbarViewInput;
@@ -271,7 +272,8 @@ function toolbarView(input: ToolbarViewInput): Lit.LitTemplate {
271272
return html`
272273
<div class="toolbar-container" role="toolbar" .jslogContext=${VisualLogging.toolbar()}>
273274
<devtools-toolbar class="freestyler-left-toolbar" role="presentation">
274-
<devtools-button
275+
${input.showChatActions
276+
? html`<devtools-button
275277
title=${i18nString(UIStrings.newChat)}
276278
aria-label=${i18nString(UIStrings.newChat)}
277279
.iconName=${'plus'}
@@ -285,8 +287,9 @@ function toolbarView(input: ToolbarViewInput): Lit.LitTemplate {
285287
.iconName=${'history'}
286288
.jslogContext=${'freestyler.history'}
287289
.variant=${Buttons.Button.Variant.TOOLBAR}
288-
@click=${input.onHistoryClick}></devtools-button>
289-
${input.isDeleteHistoryButtonVisible
290+
@click=${input.onHistoryClick}></devtools-button>`
291+
: Lit.nothing}
292+
${input.showDeleteHistoryAction
290293
? html`<devtools-button
291294
title=${i18nString(UIStrings.deleteChat)}
292295
aria-label=${i18nString(UIStrings.deleteChat)}
@@ -839,7 +842,8 @@ export class AiAssistancePanel extends UI.Panel.Panel {
839842
multimodalInputEnabled: isAiAssistanceMultimodalInputEnabled() &&
840843
this.#conversation?.type === AiAssistanceModel.ConversationType.STYLING,
841844
imageInput: this.#imageInput,
842-
isDeleteHistoryButtonVisible: Boolean(this.#conversation && !this.#conversation.isEmpty),
845+
showDeleteHistoryAction: Boolean(this.#conversation && !this.#conversation.isEmpty),
846+
showChatActions: this.#shouldShowChatActions(),
843847
isTextInputDisabled: this.#isTextInputDisabled(),
844848
emptyStateSuggestions,
845849
inputPlaceholder: this.#getChatInputPlaceholder(),
@@ -908,6 +912,19 @@ export class AiAssistancePanel extends UI.Panel.Panel {
908912
return false;
909913
}
910914

915+
#shouldShowChatActions(): boolean {
916+
const aiAssistanceSetting = this.#aiAssistanceEnabledSetting?.getIfNotDisabled();
917+
const isBlockedByAge = Root.Runtime.hostConfig.aidaAvailability?.blockedByAge === true;
918+
if (!aiAssistanceSetting || isBlockedByAge) {
919+
return false;
920+
}
921+
if (this.#aidaAvailability === Host.AidaClient.AidaAccessPreconditions.NO_ACCOUNT_EMAIL ||
922+
this.#aidaAvailability === Host.AidaClient.AidaAccessPreconditions.SYNC_IS_PAUSED) {
923+
return false;
924+
}
925+
return true;
926+
}
927+
911928
#getChatInputPlaceholder(): Platform.UIString.LocalizedString {
912929
const state = this.#getChatUiState();
913930
if (state === ChatViewState.CONSENT_VIEW || !this.#conversation) {

0 commit comments

Comments
 (0)