Skip to content

Commit 7c441bc

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Use <devtools-new-data-grid> in the InterestGroupAccessGrid
Bug: 390346490 Change-Id: Id523796fc92d369e2f3c2b1e07a46aaaa4788e8a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6195172 Commit-Queue: Danil Somsikov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent 02ab38d commit 7c441bc

File tree

5 files changed

+35
-117
lines changed

5 files changed

+35
-117
lines changed

front_end/panels/application/InterestGroupStorageView.test.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as Protocol from '../../generated/protocol.js';
66
import {raf} from '../../testing/DOMHelpers.js';
77
import {expectCall} from '../../testing/ExpectStubCall.js';
88
import {describeWithMockConnection} from '../../testing/MockConnection.js';
9-
import * as DataGrid from '../../ui/components/data_grid/data_grid.js';
109

1110
import * as Resources from './application.js';
1211

@@ -84,16 +83,9 @@ describeWithMockConnection('InterestGroupStorageView', () => {
8483
view.addEvent(event);
8584
});
8685
const grid = view.getInterestGroupGridForTesting();
87-
const cells = [
88-
{columnId: 'event-time', value: 0},
89-
{columnId: 'event-type', value: Protocol.Storage.InterestGroupAccessType.Join},
90-
{columnId: 'event-group-owner', value: 'https://owner1.com'},
91-
{columnId: 'event-group-name', value: 'cars'},
92-
];
9386
const spy = sinon.spy(view, 'setSidebarWidget');
9487
assert.isTrue(spy.notCalled);
95-
grid.dispatchEvent(
96-
new DataGrid.DataGridEvents.BodyCellFocusedEvent({columnId: 'event-time', value: '0'}, {cells}));
88+
grid.dispatchEvent(new CustomEvent('select', {detail: events[0]}));
9789
await raf();
9890
assert.isTrue(spy.calledOnce);
9991
assert.deepEqual(view.sidebarWidget()?.constructor.name, 'SearchableView');
@@ -113,17 +105,10 @@ describeWithMockConnection('InterestGroupStorageView', () => {
113105
view.addEvent(event);
114106
});
115107
const grid = view.getInterestGroupGridForTesting();
116-
const cells = [
117-
{columnId: 'event-time', value: 0},
118-
{columnId: 'event-type', value: eventType},
119-
{columnId: 'event-group-owner', value: 'https://owner1.com'},
120-
{columnId: 'event-group-name', value: 'cars'},
121-
];
122108
const sideBarUpdateDone = expectCall(sinon.stub(view, 'sidebarUpdatedForTesting'));
123109
const spy = sinon.spy(view, 'setSidebarWidget');
124110
assert.isTrue(spy.notCalled);
125-
grid.dispatchEvent(
126-
new DataGrid.DataGridEvents.BodyCellFocusedEvent({columnId: 'event-time', value: '0'}, {cells}));
111+
grid.dispatchEvent(new CustomEvent('select', {detail: {...events[0], type: eventType}}));
127112
await sideBarUpdateDone;
128113
assert.isTrue(spy.calledOnce);
129114
assert.notDeepEqual(view.sidebarWidget()?.constructor.name, 'SearchableView');
@@ -144,16 +129,9 @@ describeWithMockConnection('InterestGroupStorageView', () => {
144129
view.addEvent(event);
145130
});
146131
const grid = view.getInterestGroupGridForTesting();
147-
const cells = [
148-
{columnId: 'event-time', value: 0},
149-
{columnId: 'event-type', value: Protocol.Storage.InterestGroupAccessType.Join},
150-
{columnId: 'event-group-owner', value: 'https://owner1.com'},
151-
{columnId: 'event-group-name', value: 'cars'},
152-
];
153132
const spy = sinon.spy(view, 'setSidebarWidget');
154133
assert.isTrue(spy.notCalled);
155-
grid.dispatchEvent(
156-
new DataGrid.DataGridEvents.BodyCellFocusedEvent({columnId: 'event-time', value: '0'}, {cells}));
134+
grid.dispatchEvent(new CustomEvent('select', {detail: events[0]}));
157135
await raf();
158136
assert.isTrue(spy.calledOnce);
159137
assert.notDeepEqual(view.sidebarWidget()?.constructor.name, 'SearchableView');
@@ -171,15 +149,9 @@ describeWithMockConnection('InterestGroupStorageView', () => {
171149
view.addEvent(event);
172150
});
173151
const grid = view.getInterestGroupGridForTesting();
174-
const cells = [
175-
{columnId: 'event-time', value: 0},
176-
{columnId: 'event-type', value: Protocol.Storage.InterestGroupAccessType.Join},
177-
{columnId: 'event-group-owner', value: 'https://owner1.com'},
178-
{columnId: 'event-group-name', value: 'cars'},
179-
];
180152
const spy = sinon.spy(view, 'setSidebarWidget');
181153
assert.isTrue(spy.notCalled);
182-
grid.dispatchEvent(new DataGrid.DataGridEvents.BodyCellFocusedEvent({columnId: 'event-time', value: '0'}, {cells}));
154+
grid.dispatchEvent(new CustomEvent('select', {detail: events[0]}));
183155
await raf();
184156
assert.isTrue(spy.calledOnce);
185157
assert.deepEqual(view.sidebarWidget()?.constructor.name, 'SearchableView');

