Skip to content

Commit 0052fd3

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[Settings] Update Sync section to be Account section
Please see the screenshots in the attached bug. Changes are: * Started showing the account info even if the sync is not enabled. * Added a not signed in state for the case when the user is not signed in. Previously, it was showing "You need to enable sync" warning and the link was going to "about:blank". * Updated the warnings to be rendered in a tooltip that's triggered by the info icon. Refactorings are: * Updated "Sync" texts to be "Account" texts. * Updated Sync category to be Account category for the settings. Bypass-Check-License: Only updates files, no new files are added. Fixed: 436201259 Change-Id: Ifee27b1796737b5dae5b5b7864b8379b05f9f18d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6862745 Commit-Queue: Ergün Erdoğmuş <[email protected]> Reviewed-by: Simon Zünd <[email protected]>
1 parent 69742b8 commit 0052fd3

File tree

7 files changed

+133
-55
lines changed

7 files changed

+133
-55
lines changed

front_end/core/common/SettingRegistration.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ const UIStrings = {
7474
*/
7575
adorner: 'Adorner',
7676
/**
77-
* @description Header for the "Sync" section in the settings UI. The "Sync"
78-
* section allows users to configure which DevTools data is synced via Chrome Sync.
77+
* @description Header for the "Account" section in the settings UI. The "Account"
78+
* section allows users see their signed in account and configure which DevTools data is synced via Chrome Sync.
7979
*/
80-
sync: 'Sync',
80+
account: 'Account',
8181
/**
8282
* @description Text for the privacy section of the page.
8383
*/
@@ -148,7 +148,7 @@ export const enum SettingCategory {
148148
MEMORY = 'MEMORY',
149149
EXTENSIONS = 'EXTENSIONS',
150150
ADORNER = 'ADORNER',
151-
SYNC = 'SYNC',
151+
ACCOUNT = 'ACCOUNT',
152152
PRIVACY = 'PRIVACY',
153153
}
154154

@@ -190,8 +190,8 @@ export function getLocalizedSettingsCategory(category: SettingCategory): Platfor
190190
return i18nString(UIStrings.adorner);
191191
case SettingCategory.NONE:
192192
return i18n.i18n.lockedString('');
193-
case SettingCategory.SYNC:
194-
return i18nString(UIStrings.sync);
193+
case SettingCategory.ACCOUNT:
194+
return i18nString(UIStrings.account);
195195
case SettingCategory.PRIVACY:
196196
return i18nString(UIStrings.privacy);
197197
}

front_end/entrypoints/main/main-meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ function createOptionForLocale(localeString: string): Common.Settings.SettingExt
781781
}
782782

