Skip to content

Commit 6af9930

Browse files
Piotr PaulskiDevtools-frontend LUCI CQ
authored andcommitted
Convert BounceTrackingMitigationsView to Widget
Finish fixing UI Engineering Vision violations in the component itself by replacing its base class and making adjustments to component creation in tests and parent component. Bug: 407749385 Change-Id: Idcc59847100d45c6661c687c40b3b38248a4f4f2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7228669 Commit-Queue: Piotr Paulski <[email protected]> Reviewed-by: Danil Somsikov <[email protected]>
1 parent 96f160e commit 6af9930

File tree

3 files changed

+42
-50
lines changed

3 files changed

+42
-50
lines changed

front_end/panels/application/BounceTrackingMitigationsTreeElement.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import * as Host from '../../core/host/host.js';
66
import * as i18n from '../../core/i18n/i18n.js';
77
import type * as Platform from '../../core/platform/platform.js';
8-
import * as LegacyWrapper from '../../ui/components/legacy_wrapper/legacy_wrapper.js';
98
import {createIcon} from '../../ui/kit/kit.js';
10-
import * as UI from '../../ui/legacy/legacy.js';
119

1210
import {ApplicationPanelTreeElement} from './ApplicationPanelTreeElement.js';
1311
import * as ApplicationComponents from './components/components.js';
@@ -23,8 +21,7 @@ const str_ = i18n.i18n.registerUIStrings('panels/application/BounceTrackingMitig
2321
export const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
2422

2523
export class BounceTrackingMitigationsTreeElement extends ApplicationPanelTreeElement {
26-
private view?: LegacyWrapper.LegacyWrapper.LegacyWrapper<
27-
UI.Widget.Widget, ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView>;
24+
private view?: ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView;
2825

2926
constructor(resourcesPanel: ResourcesPanel) {
3027
super(resourcesPanel, i18nString(UIStrings.bounceTrackingMitigations), false, 'bounce-tracking-mitigations');
@@ -39,8 +36,7 @@ export class BounceTrackingMitigationsTreeElement extends ApplicationPanelTreeEl
3936
override onselect(selectedByUser?: boolean): boolean {
4037
super.onselect(selectedByUser);
4138
if (!this.view) {
42-
this.view = LegacyWrapper.LegacyWrapper.legacyWrapper(
43-
UI.Widget.Widget, new ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView());
39+
this.view = new ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView();
4440
}
4541
this.showView(this.view);
4642
Host.userMetrics.panelShown('bounce-tracking-mitigations');

front_end/panels/application/components/BounceTrackingMitigationsView.test.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import * as ApplicationComponents from './components.js';
1919

2020
async function renderBounceTrackingMitigationsView():
2121
Promise<ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView> {
22-
const component = new ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView();
23-
component.style.display = 'block';
24-
component.style.width = '640px';
25-
component.style.height = '480px';
22+
const element = document.createElement('div');
23+
element.style.display = 'block';
24+
element.style.width = '640px';
25+
element.style.height = '480px';
26+
const component = new ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView(element);
2627
renderElementIntoDOM(component);
2728

29+
await component.updateComplete;
2830
// The data-grid's renderer is scheduled, so we need to wait until the coordinator
2931
// is done before we can test against it.
3032
await RenderCoordinator.done();
@@ -34,7 +36,7 @@ async function renderBounceTrackingMitigationsView():
3436

3537
function getInternalDataGridShadowRoot(
3638
component: ApplicationComponents.BounceTrackingMitigationsView.BounceTrackingMitigationsView): ShadowRoot {
37-
const dataGrid = component.shadowRoot!.querySelector('devtools-data-grid')!;
39+
const dataGrid = component.element.shadowRoot!.querySelector('devtools-data-grid')!;
3840
assert.isNotNull(dataGrid.shadowRoot);
3941
return dataGrid.shadowRoot;
4042
}
@@ -47,14 +49,14 @@ describeWithMockConnection('BounceTrackingMitigationsView', () => {
4749

4850
const component = await renderBounceTrackingMitigationsView();
4951
await RenderCoordinator.done();
50-
await component.wrapper?.updateComplete;
52+
await component.updateComplete;
5153

52-
const nullGridElement = component.shadowRoot!.querySelector('devtools-data-grid');
54+
const nullGridElement = component.element.shadowRoot!.querySelector('devtools-data-grid');
5355
assert.isNull(nullGridElement);
5456

5557
await assertScreenshot('application/bounce-tracking-mitigations-view-initial.png');
5658

57-
const sections = component.shadowRoot!.querySelectorAll('devtools-report-section');
59+
const sections = component.element.shadowRoot!.querySelectorAll('devtools-report-section');
5860
const sectionsText = Array.from(sections).map(section => section.textContent?.trim());
5961
const expected = [
6062
'Force run',
@@ -70,14 +72,14 @@ describeWithMockConnection('BounceTrackingMitigationsView', () => {
7072

7173
const component = await renderBounceTrackingMitigationsView();
7274
await RenderCoordinator.done();
73-
await component.wrapper?.updateComplete;
75+
await component.updateComplete;
7476

75-
const nullGridElement = component.shadowRoot!.querySelector('devtools-data-grid');
77+
const nullGridElement = component.element.shadowRoot!.querySelector('devtools-data-grid');
7678
assert.isNull(nullGridElement);
7779

7880
await assertScreenshot('application/bounce-tracking-mitigations-view-disabled.png');
7981

80-
const sections = component.shadowRoot!.querySelectorAll('devtools-report-section');
82+
const sections = component.element.shadowRoot!.querySelectorAll('devtools-report-section');
8183
const sectionsText = Array.from(sections).map(section => section.textContent?.trim());
8284
const expected = [
8385
'Bounce tracking mitigations are disabled.',
@@ -98,22 +100,22 @@ describeWithMockConnection('BounceTrackingMitigationsView', () => {
98100

99101
const component = await renderBounceTrackingMitigationsView();
100102
await RenderCoordinator.done();
101-
await component.wrapper?.updateComplete;
103+
await component.updateComplete;
102104

103-
const forceRunButton = component.shadowRoot!.querySelector('[aria-label="Force run"]');
105+
const forceRunButton = component.element.shadowRoot!.querySelector('[aria-label="Force run"]');
104106
assert.instanceOf(forceRunButton, HTMLElement);
105107
dispatchClickEvent(forceRunButton);
106108
await runBounceTrackingMitigationsPromise;
107109

108110
await RenderCoordinator.done();
109-
await component.wrapper?.updateComplete;
111+
await component.updateComplete;
110112

111113
await assertScreenshot('application/bounce-tracking-mitigations-view-empty.png');
112114

113-
const nullGridElement = component.shadowRoot!.querySelector('devtools-data-grid');
115+
const nullGridElement = component.element.shadowRoot!.querySelector('devtools-data-grid');
114116
assert.isNull(nullGridElement);
115117

116-
const sections = component.shadowRoot!.querySelectorAll('devtools-report-section');
118+
const sections = component.element.shadowRoot!.querySelectorAll('devtools-report-section');
117119
const sectionsText = Array.from(sections).map(section => section.textContent?.trim());
118120
const expected = [
119121
'Force run',
@@ -132,14 +134,14 @@ describeWithMockConnection('BounceTrackingMitigationsView', () => {
132134

133135
const component = await renderBounceTrackingMitigationsView();
134136
await RenderCoordinator.done();
135-
await component.wrapper?.updateComplete;
137+
await component.updateComplete;
136138

137-
const forceRunButton = component.shadowRoot!.querySelector('[aria-label="Force run"]');
139+
const forceRunButton = component.element.shadowRoot!.querySelector('[aria-label="Force run"]');
138140
assert.instanceOf(forceRunButton, HTMLElement);
139141
dispatchClickEvent(forceRunButton);
140142

141143
await RenderCoordinator.done({waitForWork: true});
142-
await component.wrapper?.updateComplete;
144+
await component.updateComplete;
143145

144146
await assertScreenshot('application/bounce-tracking-mitigations-view-populated.png');
145147

front_end/panels/application/components/BounceTrackingMitigationsView.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '../../../ui/legacy/components/data_grid/data_grid.js';
88
import * as i18n from '../../../core/i18n/i18n.js';
99
import * as SDK from '../../../core/sdk/sdk.js';
1010
import * as Buttons from '../../../ui/components/buttons/buttons.js';
11-
import * as LegacyWrapper from '../../../ui/components/legacy_wrapper/legacy_wrapper.js';
11+
import * as UI from '../../../ui/legacy/legacy.js';
1212
import * as Lit from '../../../ui/lit/lit.js';
1313
import * as VisualLogging from '../../../ui/visual_logging/visual_logging.js';
1414

@@ -166,7 +166,7 @@ const renderMainFrameInformation = (input: ViewInput): Lit.LitTemplate => {
166166
// clang-format on
167167
};
168168

169-
export const DEFAULT_VIEW = (input: ViewInput, _output: undefined, target: HTMLElement|ShadowRoot): void => {
169+
export const DEFAULT_VIEW = (input: ViewInput, _output: undefined, target: HTMLElement): void => {
170170
// clang-format off
171171
Lit.render(html`
172172
<style>${bounceTrackingMitigationsViewStyles}</style>
@@ -178,42 +178,44 @@ export const DEFAULT_VIEW = (input: ViewInput, _output: undefined, target: HTMLE
178178
// clang-format on
179179
};
180180

181-
export class BounceTrackingMitigationsView extends LegacyWrapper.LegacyWrapper.WrappableComponent {
182-
readonly #shadow = this.attachShadow({mode: 'open'});
181+
type ViewFunction = typeof DEFAULT_VIEW;
182+
183+
export class BounceTrackingMitigationsView extends UI.Widget.Widget {
183184
#trackingSites: string[] = [];
184185
#screenStatus = ScreenStatusType.INITIALIZING;
185186
#seenButtonClick = false;
187+
#view: ViewFunction;
188+
189+
constructor(element?: HTMLElement, view: ViewFunction = DEFAULT_VIEW) {
190+
super(element, {useShadowDom: true, classes: ['overflow-auto']});
186191

187-
constructor() {
188-
super();
192+
this.#view = view;
189193

190194
const mainTarget = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
191195
if (!mainTarget) {
192196
this.#screenStatus = ScreenStatusType.RESULT;
193197
} else {
194198
void mainTarget.systemInfo().invoke_getFeatureState({featureState: 'DIPS'}).then(state => {
195199
this.#screenStatus = state.featureEnabled ? ScreenStatusType.RESULT : ScreenStatusType.DISABLED;
196-
if (this.isConnected) {
197-
this.#render();
198-
}
200+
this.requestUpdate();
199201
});
200202
}
201203
}
202204

203-
connectedCallback(): void {
204-
void this.#render();
205-
this.parentElement?.classList.add('overflow-auto');
205+
override wasShown(): void {
206+
super.wasShown();
207+
this.requestUpdate();
206208
}
207209

208-
#render(): void {
209-
DEFAULT_VIEW(
210+
override performUpdate(): void {
211+
this.#view(
210212
{
211213
screenStatus: this.#screenStatus,
212214
trackingSites: this.#trackingSites,
213215
seenButtonClick: this.#seenButtonClick,
214216
runMitigations: this.#runMitigations.bind(this),
215217
},
216-
undefined, this.#shadow);
218+
undefined, this.contentElement);
217219
}
218220

219221
async #runMitigations(): Promise<void> {
@@ -225,7 +227,7 @@ export class BounceTrackingMitigationsView extends LegacyWrapper.LegacyWrapper.W
225227
this.#seenButtonClick = true;
226228
this.#screenStatus = ScreenStatusType.RUNNING;
227229

228-
void this.#render();
230+
this.requestUpdate();
229231

230232
const response = await mainTarget.storageAgent().invoke_runBounceTrackingMitigations();
231233
this.#trackingSites = [];
@@ -238,14 +240,6 @@ export class BounceTrackingMitigationsView extends LegacyWrapper.LegacyWrapper.W
238240

239241
#renderMitigationsResult(): void {
240242
this.#screenStatus = ScreenStatusType.RESULT;
241-
void this.#render();
242-
}
243-
}
244-
245-
customElements.define('devtools-bounce-tracking-mitigations-view', BounceTrackingMitigationsView);
246-
247-
declare global {
248-
interface HTMLElementTagNameMap {
249-
'devtools-bounce-tracking-mitigations-view': BounceTrackingMitigationsView;
243+
this.requestUpdate();
250244
}
251245
}

0 commit comments

Comments
 (0)