Skip to content

Commit 8fadf21

Browse files
Kateryna ProkopenkoDevtools-frontend LUCI CQ
authored andcommitted
Add new badges to AI Assistance in Main and command menus
Screenshot: http://b/434870886#attachment68071724, http://b/434871110#attachment68111099 Bug: 434871110, 434870886 Change-Id: Ia087c4fbb0cdb88f9dbbb08d81026a64fb5a4a84 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6811473 Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Kateryna Prokopenko <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]> Auto-Submit: Kateryna Prokopenko <[email protected]>
1 parent 9f32d90 commit 8fadf21

File tree

9 files changed

+61
-2
lines changed

9 files changed

+61
-2
lines changed

front_end/entrypoints/main/MainImpl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,11 @@ export class MainMenuItem implements UI.Toolbar.Provider {
906906

907907
const aiPreregisteredView = UI.ViewManager.getRegisteredViewExtensionForID('freestyler');
908908
if (aiPreregisteredView) {
909+
const additionalElement = UI.UIUtils.maybeCreateNewBadge('ai-asisstance');
909910
contextMenu.defaultSection().appendItem(aiPreregisteredView.title(), () => {
910911
void UI.ViewManager.ViewManager.instance().showView('freestyler', true, false);
911-
}, {jslogContext: 'freestyler'});
912+
UI.UIUtils.PromotionManager.instance().recordFeatureInteraction('ai-asisstance');
913+
}, {additionalElement, jslogContext: 'freestyler'});
912914
}
913915

914916
if (dockController.dockSide() === UI.DockController.DockState.UNDOCKED) {

front_end/ui/legacy/UIUtils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ const UIStrings = {
115115
*@description Text to cancel something
116116
*/
117117
cancel: 'Cancel',
118+
/**
119+
*@description Text for the new badge appearing next to some menu items
120+
*/
121+
new: 'NEW',
118122
} as const;
119123
const str_ = i18n.i18n.registerUIStrings('ui/legacy/UIUtils.ts', UIStrings);
120124
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -2119,3 +2123,28 @@ export class PromotionManager {
21192123
return false;
21202124
}
21212125
}
2126+
2127+
/**
2128+
* Creates a `<div>` element with the localized text NEW.
2129+
*
2130+
* The element is automatically styled correctly, as long as the core styles (in particular
2131+
* `inspectorCommon.css` is injected into the current document / shadow root). The lit
2132+
* equivalent of calling this method is:
2133+
*
2134+
* ```js
2135+
* const jslog = VisualLogging.badge('new-badge');
2136+
* html`<div class='new-badge' jsog=${jslog}>i18nString(UIStrings.new)</div>`
2137+
*
2138+
* @returns the newly created `HTMLDivElement` for the new badge.
2139+
*/
2140+
export function maybeCreateNewBadge(promotionId: string): HTMLDivElement|undefined {
2141+
const promotionManager = PromotionManager.instance();
2142+
if (promotionManager.maybeShowPromotion(promotionId)) {
2143+
const badge = document.createElement('div');
2144+
badge.className = 'new-badge';
2145+
badge.textContent = i18nString(UIStrings.new);
2146+
badge.setAttribute('jslog', `${VisualLogging.badge('new-badge')}`);
2147+
return badge;
2148+
}
2149+
return undefined;
2150+
}

front_end/ui/legacy/components/quick_open/CommandMenu.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ export class CommandMenuProvider extends Provider {
344344
UI.UIUtils.createTextChild(titleElement, command.title);
345345
FilteredListWidget.highlightRanges(titleElement, query, true);
346346

347+
if (command.promoteFeature) {
348+
const badge = UI.UIUtils.maybeCreateNewBadge('ai-asisstance');
349+
if (badge) {
350+
titleElement.parentElement?.insertBefore(badge, subtitleElement);
351+
}
352+
}
353+
347354
subtitleElement.textContent = command.shortcut;
348355

349356
const deprecationWarning = command.deprecationWarning;

front_end/ui/legacy/components/quick_open/filteredListWidget.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ devtools-text-prompt {
136136

137137
.filtered-list-widget-item.one-row {
138138
line-height: var(--sys-typescale-body3-line-height);
139+
align-items: center;
139140
align-content: center;
140141
display: flex;
142+
gap: var(--sys-size-4);
141143
}
142144

143145
.filtered-list-widget-item.one-row .filtered-list-widget-title {

front_end/ui/legacy/inspectorCommon.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,19 @@ dt-icon-label {
526526
background-color: var(--sys-color-purple-bright);
527527
}
528528

529+
.new-badge {
530+
width: fit-content;
531+
height: var(--sys-size-7);
532+
line-height: var(--sys-size-7);
533+
border-radius: var(--sys-shape-corner-extra-small);
534+
padding: 0 var(--sys-size-3);
535+
background-color: var(--sys-color-primary);
536+
color: var(--sys-color-on-primary);
537+
font-weight: var(--ref-typeface-weight-bold);
538+
font-size: 9px;
539+
text-align: center;
540+
}
541+
529542
.expandable-inline-button {
530543
background-color: var(--sys-color-cdt-base-container);
531544
color: var(--sys-color-on-surface);

front_end/ui/legacy/softContextMenu.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
background-color: var(--sys-color-state-hover-on-subtle);
4141
}
4242

43+
& .new-badge {
44+
margin-left: var(--sys-size-4);
45+
}
46+
4347
& devtools-icon {
4448
width: var(--sys-size-8);
4549
height: var(--sys-size-8);

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,7 @@ export const knownContextValues = new Set([
25702570
'never-pause-here',
25712571
'new-attribute',
25722572
'new-authenticator',
2573+
'new-badge',
25732574
'new-file',
25742575
'next',
25752576
'next-page',

front_end/ui/visual_logging/LoggingConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export enum VisualElements {
6161
Gutter = 22,
6262
MetricsBox = 23,
6363
MetricsBoxPart = 24,
64-
/* 25 used to be DOMBreakpointsPane, but free to grab now */
64+
Badge = 25,
6565
DOMBreakpoint = 26,
6666
/* 27 used to be ElementPropertiesPane, but free to grab now */
6767
/* 28 used to be EventListenersPane, but free to grab now */

front_end/ui/visual_logging/visual_logging.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function setHighlightedVe(veKey: string|null): void {
5757
export const action = LoggingConfig.makeConfigStringBuilder.bind(null, 'Action');
5858
export const adorner = LoggingConfig.makeConfigStringBuilder.bind(null, 'Adorner');
5959
export const animationClip = LoggingConfig.makeConfigStringBuilder.bind(null, 'AnimationClip');
60+
export const badge = LoggingConfig.makeConfigStringBuilder.bind(null, 'Badge');
6061
export const bezierCurveEditor = LoggingConfig.makeConfigStringBuilder.bind(null, 'BezierCurveEditor');
6162
export const bezierPresetCategory = LoggingConfig.makeConfigStringBuilder.bind(null, 'BezierPresetCategory');
6263
export const breakpointMarker = LoggingConfig.makeConfigStringBuilder.bind(null, 'BreakpointMarker');

0 commit comments

Comments
 (0)