Skip to content

Commit 0c152b7

Browse files
Samiya CaurDevtools-frontend LUCI CQ
authored andcommitted
Add hover button for drjones file entrypoint
Bug: 372154092 Change-Id: I6aadf578c6e327b13a2a97c6e25f4276a0cada8a Fixed: 372154092 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5932948 Auto-Submit: Samiya Caur <[email protected]> Commit-Queue: Samiya Caur <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent 60a23c7 commit 0c152b7

File tree

7 files changed

+69
-4
lines changed

7 files changed

+69
-4
lines changed

front_end/core/host/UserMetrics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ export enum Action {
570570
InsightsReminderTeaserAbortedInSettings = 167,
571571
GeneratingInsightWithoutDisclaimer = 168,
572572
FreestylerOpenedFromElementsPanelFloatingButton = 169,
573-
MAX_VALUE = 170,
573+
DrJonesOpenedFromNetworkPanel = 170,
574+
DrJonesOpenedFromSourcesPanel = 171,
575+
DrJonesOpenedFromSourcesPanelFloatingButton = 172,
576+
DrJonesOpenedFromPerformancePanel = 173,
577+
MAX_VALUE = 174,
574578
/* eslint-enable @typescript-eslint/naming-convention */
575579
}
576580

front_end/panels/freestyler/FreestylerPanel.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,22 +403,29 @@ export class FreestylerPanel extends UI.Panel.Panel {
403403
break;
404404
}
405405
case 'drjones.network-panel-context': {
406-
// TODO(samiyac): Add UMA
407406
this.#viewOutput.freestylerChatUi?.focusTextInput();
407+
Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromNetworkPanel);
408408
this.#viewProps.agentType = AgentType.DRJONES_NETWORK_REQUEST;
409409
this.doUpdate();
410410
break;
411411
}
412412
case 'drjones.performance-panel-context': {
413-
// TODO(samiyac): Add UMA
414413
this.#viewOutput.freestylerChatUi?.focusTextInput();
414+
Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromPerformancePanel);
415415
this.#viewProps.agentType = AgentType.DRJONES_PERFORMANCE;
416416
this.doUpdate();
417417
break;
418418
}
419+
case 'drjones.sources-floating-button': {
420+
this.#viewOutput.freestylerChatUi?.focusTextInput();
421+
Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromSourcesPanelFloatingButton);
422+
this.#viewProps.agentType = AgentType.DRJONES_FILE;
423+
this.doUpdate();
424+
break;
425+
}
419426
case 'drjones.sources-panel-context': {
420-
// TODO(samiyac): Add UMA
421427
this.#viewOutput.freestylerChatUi?.focusTextInput();
428+
Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromSourcesPanel);
422429
this.#viewProps.agentType = AgentType.DRJONES_FILE;
423430
this.doUpdate();
424431
break;
@@ -576,6 +583,7 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
576583
case 'freestyler.element-panel-context':
577584
case 'drjones.network-panel-context':
578585
case 'drjones.performance-panel-context':
586+
case 'drjones.sources-floating-button':
579587
case 'drjones.sources-panel-context': {
580588
void (async () => {
581589
const view = UI.ViewManager.ViewManager.instance().view(

front_end/panels/freestyler/freestyler-meta.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ UI.ActionRegistration.registerActionExtension({
193193
condition: config => isDrJonesPerformanceFeatureAvailable(config) && !isPolicyRestricted(config),
194194
});
195195

196+
UI.ActionRegistration.registerActionExtension({
197+
actionId: 'drjones.sources-floating-button',
198+
contextTypes(): [] {
199+
return [];
200+
},
201+
experiment: Root.Runtime.ExperimentName.FLOATING_ENTRY_POINTS_FOR_AI_ASSISTANCE,
202+
category: UI.ActionRegistration.ActionCategory.GLOBAL,
203+
title: i18nLazyString(UIStrings.askAi),
204+
async loadActionDelegate() {
205+
const Freestyler = await loadFreestylerModule();
206+
return new Freestyler.ActionDelegate();
207+
},
208+
condition: config => isDrJonesFileFeatureAvailable(config) && !isPolicyRestricted(config),
209+
});
210+
196211
UI.ActionRegistration.registerActionExtension({
197212
actionId: 'drjones.sources-panel-context',
198213
contextTypes() {

front_end/panels/sources/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ devtools_module("sources") {
8181
"../../panels/snippets:bundle",
8282
"../../panels/utils:bundle",
8383
"../../third_party/diff:bundle",
84+
"../../ui/components/floating_button:bundle",
8485
"../../ui/components/icon_button:bundle",
8586
"../../ui/components/text_editor:bundle",
8687
"../../ui/legacy:bundle",

front_end/panels/sources/NavigatorView.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import * as SDK from '../../core/sdk/sdk.js';
3737
import * as Bindings from '../../models/bindings/bindings.js';
3838
import * as Persistence from '../../models/persistence/persistence.js';
3939
import * as Workspace from '../../models/workspace/workspace.js';
40+
import * as FloatingButton from '../../ui/components/floating_button/floating_button.js';
4041
import * as IconButton from '../../ui/components/icon_button/icon_button.js';
4142
import * as UI from '../../ui/legacy/legacy.js';
4243
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
@@ -1375,6 +1376,7 @@ export class NavigatorSourceTreeElement extends UI.TreeOutline.TreeElement {
13751376
readonly node: NavigatorUISourceCodeTreeNode;
13761377
private readonly navigatorView: NavigatorView;
13771378
uiSourceCodeInternal: Workspace.UISourceCode.UISourceCode;
1379+
private aiButtonContainer?: HTMLElement;
13781380

13791381
constructor(
13801382
navigatorView: NavigatorView, uiSourceCode: Workspace.UISourceCode.UISourceCode, title: string,
@@ -1425,6 +1427,28 @@ export class NavigatorSourceTreeElement extends UI.TreeOutline.TreeElement {
14251427
UI.ARIAUtils.setLabel(this.listItemElement, `${this.uiSourceCodeInternal.name()}, ${this.nodeType}`);
14261428
}
14271429

1430+
private createAiButton(): void {
1431+
if (!UI.ActionRegistry.ActionRegistry.instance().hasAction('drjones.sources-floating-button')) {
1432+
return;
1433+
}
1434+
const action = UI.ActionRegistry.ActionRegistry.instance().getAction('drjones.sources-floating-button');
1435+
if (!this.aiButtonContainer) {
1436+
this.aiButtonContainer = this.listItemElement.createChild('span', 'ai-button-container');
1437+
const floatingButton = new FloatingButton.FloatingButton.FloatingButton({
1438+
iconName: 'smart-assistant',
1439+
});
1440+
floatingButton.addEventListener('click', ev => {
1441+
ev.stopPropagation();
1442+
this.navigatorView.sourceSelected(this.uiSourceCode, false);
1443+
void action.execute();
1444+
}, {capture: true});
1445+
floatingButton.addEventListener('mousedown', ev => {
1446+
ev.stopPropagation();
1447+
}, {capture: true});
1448+
this.aiButtonContainer.appendChild(floatingButton);
1449+
}
1450+
}
1451+
14281452
get uiSourceCode(): Workspace.UISourceCode.UISourceCode {
14291453
return this.uiSourceCodeInternal;
14301454
}
@@ -1434,6 +1458,7 @@ export class NavigatorSourceTreeElement extends UI.TreeOutline.TreeElement {
14341458
this.listItemElement.addEventListener('click', this.onclick.bind(this), false);
14351459
this.listItemElement.addEventListener('contextmenu', this.handleContextMenuEvent.bind(this), false);
14361460
this.listItemElement.addEventListener('dragstart', this.ondragstart.bind(this), false);
1461+
this.createAiButton();
14371462
}
14381463

14391464
private shouldRenameOnMouseDown(): boolean {

front_end/panels/sources/navigatorTree.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@
6161
color: var(--icon-file-script);
6262
}
6363

64+
.navigator-file-tree-item .ai-button-container {
65+
display: none;
66+
position: absolute;
67+
z-index: 999;
68+
right: var(--sys-size-3);
69+
}
70+
71+
.navigator-file-tree-item:hover .ai-button-container {
72+
display: inline-flex;
73+
}
74+
6475
.navigator-file-tree-item devtools-icon.dot::before {
6576
width: 7px;
6677
height: 7px;

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ export const knownContextValues = new Set([
10861086
'drawer-view-closeableTabs',
10871087
'drjones.network-panel-context',
10881088
'drjones.performance-panel-context',
1089+
'drjones.sources-floating-button',
10891090
'drjones.sources-panel-context',
10901091
'drop',
10911092
'duration',

0 commit comments

Comments
 (0)