Skip to content

Commit 45572d7

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
Adopt UI eng vision in the HiddenIssuesRow
Fixed: 407751929 Change-Id: I4f71c59ebd4f92c8e65ba3a1684fb9bcf83b66ad Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6801798 Commit-Queue: Benedikt Meurer <[email protected]> Reviewed-by: Alex Rudenko <[email protected]>
1 parent 460272e commit 45572d7

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

front_end/panels/issues/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ devtools_module("issues") {
5252
"../../panels/console_counters:bundle",
5353
"../../panels/network/forward:bundle",
5454
"../../ui/components/adorners:bundle",
55+
"../../ui/components/buttons:bundle",
5556
"../../ui/components/linkifier:bundle",
5657
"../../ui/components/markdown_view:bundle",
5758
"../../ui/components/request_link_icon:bundle",
Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// Copyright 2021 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
/* eslint-disable rulesdir/no-imperative-dom-api */
4+
5+
import '../../ui/components/adorners/adorners.js';
56

67
import * as i18n from '../../core/i18n/i18n.js';
78
import * as IssuesManager from '../../models/issues_manager/issues_manager.js';
8-
import * as Adorners from '../../ui/components/adorners/adorners.js';
9+
import * as Buttons from '../../ui/components/buttons/buttons.js';
910
import * as UI from '../../ui/legacy/legacy.js';
11+
import {html, render} from '../../ui/lit/lit.js';
12+
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
1013

1114
const UIStrings = {
1215
/**
@@ -22,41 +25,64 @@ const UIStrings = {
2225
const str_ = i18n.i18n.registerUIStrings('panels/issues/HiddenIssuesRow.ts', UIStrings);
2326
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
2427

28+
interface ViewInput {
29+
count: number;
30+
onUnhideAllIssues: () => void;
31+
}
32+
33+
type ViewOutput = unknown;
34+
35+
type View = (input: ViewInput, output: ViewOutput, target: HTMLElement) => void;
36+
37+
const DEFAULT_VIEW: View = (input: ViewInput, _output: ViewOutput, target: HTMLElement): void => {
38+
const stopPropagationForEnter = (event: KeyboardEvent): void => {
39+
if (event.key === 'Enter') {
40+
// Make sure we don't propagate 'Enter' key events to parents,
41+
// so that these get turned into 'click' events properly. If we
42+
// don't stop the propagation here, the 'Enter' key down event
43+
// will be consumed by the tree element and it'll be expanded
44+
// or collapsed instead of the "Unhide all" action being taken.
45+
event.stopImmediatePropagation();
46+
}
47+
};
48+
49+
// clang-format off
50+
render(html`
51+
<div class="header">
52+
<devtools-adorner class="aggregated-issues-count"
53+
.data=${{name: 'countWrapper'}}>
54+
<span>${input.count}</span>
55+
</devtools-adorner>
56+
<div class="title">${i18nString(UIStrings.hiddenIssues)}</div>
57+
<devtools-button class="unhide-all-issues-button"
58+
jslog=${VisualLogging.action().track({click: true}).context('issues.unhide-all-hiddes')}
59+
@click=${input.onUnhideAllIssues}
60+
@keydown=${stopPropagationForEnter}
61+
.variant=${Buttons.Button.Variant.OUTLINED}>${i18nString(UIStrings.unhideAll)}</devtools-button>
62+
</div>`, target, {host: input});
63+
// clang-format on
64+
};
65+
2566
export class HiddenIssuesRow extends UI.TreeOutline.TreeElement {
26-
#numHiddenAggregatedIssues: HTMLElement;
67+
#view: View;
2768

28-
constructor() {
69+
constructor(view: View = DEFAULT_VIEW) {
2970
super(undefined, true);
30-
this.#numHiddenAggregatedIssues = document.createElement('span');
71+
this.#view = view;
3172
this.toggleOnClick = true;
3273
this.listItemElement.classList.add('issue-category', 'hidden-issues');
3374
this.childrenListElement.classList.add('hidden-issues-body');
34-
this.#appendHeader();
35-
}
36-
37-
#appendHeader(): void {
38-
const unhideAllIssuesBtn = UI.UIUtils.createTextButton(
39-
i18nString(UIStrings.unhideAll), () => IssuesManager.IssuesManager.IssuesManager.instance().unhideAllIssues(),
40-
{className: 'unhide-all-issues-button', jslogContext: 'issues.unhide-all-hiddes'});
41-
const countAdorner = new Adorners.Adorner.Adorner();
42-
countAdorner.data = {
43-
name: 'countWrapper',
44-
content: this.#numHiddenAggregatedIssues,
45-
};
46-
countAdorner.classList.add('aggregated-issues-count');
47-
this.#numHiddenAggregatedIssues.textContent = '0';
48-
const header = document.createElement('div');
49-
const title = document.createElement('div');
50-
header.classList.add('header');
51-
title.classList.add('title');
52-
title.textContent = i18nString(UIStrings.hiddenIssues);
53-
header.appendChild(countAdorner);
54-
header.appendChild(title);
55-
header.appendChild(unhideAllIssuesBtn);
56-
this.listItemElement.appendChild(header);
75+
this.update(0);
5776
}
5877

5978
update(count: number): void {
60-
this.#numHiddenAggregatedIssues.textContent = `${count}`;
79+
const issuesManager = IssuesManager.IssuesManager.IssuesManager.instance();
80+
const onUnhideAllIssues = issuesManager.unhideAllIssues.bind(issuesManager);
81+
const input = {
82+
count,
83+
onUnhideAllIssues,
84+
};
85+
const output = undefined;
86+
this.#view(input, output, this.listItemElement);
6187
}
6288
}

0 commit comments

Comments
 (0)