front_end/panels/application/InterestGroupStorageView.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as i18n from '../../core/i18n/i18n.js';
66
import * as Protocol from '../../generated/protocol.js';
7-
import type * as DataGrid from '../../ui/components/data_grid/data_grid.js';
87
import * as SourceFrame from '../../ui/legacy/components/source_frame/source_frame.js';
98
import * as UI from '../../ui/legacy/legacy.js';
109
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
@@ -59,7 +58,7 @@ export class InterestGroupStorageView extends UI.SplitWidget.SplitWidget {
5958
this.noDataView.setMinimumSize(0, 40);
6059

6160
topPanel.contentElement.appendChild(this.interestGroupGrid);
62-
this.interestGroupGrid.addEventListener('cellfocused', this.onFocus.bind(this));
61+
this.interestGroupGrid.addEventListener('select', this.onFocus.bind(this));
6362

6463
this.noDisplayView.contentElement.classList.add('placeholder');
6564
this.noDisplayView.contentElement.setAttribute('jslog', `${VisualLogging.pane('details').track({resize: true})}`);
@@ -97,19 +96,8 @@ export class InterestGroupStorageView extends UI.SplitWidget.SplitWidget {
9796
}
9897

9998
private async onFocus(event: Event): Promise<void> {
100-
const focusedEvent = event as DataGrid.DataGridEvents.BodyCellFocusedEvent;
101-
const row = focusedEvent.data.row;
102-
if (!row) {
103-
return;
104-
}
105-
106-
const ownerOrigin = row.cells.find(cell => cell.columnId === 'event-group-owner')?.value as string;
107-
const name = row.cells.find(cell => cell.columnId === 'event-group-name')?.value as string;
108-
const eventType =
109-
row.cells.find(cell => cell.columnId === 'event-type')?.value as Protocol.Storage.InterestGroupAccessType;
110-
if (!ownerOrigin || !name) {
111-
return;
112-
}
99+
const focusedEvent = event as CustomEvent<Protocol.Storage.InterestGroupAccessedEvent>;
100+
const {ownerOrigin, name, type: eventType} = focusedEvent.detail;
113101

114102
let details = null;
115103
// Details of additional bids can't be looked up like regular bids,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import * as Protocol from '../../../generated/protocol.js';
66
import {getValuesOfAllBodyRows} from '../../../testing/DataGridHelpers.js';
77
import {
8-
getElementWithinComponent,
98
renderElementIntoDOM,
109
} from '../../../testing/DOMHelpers.js';
1110
import {describeWithLocale} from '../../../testing/EnvironmentHelpers.js';
12-
import * as DataGrid from '../../../ui/components/data_grid/data_grid.js';
1311
import * as RenderCoordinator from '../../../ui/components/render_coordinator/render_coordinator.js';
1412

1513
import * as ApplicationComponents from './components.js';
@@ -29,9 +27,7 @@ async function renderInterestGroupAccessGrid(events: Protocol.Storage.InterestGr
2927

3028
function getInternalDataGridShadowRoot(
3129
component: ApplicationComponents.InterestGroupAccessGrid.InterestGroupAccessGrid): ShadowRoot {
32-
const dataGridController = getElementWithinComponent(
33-
component, 'devtools-data-grid-controller', DataGrid.DataGridController.DataGridController);
34-
const dataGrid = getElementWithinComponent(dataGridController, 'devtools-data-grid', DataGrid.DataGrid.DataGrid);
30+
const dataGrid = component.shadowRoot!.querySelector('devtools-new-data-grid')!;
3531
assert.isNotNull(dataGrid.shadowRoot);
3632
return dataGrid.shadowRoot;
3733
}
@@ -65,7 +61,7 @@ describeWithLocale('InterestGroupAccessGrid', () => {
6561
it('hides interest group event table when there are no events', async () => {
6662
const component = await renderInterestGroupAccessGrid([]);
6763

68-
const nullGridElement = component.shadowRoot!.querySelector('devtools-data-grid-controller');
64+
const nullGridElement = component.shadowRoot!.querySelector('devtools-new-data-grid');
6965
assert.isNull(nullGridElement);
7066

7167
const noEventsElement = component.shadowRoot!.querySelector('div.no-events-message');

front_end/panels/application/components/InterestGroupAccessGrid.ts

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
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 '../../../ui/legacy/components/data_grid/data_grid.js';
6+
57
import * as i18n from '../../../core/i18n/i18n.js';
68
import type * as Protocol from '../../../generated/protocol.js';
7-
import * as DataGrid from '../../../ui/components/data_grid/data_grid.js';
89
import * as LitHtml from '../../../ui/lit-html/lit-html.js';
910

1011
import interestGroupAccessGridStyles from './interestGroupAccessGrid.css.js';
@@ -85,71 +86,32 @@ export class InterestGroupAccessGrid extends HTMLElement {
8586
return html`<div class="no-events-message">${i18nString(UIStrings.noEvents)}</div>`;
8687
}
8788

88-
const gridData: DataGrid.DataGridController.DataGridControllerData = {
89-
columns: [
90-
{
91-
id: 'event-time',
92-
title: i18nString(UIStrings.eventTime),
93-
widthWeighting: 10,
94-
hideable: false,
95-
visible: true,
96-
sortable: true,
97-
},
98-
{
99-
id: 'event-type',
100-
title: i18nString(UIStrings.eventType),
101-
widthWeighting: 5,
102-
hideable: false,
103-
visible: true,
104-
sortable: true,
105-
},
106-
{
107-
id: 'event-group-owner',
108-
title: i18nString(UIStrings.groupOwner),
109-
widthWeighting: 10,
110-
hideable: false,
111-
visible: true,
112-
sortable: true,
113-
},
114-
{
115-
id: 'event-group-name',
116-
title: i18nString(UIStrings.groupName),
117-
widthWeighting: 10,
118-
hideable: false,
119-
visible: true,
120-
sortable: true,
121-
},
122-
],
123-
rows: this.#buildRows(),
124-
initialSort: {
125-
columnId: 'event-time',
126-
direction: DataGrid.DataGridUtils.SortDirection.ASC,
127-
},
128-
};
129-
13089
return html`
131-
<devtools-data-grid-controller .data=${gridData}></devtools-data-grid-controller>
90+
<devtools-new-data-grid @select=${this.#onSelect}>
91+
<table>
92+
<tr>
93+
<th id="event-time" sortable weight="10">${i18nString(UIStrings.eventTime)}</td>
94+
<th id="event-type" sortable weight="5">${i18nString(UIStrings.eventType)}</td>
95+
<th id="event-group-owner" sortable weight="10">${i18nString(UIStrings.groupOwner)}</td>
96+
<th id="event-group-name" sortable weight="10">${i18nString(UIStrings.groupName)}</td>
97+
</tr>
98+
${this.#datastores.map((event, index) => html`
99+
<tr data-index=${index}>
100+
<td>${new Date(1e3 * event.accessTime).toLocaleString()}</td>
101+
<td>${event.type}</td>
102+
<td>${event.ownerOrigin}</td>
103+
<td>${event.name}</td>
104+
</tr>
105+
`)}
106+
</table>
107+
</devtools-new-data-grid>
132108
`;
133109
}
134110

135-
#buildRows(): DataGrid.DataGridUtils.Row[] {
136-
return this.#datastores.map(event => ({
137-
cells: [
138-
{
139-
columnId: 'event-time',
140-
value: event.accessTime,
141-
renderer: this.#renderDateForDataGridCell.bind(this),
142-
},
143-
{columnId: 'event-type', value: event.type},
144-
{columnId: 'event-group-owner', value: event.ownerOrigin},
145-
{columnId: 'event-group-name', value: event.name},
146-
],
147-
}));
148-
}
149-
150-
#renderDateForDataGridCell(value: DataGrid.DataGridUtils.CellValue): LitHtml.TemplateResult {
151-
const date = new Date(1e3 * (value as number));
152-
return html`${date.toLocaleString()}`;
111+
#onSelect(event: CustomEvent<HTMLElement|null>): void {
112+
if (event.detail) {
113+
this.dispatchEvent(new CustomEvent('select', {detail: this.#datastores[Number(event.detail.dataset.index)]}));
114+
}
153115
}
154116
}
155117

front_end/panels/application/components/interestGroupAccessGrid.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
font-size: 15px;
1212
}
1313

14-
devtools-data-grid-controller {
15-
border: 1px solid var(--sys-color-divider);
14+
devtools-new-data-grid {
1615
margin-top: 20px;
16+
height: 200px;
1717
}
1818

1919
.info-icon {

0 commit comments

Comments
 (0)