Skip to content

Commit d417160

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
[GM3Restyling] Update speculation rules empty states
Before: https://i.imgur.com/m9JsPn8.png After: https://i.imgur.com/AjqG9Fr.png Bug: 325443331 Change-Id: I27a1bb80cbb47c24ced72fdf138281ec5c9e8a5d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6285327 Reviewed-by: Kateryna Prokopenko <[email protected]> Commit-Queue: Kim-Anh Tran <[email protected]>
1 parent d8bde3a commit d417160

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

front_end/panels/application/preloading/components/RuleSetDetailsView.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
* found in the LICENSE file.
55
*/
66

7+
:host {
8+
display: block;
9+
height: 100%;
10+
}
11+
12+
.placeholder {
13+
display: flex;
14+
height: 100%;
15+
}
16+
717
.ruleset-header {
818
padding: 4px 8px;
919
white-space: nowrap;

front_end/panels/application/preloading/components/RuleSetDetailsView.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ async function renderRuleSetDetailsView(
2626
}
2727

2828
describeWithEnvironment('RuleSetDetailsView', () => {
29-
it('renders nothing if not selected', async () => {
29+
it('renders placeholder if not selected', async () => {
3030
const data = null;
3131

3232
const component = await renderRuleSetDetailsView(data, false);
3333
assert.isNotNull(component.shadowRoot);
34-
assert.strictEqual(component.shadowRoot.textContent, '');
34+
assert.exists(component.shadowRoot.querySelector('.empty-state'));
35+
36+
const header = component.shadowRoot.querySelector('.empty-state-header')?.textContent;
37+
const description = component.shadowRoot.querySelector('.empty-state-description')?.textContent;
38+
assert.deepEqual(header, 'No element selected');
39+
assert.deepEqual(description, 'Select an element for more details');
3540
});
3641

3742
it('renders rule set', async () => {

front_end/panels/application/preloading/components/RuleSetDetailsView.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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 * as i18n from '../../../../core/i18n/i18n.js';
56
import {assertNotNullOrUndefined} from '../../../../core/platform/platform.js';
67
import * as SDK from '../../../../core/sdk/sdk.js';
78
import type * as Protocol from '../../../../generated/protocol.js';
@@ -11,6 +12,8 @@ import * as CodeHighlighter from '../../../../ui/components/code_highlighter/cod
1112
import * as LegacyWrapper from '../../../../ui/components/legacy_wrapper/legacy_wrapper.js';
1213
import * as RenderCoordinator from '../../../../ui/components/render_coordinator/render_coordinator.js';
1314
import * as TextEditor from '../../../../ui/components/text_editor/text_editor.js';
15+
// eslint-disable-next-line rulesdir/es-modules-import
16+
import inspectorCommonStylesRaw from '../../../../ui/legacy/inspectorCommon.css.js';
1417
import type * as UI from '../../../../ui/legacy/legacy.js';
1518
import * as Lit from '../../../../ui/lit/lit.js';
1619

@@ -20,8 +23,29 @@ import ruleSetDetailsViewStylesRaw from './RuleSetDetailsView.css.js';
2023
const ruleSetDetailsViewStyles = new CSSStyleSheet();
2124
ruleSetDetailsViewStyles.replaceSync(ruleSetDetailsViewStylesRaw.cssContent);
2225

26+
// TODO(crbug.com/391381439): Fully migrate off of constructed style sheets.
27+
const inspectorCommonStyles = new CSSStyleSheet();
28+
inspectorCommonStyles.replaceSync(inspectorCommonStylesRaw.cssContent);
29+
2330
const {html} = Lit;
2431

32+
const UIStrings = {
33+
/**
34+
*@description Text in RuleSetDetailsView of the Application panel if no element is selected. An element here is an item in a
35+
* table of speculation rules. Speculation rules define the rules when and which urls should be prefetched.
36+
* https://developer.chrome.com/docs/devtools/application/debugging-speculation-rules
37+
*/
38+
noElementSelected: 'No element selected',
39+
/**
40+
*@description Text in RuleSetDetailsView of the Application panel if no element is selected. An element here is an item in a
41+
* table of speculation rules. Speculation rules define the rules when and which urls should be prefetched.
42+
* https://developer.chrome.com/docs/devtools/application/debugging-speculation-rules
43+
*/
44+
selectAnElementForMoreDetails: 'Select an element for more details',
45+
};
46+
const str_ = i18n.i18n.registerUIStrings('panels/application/preloading/components/RuleSetDetailsView.ts', UIStrings);
47+
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
48+
2549
type RuleSet = Protocol.Preload.RuleSet;
2650

2751
const codeMirrorJsonType = await CodeHighlighter.CodeHighlighter.languageFromMIME('application/json');
@@ -35,7 +59,7 @@ export class RuleSetDetailsView extends LegacyWrapper.LegacyWrapper.WrappableCom
3559
#editorState?: CodeMirror.EditorState;
3660

3761
connectedCallback(): void {
38-
this.#shadow.adoptedStyleSheets = [ruleSetDetailsViewStyles];
62+
this.#shadow.adoptedStyleSheets = [ruleSetDetailsViewStyles, inspectorCommonStyles];
3963
}
4064

4165
set data(data: RuleSetDetailsViewData) {
@@ -50,7 +74,17 @@ export class RuleSetDetailsView extends LegacyWrapper.LegacyWrapper.WrappableCom
5074
async #render(): Promise<void> {
5175
await RenderCoordinator.write('RuleSetDetailsView render', async () => {
5276
if (this.#data === null) {
53-
Lit.render(Lit.nothing, this.#shadow, {host: this});
77+
Lit.render(
78+
html`
79+
<div class="placeholder">
80+
<div class="empty-state">
81+
<span class="empty-state-header">${i18nString(UIStrings.noElementSelected)}</span>
82+
<span class="empty-state-description">${i18nString(UIStrings.selectAnElementForMoreDetails)}</span>
83+
</div>
84+
</div>
85+
`,
86+
this.#shadow, {host: this});
87+
// clang-format on
5488
return;
5589
}
5690

0 commit comments

Comments
 (0)