Skip to content

Commit 1c1db39

Browse files
masnobleDevtools-frontend LUCI CQ
authored andcommitted
Fix NamedBitSetFilterUIElement behavior
Before, updating the options of an existing element would not be reflected since the underlying object was never updated. Now, the underlying object is invalidated if the options have changed and will thus return properly updated filters. Bug:b/391610376 Change-Id: If32dfb52c93bae7b839292467138e92b2029d057 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6195967 Reviewed-by: Danil Somsikov <[email protected]> Reviewed-by: Shuran Huang <[email protected]> Commit-Queue: Joshua Thomas <[email protected]>
1 parent 16c7df4 commit 1c1db39

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

front_end/panels/security/CookieReportView.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
186186

187187
export interface ViewInput {
188188
gridData: DataGrid.DataGrid.DataGridNode<CookieReportNodeData>[];
189+
filterItems: UI.FilterBar.Item[];
189190
onFilterChanged: () => void;
190191
onSortingChanged: () => void;
191192
populateContextMenu:
@@ -214,6 +215,7 @@ export class CookieReportView extends UI.Widget.VBox {
214215
#view: View;
215216
dataGrid?: DataGrid.DataGrid.DataGridImpl<CookieReportNodeData>;
216217
gridData: DataGrid.DataGrid.DataGridNode<CookieReportNodeData>[] = [];
218+
filterItems: UI.FilterBar.Item[] = [];
217219

218220
constructor(element?: HTMLElement, view: View = (input, output, target) => {
219221
const dataGridOptions: DataGrid.DataGrid.DataGridWidgetOptions<CookieReportNodeData> = {
@@ -231,33 +233,6 @@ export class CookieReportView extends UI.Widget.VBox {
231233
rowContextMenuCallback: input.populateContextMenu.bind(input),
232234
};
233235

234-
const filterItems: UI.FilterBar.Item[] = [];
235-
236-
if (input.gridData.some(n => n.data['status'] === i18nString(UIStrings.blocked))) {
237-
filterItems.push({
238-
name: UIStrings.blocked,
239-
label: () => i18nString(UIStrings.blocked),
240-
title: UIStrings.blocked,
241-
jslogContext: UIStrings.blocked,
242-
});
243-
}
244-
if (input.gridData.some(n => n.data['status'] === i18nString(UIStrings.allowed))) {
245-
filterItems.push({
246-
name: UIStrings.allowed,
247-
label: () => i18nString(UIStrings.allowed),
248-
title: UIStrings.allowed,
249-
jslogContext: UIStrings.allowed,
250-
});
251-
}
252-
if (input.gridData.some(n => n.data['status'] === i18nString(UIStrings.allowedByException))) {
253-
filterItems.push({
254-
name: UIStrings.allowedByException,
255-
label: () => i18nString(UIStrings.allowedByException),
256-
title: UIStrings.allowedByException,
257-
jslogContext: UIStrings.allowedByException,
258-
});
259-
}
260-
261236
// clang-format off
262237
render(html `
263238
<div class="report overflow-auto">
@@ -270,7 +245,7 @@ export class CookieReportView extends UI.Widget.VBox {
270245
<devtools-named-bit-set-filter
271246
class="filter"
272247
@filterChanged=${input.onFilterChanged}
273-
.options=${{items: filterItems}}
248+
.options=${{items: input.filterItems}}
274249
${ref((el?: Element) => {
275250
if(el instanceof UI.FilterBar.NamedBitSetFilterUIElement){
276251
output.namedBitSetFilterUI = el.getOrCreateNamedBitSetFilterUI();
@@ -327,6 +302,7 @@ export class CookieReportView extends UI.Widget.VBox {
327302

328303
override performUpdate(): void {
329304
this.gridData = this.#buildNodes();
305+
this.filterItems = this.#buildFilterItems();
330306
this.#view(this, this, this.contentElement);
331307
}
332308

@@ -361,6 +337,39 @@ export class CookieReportView extends UI.Widget.VBox {
361337
}
362338
}
363339

340+
#buildFilterItems(): UI.FilterBar.Item[] {
341+
const filterItems: UI.FilterBar.Item[] = [];
342+
343+
if (this.#cookieRows.values().some(n => n.status === IssuesManager.CookieIssue.CookieStatus.BLOCKED)) {
344+
filterItems.push({
345+
name: UIStrings.blocked,
346+
label: () => i18nString(UIStrings.blocked),
347+
title: UIStrings.blocked,
348+
jslogContext: UIStrings.blocked,
349+
});
350+
}
351+
if (this.#cookieRows.values().some(n => n.status === IssuesManager.CookieIssue.CookieStatus.ALLOWED)) {
352+
filterItems.push({
353+
name: UIStrings.allowed,
354+
label: () => i18nString(UIStrings.allowed),
355+
title: UIStrings.allowed,
356+
jslogContext: UIStrings.allowed,
357+
});
358+
}
359+
if (this.#cookieRows.values().some(
360+
n => n.status === IssuesManager.CookieIssue.CookieStatus.ALLOWED_BY_GRACE_PERIOD ||
361+
n.status === IssuesManager.CookieIssue.CookieStatus.ALLOWED_BY_HEURISTICS)) {
362+
filterItems.push({
363+
name: UIStrings.allowedByException,
364+
label: () => i18nString(UIStrings.allowedByException),
365+
title: UIStrings.allowedByException,
366+
jslogContext: UIStrings.allowedByException,
367+
});
368+
}
369+
370+
return filterItems;
371+
}
372+
364373
#buildNodes(): DataGrid.DataGrid.DataGridNode<CookieReportNodeData>[] {
365374
return [...this.#cookieRows.values()]
366375
.filter(row => {

front_end/ui/legacy/FilterBar.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,15 @@ export class NamedBitSetFilterUIElement extends HTMLElement {
279279
#namedBitSetFilterUI?: NamedBitSetFilterUI;
280280

281281
set options(options: NamedBitSetFilterUIOptions) {
282+
// return if they are the same
283+
if (this.#options.items.toString() === options.items.toString() && this.#options.setting === options.setting) {
284+
return;
285+
}
286+
282287
this.#options = options;
288+
// When options are updated, clear the UI so that a new one is created with the new options
289+
this.#shadow.innerHTML = '';
290+
this.#namedBitSetFilterUI = undefined;
283291
}
284292

285293
getOrCreateNamedBitSetFilterUI(): NamedBitSetFilterUI {

0 commit comments

Comments
 (0)