Skip to content

Commit 378550e

Browse files
Adam RaineDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Add Node specific title for the history manager
Bug: 381886477 Change-Id: I58f06e901e9d0eab9c49891579546b0e72ad0f2c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6112197 Auto-Submit: Adam Raine <[email protected]> Commit-Queue: Adam Raine <[email protected]> Reviewed-by: Adriana Ixba <[email protected]> Commit-Queue: Adriana Ixba <[email protected]>
1 parent 3c820cb commit 378550e

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed

front_end/panels/timeline/TimelineHistoryManager.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ describeWithEnvironment('TimelineHistoryManager', function() {
2323
});
2424

2525
it('shows the dropdown including a landing page link', async function() {
26+
assert.strictEqual(historyManager.button().element.innerText!, 'Live metrics');
27+
2628
const {parsedTrace, metadata} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
2729
historyManager.addRecording(
2830
{
@@ -36,6 +38,8 @@ describeWithEnvironment('TimelineHistoryManager', function() {
3638
},
3739
);
3840

41+
assert.strictEqual(historyManager.button().element.innerText!, 'web.dev #1');
42+
3943
const showPromise = historyManager.showHistoryDropDown();
4044
const glassPane = document.querySelector('div[data-devtools-glass-pane]');
4145
const dropdown =
@@ -53,6 +57,40 @@ describeWithEnvironment('TimelineHistoryManager', function() {
5357
await showPromise;
5458
});
5559

60+
it('uses Node specific landing page title', async function() {
61+
historyManager = new Timeline.TimelineHistoryManager.TimelineHistoryManager(undefined, true);
62+
assert.strictEqual(historyManager.button().element.innerText!, 'New recording');
63+
64+
const {parsedTrace, metadata} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
65+
historyManager.addRecording(
66+
{
67+
data: {
68+
parsedTraceIndex: 1,
69+
type: 'TRACE_INDEX',
70+
},
71+
filmStripForPreview: null,
72+
parsedTrace,
73+
metadata,
74+
},
75+
);
76+
77+
const showPromise = historyManager.showHistoryDropDown();
78+
const glassPane = document.querySelector('div[data-devtools-glass-pane]');
79+
const dropdown =
80+
glassPane?.shadowRoot?.querySelector('.widget')?.shadowRoot?.querySelector<HTMLElement>('.drop-down');
81+
assert.isOk(dropdown);
82+
83+
const menuItemText = Array.from(dropdown.querySelectorAll<HTMLDivElement>('[role="menuitem"]'), elem => {
84+
return elem.innerText.replaceAll('\n', '');
85+
});
86+
assert.deepEqual(menuItemText, ['New recording', 'web.dev1× slowdown, No throttling']);
87+
88+
// Cancel the dropdown, which also resolves the show() promise, meaning we
89+
// don't leak it into other tests.
90+
historyManager.cancelIfShowing();
91+
await showPromise;
92+
});
93+
5694
it('can select from multiple parsed data objects', async function() {
5795
// Add two parsed data objects to the history manager.
5896
const {parsedTrace: trace1Data, metadata: metadata1} =

front_end/panels/timeline/TimelineHistoryManager.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import * as Common from '../../core/common/common.js';
66
import * as i18n from '../../core/i18n/i18n.js';
77
import * as Platform from '../../core/platform/platform.js';
8-
import * as CrUXManager from '../../models/crux-manager/crux-manager.js';
98
import type * as Trace from '../../models/trace/trace.js';
109
import * as IconButton from '../../ui/components/icon_button/icon_button.js';
1110
import * as UI from '../../ui/legacy/legacy.js';
@@ -39,6 +38,10 @@ const UIStrings = {
3938
*@description the title shown when the user is viewing the landing page which is showing live performance metrics that are updated automatically.
4039
*/
4140
landingPageTitle: 'Live metrics',
41+
/**
42+
* @description the title shown when the user is viewing the landing page which can be used to make a new performance recording.
43+
*/
44+
nodeLandingPageTitle: 'New recording',
4245
/**
4346
*@description Text in Timeline History Manager of the Performance panel
4447
*@example {example.com} PH1
@@ -112,13 +115,18 @@ export class TimelineHistoryManager {
112115
private enabled: boolean;
113116
private lastActiveTrace: RecordingData|null = null;
114117
#minimapComponent?: TimelineMiniMap;
115-
constructor(minimapComponent?: TimelineMiniMap) {
118+
#landingPageTitle: Common.UIString.LocalizedString;
119+
120+
constructor(minimapComponent?: TimelineMiniMap, isNode?: boolean) {
116121
this.recordings = [];
117122
this.#minimapComponent = minimapComponent;
118123
this.action = UI.ActionRegistry.ActionRegistry.instance().getAction('timeline.show-history');
119124
this.nextNumberByDomain = new Map();
120125
this.buttonInternal = new ToolbarButton(this.action);
121126

127+
this.#landingPageTitle =
128+
isNode ? i18nString(UIStrings.nodeLandingPageTitle) : i18nString(UIStrings.landingPageTitle);
129+
122130
UI.ARIAUtils.markAsMenuButton(this.buttonInternal.element);
123131
this.clear();
124132

@@ -160,25 +168,6 @@ export class TimelineHistoryManager {
160168
];
161169
this.totalHeight = this.allOverviews.reduce((acc, entry) => acc + entry.height, 0);
162170
this.enabled = true;
163-
164-
CrUXManager.CrUXManager.instance().addEventListener(CrUXManager.Events.FIELD_DATA_CHANGED, () => {
165-
this.#updateLandingPageTitleIfActive();
166-
});
167-
}
168-
169-
/**
170-
* If the user changes the CrUX consent status, the title shown in the
171-
* dropdown could be outdated, as we show "Local" or "Local and field"
172-
* depending on if the user has consented.
173-
* This method will be called whenever the CrUXManager detects a change, and
174-
* we use it as a chance to re-evaluate if the title needs changing or not.
175-
*/
176-
#updateLandingPageTitleIfActive(): void {
177-
if (this.lastActiveTrace?.type === 'LANDING_PAGE') {
178-
const title = this.title(this.lastActiveTrace);
179-
this.buttonInternal.setTitle(title);
180-
this.buttonInternal.setText(title);
181-
}
182171
}
183172

184173
addRecording(newInput: NewHistoryRecordingData): void {
@@ -225,7 +214,7 @@ export class TimelineHistoryManager {
225214
this.recordings = [];
226215
this.lastActiveTrace = null;
227216
this.updateState();
228-
this.buttonInternal.setText(i18nString(UIStrings.landingPageTitle));
217+
this.buttonInternal.setText(this.#landingPageTitle);
229218
this.nextNumberByDomain.clear();
230219
}
231220

@@ -247,7 +236,7 @@ export class TimelineHistoryManager {
247236
// DropDown.show() function finishes when the dropdown menu is closed via selection or losing focus
248237
const activeTraceIndex = await DropDown.show(
249238
this.recordings.map(recording => recording.parsedTraceIndex), this.#getActiveTraceIndexForListControl(),
250-
this.buttonInternal.element);
239+
this.buttonInternal.element, this.#landingPageTitle);
251240

252241
if (activeTraceIndex === null) {
253242
return null;
@@ -336,7 +325,7 @@ export class TimelineHistoryManager {
336325

337326
private title(item: RecordingData): string {
338327
if (item.type === 'LANDING_PAGE') {
339-
return i18nString(UIStrings.landingPageTitle);
328+
return this.#landingPageTitle;
340329
}
341330

342331
const data = TimelineHistoryManager.dataForTraceIndex(item.parsedTraceIndex);
@@ -463,8 +452,11 @@ export class DropDown implements UI.ListControl.ListDelegate<number> {
463452
private readonly listControl: UI.ListControl.ListControl<number>;
464453
private readonly focusRestorer: UI.UIUtils.ElementFocusRestorer;
465454
private selectionDone: ((arg0: number|null) => void)|null;
455+
#landingPageTitle: Common.UIString.LocalizedString;
456+
457+
constructor(availableparsedTraceIndexes: number[], landingPageTitle: Common.UIString.LocalizedString) {
458+
this.#landingPageTitle = landingPageTitle;
466459

467-
constructor(availableparsedTraceIndexes: number[]) {
468460
this.glassPane = new UI.GlassPane.GlassPane();
469461
this.glassPane.setSizeBehavior(UI.GlassPane.SizeBehavior.MEASURE_CONTENT);
470462
this.glassPane.setOutsideClickCallback(() => this.close(null));
@@ -493,14 +485,16 @@ export class DropDown implements UI.ListControl.ListDelegate<number> {
493485
this.selectionDone = null;
494486
}
495487

496-
static show(availableparsedTraceIndexes: number[], activeparsedTraceIndex: number, anchor: Element):
488+
static show(
489+
availableparsedTraceIndexes: number[], activeparsedTraceIndex: number, anchor: Element,
490+
landingPageTitle: Common.UIString.LocalizedString = i18nString(UIStrings.landingPageTitle)):
497491
Promise<number|null> {
498492
if (DropDown.instance) {
499493
return Promise.resolve(null);
500494
}
501495
const availableDropdownChoices = [...availableparsedTraceIndexes];
502496
availableDropdownChoices.unshift(LANDING_PAGE_INDEX_DROPDOWN_CHOICE);
503-
const instance = new DropDown(availableDropdownChoices);
497+
const instance = new DropDown(availableDropdownChoices, landingPageTitle);
504498
return instance.show(anchor, activeparsedTraceIndex);
505499
}
506500

@@ -588,7 +582,7 @@ export class DropDown implements UI.ListControl.ListDelegate<number> {
588582
div.appendChild(icon);
589583

590584
const text = document.createElement('span');
591-
text.innerText = i18nString(UIStrings.landingPageTitle);
585+
text.innerText = this.#landingPageTitle;
592586
div.appendChild(text);
593587
return div;
594588
}

front_end/panels/timeline/TimelinePanel.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
516516
this.toggleRecordAction = UI.ActionRegistry.ActionRegistry.instance().getAction('timeline.toggle-recording');
517517
this.recordReloadAction = UI.ActionRegistry.ActionRegistry.instance().getAction('timeline.record-reload');
518518

519-
this.#historyManager = new TimelineHistoryManager(this.#minimapComponent);
519+
this.#historyManager = new TimelineHistoryManager(this.#minimapComponent, isNode);
520520

521521
this.traceLoadStart = null;
522522

@@ -1085,14 +1085,16 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
10851085
// History
10861086
this.panelToolbar.appendSeparator();
10871087

1088-
this.homeButton = new UI.Toolbar.ToolbarButton(
1089-
i18nString(UIStrings.backToLiveMetrics), 'home', undefined, 'timeline.back-to-live-metrics');
1090-
this.homeButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, () => {
1091-
this.#changeView({mode: 'LANDING_PAGE'});
1092-
this.#historyManager.navigateToLandingPage();
1093-
});
1094-
this.panelToolbar.appendToolbarItem(this.homeButton);
1095-
this.panelToolbar.appendSeparator();
1088+
if (!isNode) {
1089+
this.homeButton = new UI.Toolbar.ToolbarButton(
1090+
i18nString(UIStrings.backToLiveMetrics), 'home', undefined, 'timeline.back-to-live-metrics');
1091+
this.homeButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, () => {
1092+
this.#changeView({mode: 'LANDING_PAGE'});
1093+
this.#historyManager.navigateToLandingPage();
1094+
});
1095+
this.panelToolbar.appendToolbarItem(this.homeButton);
1096+
this.panelToolbar.appendSeparator();
1097+
}
10961098

10971099
this.panelToolbar.appendToolbarItem(this.#historyManager.button());
10981100
this.panelToolbar.registerCSSFiles([historyToolbarButtonStyles]);

0 commit comments

Comments
 (0)