Skip to content

Commit 6470381

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
[GM3Restyling] Update network blocking request empty states
Before: https://i.imgur.com/2Me0vzH.png After: https://i.imgur.com/i3OuKr4.png Bug: 325443331 Change-Id: I473e959a63b16412e672b53a8ba76417f1488389 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6275932 Commit-Queue: Kim-Anh Tran <[email protected]> Reviewed-by: Kateryna Prokopenko <[email protected]>
1 parent 8fb6564 commit 6470381

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

front_end/panels/network/BlockedURLsPane.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as Platform from '../../core/platform/platform.js';
66
import * as SDK from '../../core/sdk/sdk.js';
77
import * as Logs from '../../models/logs/logs.js';
8+
import {dispatchClickEvent} from '../../testing/DOMHelpers.js';
89
import {createTarget, registerNoopActions} from '../../testing/EnvironmentHelpers.js';
910
import {describeWithMockConnection} from '../../testing/MockConnection.js';
1011

@@ -20,6 +21,31 @@ describeWithMockConnection('BlockedURLsPane', () => {
2021
]);
2122
});
2223

24+
it('shows a placeholder', () => {
25+
const blockedURLsPane = new Network.BlockedURLsPane.BlockedURLsPane();
26+
const blockedElement = blockedURLsPane.contentElement.querySelector('.blocked-urls');
27+
const placeholder = blockedElement?.shadowRoot?.querySelector('.empty-state');
28+
assert.exists(placeholder);
29+
assert.deepEqual(placeholder.querySelector('.empty-state-header')?.textContent, 'No blocked network requests');
30+
assert.deepEqual(
31+
placeholder.querySelector('.empty-state-description > span')?.textContent,
32+
'Add a pattern to block network requests by clicking on the \"Add pattern\" button.');
33+
});
34+
35+
it('Add pattern button triggers showing the editor view', () => {
36+
const blockedURLsPane = new Network.BlockedURLsPane.BlockedURLsPane();
37+
const blockedElement = blockedURLsPane.contentElement.querySelector('.blocked-urls');
38+
const list = blockedElement?.shadowRoot?.querySelector('.list');
39+
const placeholder = list?.querySelector('.empty-state');
40+
41+
const button = placeholder?.querySelector('devtools-button');
42+
assert.exists(button);
43+
44+
assert.isNull(list?.querySelector('.editor-content'));
45+
dispatchClickEvent(button);
46+
assert.exists(list?.querySelector('.editor-content'));
47+
});
48+
2349
describe('update', () => {
2450
const updatesOnRequestFinishedEvent = (inScope: boolean) => () => {
2551
const target = createTarget();

front_end/panels/network/BlockedURLsPane.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ const UIStrings = {
2929
*/
3030
addNetworkRequestBlockingPattern: 'Add network request blocking pattern',
3131
/**
32-
*@description Button to add a pattern to block netwrok requests in the Network request blocking tool
32+
*@description Text that shows in the network request blocking panel if no pattern has yet been added.
33+
*/
34+
noNetworkRequestsBlocked: 'No blocked network requests',
35+
/**
36+
*@description Text that shows in the network request blocking panel if no pattern has yet been added.
3337
*@example {Add pattern} PH1
3438
*/
35-
networkRequestsAreNotBlockedS: 'Network requests are not blocked. {PH1}',
39+
addPatternToBlock: 'Add a pattern to block network requests by clicking on the "{PH1}" button.',
3640
/**
3741
*@description Text in Blocked URLs Pane of the Network panel
3842
*@example {4} PH1
@@ -54,10 +58,17 @@ const UIStrings = {
5458
*@description Message to be announced for a when list item is removed from list widget
5559
*/
5660
itemDeleted: 'Item successfully deleted',
61+
/**
62+
*@description Message to be announced for a when list item is removed from list widget
63+
*/
64+
learnMore: 'Learn more',
5765
};
5866
const str_ = i18n.i18n.registerUIStrings('panels/network/BlockedURLsPane.ts', UIStrings);
5967
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
6068

69+
const NETWORK_REQUEST_BLOCKING_EXPLANATION_URL =
70+
'https://developer.chrome.com/docs/devtools/network-request-blocking' as Platform.DevToolsPath.UrlString;
71+
6172
export class BlockedURLsPane extends UI.Widget.VBox implements
6273
UI.ListWidget.Delegate<SDK.NetworkManager.BlockedPattern> {
6374
private manager: SDK.NetworkManager.MultitargetNetworkManager;
@@ -108,16 +119,24 @@ export class BlockedURLsPane extends UI.Widget.VBox implements
108119
}
109120

110121
private createEmptyPlaceholder(): Element {
111-
const element = this.contentElement.createChild('div', 'no-blocked-urls');
122+
const placeholder = this.contentElement.createChild('div', 'empty-state');
123+
placeholder.createChild('span', 'empty-state-header').textContent = i18nString(UIStrings.noNetworkRequestsBlocked);
124+
125+
const description = placeholder.createChild('div', 'empty-state-description');
126+
description.createChild('span').textContent =
127+
i18nString(UIStrings.addPatternToBlock, {PH1: i18nString(UIStrings.addPattern)});
128+
const link = UI.XLink.XLink.create(
129+
NETWORK_REQUEST_BLOCKING_EXPLANATION_URL, i18nString(UIStrings.learnMore), undefined, undefined, 'learn-more');
130+
description.appendChild(link);
131+
112132
const addButton = UI.UIUtils.createTextButton(i18nString(UIStrings.addPattern), this.addPattern.bind(this), {
113133
className: 'add-button',
114134
jslogContext: 'network.add-network-request-blocking-pattern',
115-
variant: Buttons.Button.Variant.PRIMARY,
135+
variant: Buttons.Button.Variant.TONAL,
116136
});
117137
UI.ARIAUtils.setLabel(addButton, i18nString(UIStrings.addNetworkRequestBlockingPattern));
118-
element.appendChild(
119-
i18n.i18n.getFormatLocalizedString(str_, UIStrings.networkRequestsAreNotBlockedS, {PH1: addButton}));
120-
return element;
138+
placeholder.appendChild(addButton);
139+
return placeholder;
121140
}
122141

123142
addPattern(): void {

front_end/panels/network/blockedURLsPane.css

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
.list {
88
border: none !important; /* stylelint-disable-line declaration-no-important */
99
border-top: 1px solid var(--sys-color-divider) !important; /* stylelint-disable-line declaration-no-important */
10+
display: flex;
11+
height: 100%;
1012
}
1113

1214
.blocking-disabled {
@@ -17,23 +19,10 @@
1719
padding: 0 4px;
1820
}
1921

20-
.no-blocked-urls,
2122
.blocked-urls {
2223
overflow: hidden auto;
2324
}
2425

25-
.no-blocked-urls {
26-
display: flex;
27-
justify-content: center;
28-
padding: 10px;
29-
30-
& devtools-button {
31-
display: flex;
32-
justify-content: center;
33-
margin-top: var(--sys-size-8);
34-
}
35-
}
36-
3726
.no-blocked-urls > span {
3827
white-space: pre;
3928
}

0 commit comments

Comments
 (0)