@@ -9,17 +9,14 @@ import { BugMeta } from "./types";
9
9
10
10
/**
11
11
* 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.
13
14
*/
14
15
@customElement ( "bug-label" )
15
16
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 [ ] = [ ] ;
23
20
24
21
static styles = css `
25
22
:host {
@@ -44,17 +41,34 @@ export class BugLabel extends LitElement {
44
41
}
45
42
` ;
46
43
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
+
48
62
return html `
49
63
< a
50
64
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 } "
52
66
target ="_blank "
53
67
rel ="noopener noreferrer "
54
- title =${ `Bug ${ this . bugMeta . id } : ${ this . bugMeta . summary } ` }
68
+ title =${ `Bug ${ bug . id } : ${ bug . summary } ` }
55
69
>
56
70
< img
57
- class ="bug-icon ${ ! this . bugMeta . isOpen ? "closed" : "" } "
71
+ class ="bug-icon ${ ! bug . isOpen ? "closed" : "" } "
58
72
src =${ bugzillaIcon }
59
73
alt ="Bugzilla Icon"
60
74
width="32"
@@ -63,4 +77,30 @@ export class BugLabel extends LitElement {
63
77
</ a >
64
78
` ;
65
79
}
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
+ }
66
106
}
0 commit comments