Skip to content

Commit cb1c422

Browse files
paulirishDevtools-frontend LUCI CQ
authored andcommitted
TS: Upgrade callers of CheckboxLabel.create from string to LocalizedString
No functional change. Just using more specific types when possible. CheckboxLabel.createWithStringLiteral() introduced to handle some edge cases. Change-Id: I25adf3ae7ee057dbeb3b7ad81da76b9071610e7f Bug: 379694205 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6044325 Reviewed-by: Connor Clark <[email protected]> Auto-Submit: Paul Irish <[email protected]> Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent 5efac90 commit cb1c422

File tree

21 files changed

+69
-41
lines changed

21 files changed

+69
-41
lines changed

front_end/core/common/Settings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export class Deprecation {
367367

368368
export class Setting<V> {
369369
#titleFunction?: () => Platform.UIString.LocalizedString;
370-
#titleInternal!: string;
370+
#titleInternal!: Platform.UIString.LocalizedString;
371371
#registration: SettingRegistration|null = null;
372372
#requiresUserAction?: boolean;
373373
#value?: V;
@@ -395,14 +395,14 @@ export class Setting<V> {
395395
this.eventSupport.removeEventListener(this.name, listener, thisObject);
396396
}
397397

398-
title(): string {
398+
title(): Platform.UIString.LocalizedString {
399399
if (this.#titleInternal) {
400400
return this.#titleInternal;
401401
}
402402
if (this.#titleFunction) {
403403
return this.#titleFunction();
404404
}
405-
return '';
405+
return '' as Platform.UIString.LocalizedString;
406406
}
407407

408408
setTitleFunction(titleFunction: (() => Platform.UIString.LocalizedString)|undefined): void {
@@ -411,7 +411,7 @@ export class Setting<V> {
411411
}
412412
}
413413

414-
setTitle(title: string): void {
414+
setTitle(title: Platform.UIString.LocalizedString): void {
415415
this.#titleInternal = title;
416416
}
417417

front_end/core/root/Runtime.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import type * as Platform from '../platform/platform.js';
6+
57
import * as Root from './root.js';
68

79
describe('Runtime', () => {
@@ -35,8 +37,8 @@ describe('Runtime', () => {
3537
});
3638

3739
it('allConfigurableExperiments returns all registered experiments', () => {
38-
Root.Runtime.experiments.register('example', 'example');
39-
Root.Runtime.experiments.register('configurable', 'configurable');
40+
Root.Runtime.experiments.register('example', 'example' as Platform.UIString.LocalizedString);
41+
Root.Runtime.experiments.register('configurable', 'configurable' as Platform.UIString.LocalizedString);
4042

4143
const experiments = Root.Runtime.experiments.allConfigurableExperiments();
4244

front_end/entrypoints/inspector_main/RenderingOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ export class RenderingOptionsView extends UI.Widget.VBox {
290290
}
291291

292292
#appendCheckbox(
293-
label: string, subtitle: string, setting: Common.Settings.Setting<boolean>,
294-
metric?: UI.SettingsUI.UserMetricOptions): UI.UIUtils.CheckboxLabel {
293+
label: Common.UIString.LocalizedString, subtitle: Common.UIString.LocalizedString,
294+
setting: Common.Settings.Setting<boolean>, metric?: UI.SettingsUI.UserMetricOptions): UI.UIUtils.CheckboxLabel {
295295
const checkbox = UI.UIUtils.CheckboxLabel.create(label, false, subtitle, setting.name);
296296
UI.SettingsUI.bindCheckbox(checkbox.checkboxElement, setting, metric);
297297
this.contentElement.appendChild(checkbox);

front_end/panels/application/StorageView.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ export class StorageView extends UI.ThrottledWidget.ThrottledWidget {
221221
this.previousOverrideFieldValue = '';
222222
const quotaOverrideCheckboxRow = quota.appendRow();
223223
quotaOverrideCheckboxRow.classList.add('quota-override-row');
224-
this.quotaOverrideCheckbox =
225-
UI.UIUtils.CheckboxLabel.create(i18nString(UIStrings.simulateCustomStorage), false, '');
224+
this.quotaOverrideCheckbox = UI.UIUtils.CheckboxLabel.create(i18nString(UIStrings.simulateCustomStorage), false);
226225
this.quotaOverrideCheckbox.setAttribute(
227226
'jslog', `${VisualLogging.toggle('simulate-custom-quota').track({change: true})}`);
228227
quotaOverrideCheckboxRow.appendChild(this.quotaOverrideCheckbox);
@@ -277,7 +276,9 @@ export class StorageView extends UI.ThrottledWidget.ThrottledWidget {
277276
SDK.TargetManager.TargetManager.instance().observeTargets(this);
278277
}
279278

280-
private appendItem(section: UI.ReportView.Section, title: string, settingName: Protocol.Storage.StorageType): void {
279+
private appendItem(
280+
section: UI.ReportView.Section, title: Platform.UIString.LocalizedString,
281+
settingName: Protocol.Storage.StorageType): void {
281282
const row = section.appendRow();
282283
const setting = this.settings.get(settingName);
283284
if (setting) {

front_end/panels/console/ConsoleView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,9 @@ export class ConsoleView extends UI.Widget.VBox implements
584584
}
585585

586586
static appendSettingsCheckboxToToolbar(
587-
toolbar: UI.Toolbar.Toolbar, settingOrSetingName: Common.Settings.Setting<boolean>|string, title: string,
588-
alternateTitle?: string): UI.Toolbar.ToolbarSettingCheckbox {
587+
toolbar: UI.Toolbar.Toolbar, settingOrSetingName: Common.Settings.Setting<boolean>|string,
588+
title: Common.UIString.LocalizedString,
589+
alternateTitle?: Common.UIString.LocalizedString): UI.Toolbar.ToolbarSettingCheckbox {
589590
let setting: Common.Settings.Setting<boolean>;
590591
if (typeof settingOrSetingName === 'string') {
591592
setting = Common.Settings.Settings.instance().moduleSetting(settingOrSetingName);

front_end/panels/elements/ClassesPaneWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ export class ClassesPaneWidget extends UI.Widget.Widget {
179179
const keys = [...classes.keys()];
180180
keys.sort(Platform.StringUtilities.caseInsensetiveComparator);
181181
for (const className of keys) {
182-
const label =
183-
UI.UIUtils.CheckboxLabel.create(className, classes.get(className), undefined, 'element-class', true);
182+
const label = UI.UIUtils.CheckboxLabel.createWithStringLiteral(
183+
className, classes.get(className), undefined, 'element-class', true);
184184
label.classList.add('monospace');
185185
label.checkboxElement.addEventListener('click', this.onClick.bind(this, className), false);
186186
this.classesContainer.appendChild(label);

front_end/panels/elements/ElementStatePaneWidget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class ElementStatePaneWidget extends UI.Widget.Widget {
109109
const createElementStateCheckbox = (state: string): HTMLDivElement => {
110110
const div = document.createElement('div');
111111
div.id = state;
112-
const label = UI.UIUtils.CheckboxLabel.create(':' + state, undefined, undefined, undefined, true);
112+
const label =
113+
UI.UIUtils.CheckboxLabel.createWithStringLiteral(':' + state, undefined, undefined, undefined, true);
113114
const input = label.checkboxElement;
114115
this.inputStates.set(input, state);
115116
input.addEventListener('click', (clickListener as EventListener), false);

front_end/panels/elements/components/LayoutPane.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ describeWithMockConnection('LayoutPane', () => {
5353
}
5454

5555
it('renders settings', async () => {
56-
Common.Settings.Settings.instance().moduleSetting('show-grid-line-labels').setTitle('Enum setting title');
57-
Common.Settings.Settings.instance().moduleSetting('show-grid-track-sizes').setTitle('Boolean setting title');
56+
Common.Settings.Settings.instance()
57+
.moduleSetting('show-grid-line-labels')
58+
.setTitle('Enum setting title' as Platform.UIString.LocalizedString);
59+
Common.Settings.Settings.instance()
60+
.moduleSetting('show-grid-track-sizes')
61+
.setTitle('Boolean setting title' as Platform.UIString.LocalizedString);
5862

5963
const component = await renderComponent();
6064
assert.deepEqual(queryLabels(component, '[data-enum-setting]'), [{label: 'Enum setting title', input: 'SELECT'}]);

front_end/panels/layer_viewer/Layers3DView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,9 @@ export class Layers3DView extends Common.ObjectWrapper.eventMixin<EventTypes, ty
820820
return closestObject;
821821
}
822822

823-
private createVisibilitySetting(caption: string, name: string, value: boolean, toolbar: UI.Toolbar.Toolbar):
824-
Common.Settings.Setting<boolean> {
823+
private createVisibilitySetting(
824+
caption: Common.UIString.LocalizedString, name: string, value: boolean,
825+
toolbar: UI.Toolbar.Toolbar): Common.Settings.Setting<boolean> {
825826
const setting = Common.Settings.Settings.instance().createSetting(name, value);
826827
setting.setTitle(caption);
827828
setting.addChangeListener(this.update, this);

front_end/panels/network/NetworkConfigView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export class NetworkConfigView extends UI.Widget.VBox {
339339
Zstd: Protocol.Network.ContentEncoding.Zstd,
340340
};
341341
for (const encoding of Object.values(contentEncodings)) {
342-
const label = UI.UIUtils.CheckboxLabel.create(encoding, true, undefined, encoding);
342+
const label = UI.UIUtils.CheckboxLabel.createWithStringLiteral(encoding, true, undefined, encoding);
343343
encodingsSection.appendChild(label);
344344
checkboxes.set(encoding, label.checkboxElement);
345345
}

0 commit comments

Comments
 (0)