783783
Common.Settings.registerSettingExtension({
784-
category: Common.Settings.SettingCategory.SYNC,
784+
category: Common.Settings.SettingCategory.ACCOUNT,
785785
// This name must be kept in sync with DevToolsSettings::kSyncDevToolsPreferencesFrontendName.
786786
settingName: 'sync-preferences',
787787
settingType: Common.Settings.SettingType.BOOLEAN,

front_end/panels/settings/SettingsScreen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export class GenericSettingsTab extends UI.Widget.VBox implements SettingsTab {
275275
Common.Settings.SettingCategory.PERSISTENCE,
276276
Common.Settings.SettingCategory.DEBUGGER,
277277
Common.Settings.SettingCategory.GLOBAL,
278-
Common.Settings.SettingCategory.SYNC,
278+
Common.Settings.SettingCategory.ACCOUNT,
279279
];
280280

281281
// Some settings define their initial ordering.
@@ -360,9 +360,9 @@ export class GenericSettingsTab extends UI.Widget.VBox implements SettingsTab {
360360
// Always create the EXTENSIONS section and append the link handling control.
361361
if (category === Common.Settings.SettingCategory.EXTENSIONS) {
362362
this.createExtensionSection(settings);
363-
} else if (category === Common.Settings.SettingCategory.SYNC && settings.length > 0) {
363+
} else if (category === Common.Settings.SettingCategory.ACCOUNT && settings.length > 0) {
364364
const syncCard = createSettingsCard(
365-
Common.SettingRegistration.getLocalizedSettingsCategory(Common.SettingRegistration.SettingCategory.SYNC),
365+
Common.SettingRegistration.getLocalizedSettingsCategory(Common.SettingRegistration.SettingCategory.ACCOUNT),
366366
this.syncSection);
367367
this.containerElement.appendChild(syncCard);
368368
} else if (settings.length > 0) {

front_end/panels/settings/components/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ devtools_module("components") {
2222
"../../../ui/components/chrome_link:bundle",
2323
"../../../ui/components/helpers:bundle",
2424
"../../../ui/components/settings:bundle",
25+
"../../../ui/components/tooltips:bundle",
2526
"../../../ui/lit:bundle",
2627
]
2728
}

front_end/panels/settings/components/SyncSection.test.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,46 @@ async function renderSyncSection(data: PanelComponents.SyncSection.SyncSectionDa
2020
}
2121

2222
describeWithLocale('SyncSection', () => {
23-
it('shows a warning when sync is not active', async () => {
23+
it('shows a warning tooltip when sync is not active and the user is signed in', async () => {
2424
const syncSetting = createFakeSetting<boolean>('setting', true);
25-
const {shadowRoot} = await renderSyncSection({syncInfo: {isSyncActive: false}, syncSetting});
26-
const warning = shadowRoot.querySelector('.warning');
25+
const {shadowRoot} = await renderSyncSection({
26+
syncInfo: {
27+
isSyncActive: false,
28+
accountEmail: '[email protected]',
29+
},
30+
syncSetting
31+
});
32+
const warning = shadowRoot.querySelector('devtools-tooltip');
2733
assert.instanceOf(warning, HTMLElement);
2834
assert.include(warning.innerText, 'To turn this setting on');
2935
});
3036

31-
it('shows a warning when sync is active but preferences bucket is not synced', async () => {
37+
it('shows a warning tooltip when sync is active but preferences bucket is not synced', async () => {
3238
const syncSetting = createFakeSetting<boolean>('setting', true);
33-
const {shadowRoot} =
34-
await renderSyncSection({syncInfo: {isSyncActive: true, arePreferencesSynced: false}, syncSetting});
39+
const {shadowRoot} = await renderSyncSection({
40+
syncInfo: {
41+
isSyncActive: true,
42+
arePreferencesSynced: false,
43+
accountEmail: '[email protected]',
44+
},
45+
syncSetting
46+
});
3547

36-
const warning = shadowRoot.querySelector('.warning');
48+
const warning = shadowRoot.querySelector('devtools-tooltip');
3749
assert.instanceOf(warning, HTMLElement);
3850

3951
assert.include(warning.innerText, 'To turn this setting on');
4052
});
4153

4254
it('disables the checkbox when sync is not active', async () => {
4355
const syncSetting = createFakeSetting<boolean>('setting', true);
44-
const {shadowRoot} = await renderSyncSection({syncInfo: {isSyncActive: false}, syncSetting});
56+
const {shadowRoot} = await renderSyncSection({
57+
syncInfo: {
58+
isSyncActive: false,
59+
accountEmail: '[email protected]',
60+
},
61+
syncSetting
62+
});
4563

4664
const settingCheckbox = shadowRoot.querySelector('setting-checkbox');
4765
assert.instanceOf(settingCheckbox, SettingComponents.SettingCheckbox.SettingCheckbox);
@@ -53,7 +71,7 @@ describeWithLocale('SyncSection', () => {
5371
assert.isTrue(checkbox.disabled);
5472
});
5573

56-
it('shows the avatar and email of the logged in user when sync is active', async () => {
74+
it('shows the avatar and email of the logged in user', async () => {
5775
const syncSetting = createFakeSetting<boolean>('setting', true);
5876
const {shadowRoot} = await renderSyncSection({
5977
syncInfo: {
@@ -73,4 +91,20 @@ describeWithLocale('SyncSection', () => {
7391

7492
assert.include(email.innerText, '[email protected]');
7593
});
94+
95+
it('shows not signed in if the user is not logged in', async () => {
96+
const syncSetting = createFakeSetting<boolean>('setting', true);
97+
const {shadowRoot} = await renderSyncSection({
98+
syncInfo: {
99+
isSyncActive: false,
100+
arePreferencesSynced: false,
101+
},
102+
syncSetting,
103+
});
104+
105+
const email = shadowRoot.querySelector('.not-signed-in');
106+
assert.instanceOf(email, HTMLElement);
107+
108+
assert.include(email.innerText, 'not signed into Chrome');
109+
});
76110
});

front_end/panels/settings/components/SyncSection.ts

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import '../../../ui/components/chrome_link/chrome_link.js';
77
import '../../../ui/components/settings/settings.js';
8+
import '../../../ui/components/tooltips/tooltips.js';
89

910
import type * as Common from '../../../core/common/common.js';
1011
import type * as Host from '../../../core/host/host.js';
1112
import * as i18n from '../../../core/i18n/i18n.js';
1213
import type * as Platform from '../../../core/platform/platform.js';
14+
import * as Buttons from '../../../ui/components/buttons/buttons.js';
1315
import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js';
1416
import * as Lit from '../../../ui/lit/lit.js';
1517

@@ -28,16 +30,16 @@ const UIStrings = {
2830
* to a checkbox that is disabled.
2931
*/
3032
preferencesSyncDisabled: 'To turn this setting on, you must first enable settings sync in Chrome.',
31-
/**
32-
* @description Label for a link that take the user to the "Sync" section of the
33-
* chrome settings. The link is shown in the DevTools Settings UI.
34-
*/
35-
settings: 'Go to Settings',
3633
/**
3734
* @description Label for the account email address. Shown in the DevTools Settings UI in
3835
* front of the email address currently used for Chrome Sync.
3936
*/
4037
signedIn: 'Signed into Chrome as:',
38+
/**
39+
* @description Label for the account settings. Shown in the DevTools Settings UI in
40+
* case the user is not logged in to Chrome.
41+
*/
42+
notSignedIn: 'You\'re not signed into Chrome.',
4143
} as const;
4244
const str_ = i18n.i18n.registerUIStrings('panels/settings/components/SyncSection.ts', UIStrings);
4345
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -61,7 +63,7 @@ export class SyncSection extends HTMLElement {
6163

6264
#render(): void {
6365
if (!this.#syncSetting) {
64-
throw new Error('SyncSection not properly initialized');
66+
throw new Error('SyncSection is not properly initialized');
6567
}
6668

6769
// TODO: this should not probably happen in render, instead, the setting
@@ -73,41 +75,72 @@ export class SyncSection extends HTMLElement {
7375
Lit.render(html`
7476
<style>${syncSectionStyles}</style>
7577
<fieldset>
76-
${renderAccountInfoOrWarning(this.#syncInfo)}
77-
<setting-checkbox .data=${
78-
{setting: this.#syncSetting}}>
79-
</setting-checkbox>
78+
${renderAccountInfo(this.#syncInfo)}
79+
${renderSettingCheckboxIfNeeded(this.#syncInfo, this.#syncSetting)}
8080
</fieldset>
8181
`, this.#shadow, {host: this});
8282
// clang-format on
8383
}
8484
}
8585

86-
/* x-link doesn't work with custom click/keydown handlers */
86+
function renderSettingCheckboxIfNeeded(
87+
syncInfo: Host.InspectorFrontendHostAPI.SyncInformation,
88+
syncSetting: Common.Settings.Setting<boolean>): Lit.LitTemplate {
89+
if (!syncInfo.accountEmail) {
90+
return Lit.nothing;
91+
}
8792

88-
function renderAccountInfoOrWarning(syncInfo: Host.InspectorFrontendHostAPI.SyncInformation): Lit.TemplateResult {
89-
if (!syncInfo.isSyncActive) {
90-
const link = 'chrome://settings/syncSetup' as Platform.DevToolsPath.UrlString;
91-
// Disabled until https://crbug.com/1079231 is fixed.
92-
// clang-format off
93-
return html`
94-
<span class="warning">
95-
${i18nString(UIStrings.syncDisabled)}
96-
<devtools-chrome-link .href=${link}>${i18nString(UIStrings.settings)}</devtools-chrome-link>
97-
</span>`;
98-
// clang-format on
93+
// clang-format off
94+
return html`
95+
<div class="setting-checkbox-container">
96+
<setting-checkbox class="setting-checkbox" .data=${{setting: syncSetting}}>
97+
</setting-checkbox>
98+
${renderWarningIfNeeded(syncInfo)}
99+
</div>
100+
`;
101+
// clang-format on
102+
}
103+
104+
function renderWarningIfNeeded(syncInfo: Host.InspectorFrontendHostAPI.SyncInformation): Lit.LitTemplate {
105+
const hasWarning = !syncInfo.isSyncActive || !syncInfo.arePreferencesSynced;
106+
if (!hasWarning) {
107+
return Lit.nothing;
99108
}
100-
if (!syncInfo.arePreferencesSynced) {
101-
const link = 'chrome://settings/syncSetup/advanced' as Platform.DevToolsPath.UrlString;
102-
// Disabled until https://crbug.com/1079231 is fixed.
109+
110+
const warningLink = !syncInfo.isSyncActive ?
111+
'chrome://settings/syncSetup' as Platform.DevToolsPath.UrlString :
112+
'chrome://settings/syncSetup/advanced' as Platform.DevToolsPath.UrlString;
113+
const warningText =
114+
!syncInfo.isSyncActive ? i18nString(UIStrings.syncDisabled) : i18nString(UIStrings.preferencesSyncDisabled);
115+
// clang-format off
116+
return html`
117+
<devtools-chrome-link .href=${warningLink}>
118+
<devtools-button
119+
aria-describedby=settings-sync-info
120+
.iconName=${'info'}
121+
.variant=${Buttons.Button.Variant.ICON}
122+
.size=${Buttons.Button.Size.SMALL}>
123+
</devtools-button>
124+
</devtools-chrome-link>
125+
<devtools-tooltip
126+
id=settings-sync-info
127+
variant=simple>
128+
${warningText}
129+
</devtools-tooltip>
130+
`;
131+
// clang-format on
132+
}
133+
134+
function renderAccountInfo(syncInfo: Host.InspectorFrontendHostAPI.SyncInformation): Lit.LitTemplate {
135+
if (!syncInfo.accountEmail) {
103136
// clang-format off
104137
return html`
105-
<span class="warning">
106-
${i18nString(UIStrings.preferencesSyncDisabled)}
107-
<devtools-chrome-link .href=${link}>${i18nString(UIStrings.settings)}</devtools-chrome-link>
108-
</span>`;
138+
<div class="not-signed-in">${i18nString(UIStrings.notSignedIn)}</div>
139+
`;
109140
// clang-format on
110141
}
142+
143+
// clang-format off
111144
return html`
112145
<div class="account-info">
113146
<img src="data:image/png;base64, ${syncInfo.accountImage}" alt="Account avatar" />
@@ -116,6 +149,7 @@ function renderAccountInfoOrWarning(syncInfo: Host.InspectorFrontendHostAPI.Sync
116149
<span>${syncInfo.accountEmail}</span>
117150
</div>
118151
</div>`;
152+
// clang-format on
119153
}
120154

121155
customElements.define('devtools-sync-section', SyncSection);

front_end/panels/settings/components/syncSection.css

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
:host {
88
break-inside: avoid;
99
display: block;
10-
padding-bottom: 9px;
11-
width: 288px;
10+
width: 100%;
1211
}
1312

1413
fieldset {
1514
border: 0;
1615
padding: 0;
16+
padding: 4px 0 0;
1717
}
1818

1919
.link {
@@ -31,18 +31,27 @@ img {
3131
width: var(--sys-size-9);
3232
}
3333

34-
.warning {
35-
display: block;
36-
}
37-
3834
.account-info {
3935
display: flex;
4036
align-items: center;
41-
margin-top: 12px;
4237
}
4338

4439
.account-email {
4540
display: flex;
4641
flex-direction: column;
4742
margin-left: 8px;
4843
}
44+
45+
.not-signed-in {
46+
padding-bottom: 4px;
47+
}
48+
49+
.setting-checkbox-container {
50+
display: flex;
51+
align-items: center;
52+
gap: var(--sys-size-2);
53+
}
54+
55+
.setting-checkbox {
56+
display: inline-block;
57+
}

0 commit comments

Comments
 (0)