Skip to content

Commit 43cfc01

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Add native support of highlighted rows in the data grid and use it in the cookies table
Bug: 394287937 Change-Id: Ia6627aee14b7959e12f9d3ce4bcb1cd835dcd116 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6280733 Commit-Queue: Benedikt Meurer <[email protected]> Auto-Submit: Danil Somsikov <[email protected]> Commit-Queue: Danil Somsikov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent 0d1ecc7 commit 43cfc01

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

front_end/ui/legacy/components/cookie_table/CookiesTable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type CookieData = {
8080
inactive?: boolean,
8181
};
8282

83-
const {classMap, repeat, ifDefined} = Directives;
83+
const {repeat, ifDefined} = Directives;
8484

8585
const UIStrings = {
8686
/**
@@ -241,7 +241,7 @@ export class CookiesTable extends UI.Widget.VBox {
241241
?selected=${cookie.key === input.selectedKey}
242242
?inactive=${cookie.inactive}
243243
?dirty=${cookie.dirty}
244-
class=${classMap({'flagged-cookie-attribute-row': Boolean(cookie.flagged)})}>
244+
?highlighted=${cookie.flagged}>
245245
<td>
246246
${cookie.icons?.name}
247247
${cookie.name}

front_end/ui/legacy/components/cookie_table/cookiesTable.css

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,4 @@
1010

1111
.cookies-table devtools-icon {
1212
margin-right: 4px;
13-
}
14-
15-
.cookies-table tr.revealed.data-grid-data-grid-node.flagged-cookie-attribute-row:not(.selected):nth-child(odd) {
16-
background-color: var(--sys-color-surface-yellow-high);
17-
}
18-
19-
.cookies-table tr.revealed.data-grid-data-grid-node.flagged-cookie-attribute-row:not(.selected):nth-child(even) {
20-
background-color: var(--sys-color-surface-yellow);
21-
}
13+
}

front_end/ui/legacy/components/data_grid/DataGrid.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,7 @@ export class DataGridNode<T> {
16981698
private selectedInternal: boolean;
16991699
private dirty: boolean;
17001700
private inactive: boolean;
1701+
private highlighted: boolean;
17011702
private depthInternal!: number|undefined;
17021703
revealedInternal!: boolean|undefined;
17031704
protected attachedInternal: boolean;
@@ -1726,6 +1727,7 @@ export class DataGridNode<T> {
17261727
this.selectedInternal = false;
17271728
this.dirty = false;
17281729
this.inactive = false;
1730+
this.highlighted = false;
17291731
this.attachedInternal = false;
17301732
this.savedPosition = null;
17311733
this.shouldRefreshChildrenInternal = true;
@@ -1781,6 +1783,9 @@ export class DataGridNode<T> {
17811783
if (this.inactive) {
17821784
this.elementInternal.classList.add('inactive');
17831785
}
1786+
if (this.highlighted) {
1787+
this.elementInternal.classList.add('highlighted');
1788+
}
17841789
if (this.isCreationNode) {
17851790
this.elementInternal.classList.add('creation-node');
17861791
}
@@ -1902,6 +1907,21 @@ export class DataGridNode<T> {
19021907
}
19031908
}
19041909

1910+
setHighlighted(highlighted: boolean): void {
1911+
if (this.highlighted === highlighted) {
1912+
return;
1913+
}
1914+
this.highlighted = highlighted;
1915+
if (!this.elementInternal) {
1916+
return;
1917+
}
1918+
if (highlighted) {
1919+
this.elementInternal.classList.add('highlighted');
1920+
} else {
1921+
this.elementInternal.classList.remove('highlighted');
1922+
}
1923+
}
1924+
19051925
hasChildren(): boolean {
19061926
return this.hasChildrenInternal;
19071927
}

front_end/ui/legacy/components/data_grid/DataGridElement.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ class DataGridElement extends HTMLElement {
257257
if (hasBooleanAttribute(element, 'selected')) {
258258
node.select();
259259
}
260+
if (hasBooleanAttribute(element, 'dirty')) {
261+
node.setDirty(true);
262+
}
263+
if (hasBooleanAttribute(element, 'inactive')) {
264+
node.setInactive(true);
265+
}
266+
if (hasBooleanAttribute(element, 'highlighted')) {
267+
node.setHighlighted(true);
268+
}
260269
}
261270
}
262271

@@ -282,7 +291,9 @@ class DataGridElement extends HTMLElement {
282291
} else if (attributeName === 'dirty') {
283292
dataGridNode.setDirty(hasBooleanAttribute(dataRow, 'dirty'));
284293
} else if (attributeName === 'inactive') {
285-
dataGridNode.setDirty(hasBooleanAttribute(dataRow, 'inactive'));
294+
dataGridNode.setInactive(hasBooleanAttribute(dataRow, 'inactive'));
295+
} else if (attributeName === 'highlighted') {
296+
dataGridNode.setHighlighted(hasBooleanAttribute(dataRow, 'highlighted'));
286297
} else {
287298
dataGridNode.refresh();
288299
}
@@ -400,6 +411,9 @@ class DataGridElementNode extends SortableDataGridNode<DataGridElementNode> {
400411
if (this.#configElement.hasAttribute('style')) {
401412
element.setAttribute('style', this.#configElement.getAttribute('style') || '');
402413
}
414+
for (const classToAdd of this.#configElement.classList) {
415+
element.classList.add(classToAdd);
416+
}
403417
return element;
404418
}
405419

front_end/ui/legacy/components/data_grid/dataGrid.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@
288288
font-style: normal;
289289
}
290290

291+
.data-grid tr.highlighted:not(.selected) {
292+
background-color: var(--sys-color-surface-yellow);
293+
}
294+
295+
.striped-data-grid .revealed.data-grid-data-grid-node.highlighted:nth-child(odd):not(.dirty, .selected),
296+
.striped-data-grid-starts-with-odd .revealed.data-grid-data-grid-node.highlighted:nth-child(even):not(.dirty, .selected) {
297+
background-color: var(--sys-color-surface-yellow-high);
298+
}
299+
291300
.data-grid td.show-more {
292301
white-space: normal;
293302
gap: var(--sys-size-3);

0 commit comments

Comments
 (0)