Skip to content

Commit 3aef625

Browse files
committed
Improve bug label for entries with many bugs.
The bug label now supports showing a single bug along with it's metadata or a list of bugs. The label will either link to the individual bug or a Bugzilla bug list.
1 parent 7d0ec52 commit 3aef625

File tree

3 files changed

+68
-27
lines changed

3 files changed

+68
-27
lines changed

src/app.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ async function fetchBugMetadata(bugIds: Set<string>): Promise<BugMetaMap> {
102102
};
103103
}
104104

105+
// For some bugs Bugzilla may not return data, e.g. because they are sec bugs.
106+
// In this case we still want to include the bug ID in the map, so it gets listed
107+
// but with placeholder values.
108+
for (let bugId of bugIds) {
109+
if (!bugMetaMap[bugId]) {
110+
bugMetaMap[bugId] = {
111+
id: bugId,
112+
isOpen: false,
113+
summary: "Unavailable",
114+
};
115+
}
116+
}
117+
105118
return bugMetaMap;
106119
}
107120

src/bug-label.ts

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ import { BugMeta } from "./types";
99

1010
/**
1111
* A component for displaying a bug label with a bugzilla icon.
12-
* The bug info is asynchronously fetched from the Bugzilla REST API.
12+
* If only a single bug is provided, it will display the bug's metadata along with a link to the bug.
13+
* If multiple bugs are provided, it will display a link to a Bugzilla bug list.
1314
*/
1415
@customElement("bug-label")
1516
export class BugLabel extends LitElement {
16-
// Holds all bug metadata to display.
17-
@property({ type: Object })
18-
bugMeta: BugMeta = {
19-
id: "",
20-
isOpen: true,
21-
summary: "",
22-
};
17+
// Holds either a single bug or a list of bugs to display.
18+
@property({ type: Array })
19+
bugMeta: BugMeta[] = [];
2320

2421
static styles = css`
2522
:host {
@@ -44,17 +41,34 @@ export class BugLabel extends LitElement {
4441
}
4542
`;
4643

47-
render() {
44+
/**
45+
* Get the URL for a Bugzilla bug list.
46+
* @param bugIds The bug IDs to get the URL for.
47+
* @returns The URL for the list of bugs.
48+
*/
49+
private getBugListUrl() {
50+
const url = new URL("https://bugzilla.mozilla.org/buglist.cgi");
51+
url.searchParams.set("bug_id", this.bugIds.join(","));
52+
return url.toString();
53+
}
54+
55+
private get bugIds() {
56+
return this.bugMeta.map((bug) => bug.id);
57+
}
58+
59+
private renderSingleBugLabel() {
60+
let bug = this.bugMeta[0];
61+
4862
return html`
4963
<a
5064
class="bug-label"
51-
href="https://bugzilla.mozilla.org/show_bug.cgi?id=${this.bugMeta.id}"
65+
href="https://bugzilla.mozilla.org/show_bug.cgi?id=${bug.id}"
5266
target="_blank"
5367
rel="noopener noreferrer"
54-
title=${`Bug ${this.bugMeta.id}: ${this.bugMeta.summary}`}
68+
title=${`Bug ${bug.id}: ${bug.summary}`}
5569
>
5670
<img
57-
class="bug-icon ${!this.bugMeta.isOpen ? "closed" : ""}"
71+
class="bug-icon ${!bug.isOpen ? "closed" : ""}"
5872
src=${bugzillaIcon}
5973
alt="Bugzilla Icon"
6074
width="32"
@@ -63,4 +77,30 @@ export class BugLabel extends LitElement {
6377
</a>
6478
`;
6579
}
80+
81+
private renderMultipleBugsLabel() {
82+
return html`
83+
<a
84+
class="bug-label"
85+
href=${this.getBugListUrl()}
86+
target="_blank"
87+
rel="noopener noreferrer"
88+
title=${`Bug ${this.bugIds.join(", ")}`}
89+
>
90+
<img class="bug-icon" src=${bugzillaIcon} alt="Bugzilla Icon" width="32" height="32" />
91+
</a>
92+
`;
93+
}
94+
95+
render() {
96+
if (this.bugMeta.length === 0) {
97+
return html``;
98+
}
99+
100+
if (this.bugMeta.length === 1) {
101+
return this.renderSingleBugLabel();
102+
} else {
103+
return this.renderMultipleBugsLabel();
104+
}
105+
}
66106
}

src/exceptions-table/exceptions-table.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,8 @@ export class ExceptionsTable extends LitElement {
115115
}
116116
}
117117

118-
/**
119-
* Renders a list of bug labels for an entry.
120-
* @param entry The entry to render the bug labels for.
121-
* @returns The rendered bug labels.
122-
*/
123-
private renderBugLabels(entry: ExceptionListEntry) {
124-
if (!Array.isArray(entry.bugIds) || entry.bugIds.length === 0) {
125-
return html``;
126-
}
127-
return html`<span class="badges"
128-
>${entry.bugIds.map(
129-
(bugId) => html`<bug-label .bugMeta=${this.bugMeta[bugId]}></bug-label>`,
130-
)}</span
131-
>`;
118+
private getBugMetaForEntry(entry: ExceptionListEntry) {
119+
return entry.bugIds.map((id) => this.bugMeta[id]).filter((meta) => meta != null);
132120
}
133121

134122
private renderTable() {
@@ -150,7 +138,7 @@ export class ExceptionsTable extends LitElement {
150138
(entry) => html`
151139
<tr>
152140
<td>
153-
<span class="badges"> ${this.renderBugLabels(entry)} </span>
141+
<bug-label .bugMeta=${this.getBugMetaForEntry(entry)}></bug-label>
154142
</td>
155143
<td class="${this.hasGlobalRules ? "" : "hidden-col"}">
156144
${renderUrlPattern(entry.topLevelUrlPattern)}

0 commit comments

Comments
 (0)