@@ -23,17 +23,21 @@ export class ExceptionsTable extends LitElement {
23
23
@property ( { attribute : false } )
24
24
filter : ( entry : ExceptionListEntry ) => boolean = ( ) => true ;
25
25
26
- // An optional array of entry fields to display.
27
- @property ( { type : Array } )
28
- filterFields : ( keyof ExceptionListEntry ) [ ] = [
29
- "bugIds" ,
30
- "category" ,
31
- "urlPattern" ,
32
- "classifierFeatures" ,
33
- "topLevelUrlPattern" ,
34
- "isPrivateBrowsingOnly" ,
35
- "filterContentBlockingCategories" ,
36
- ] ;
26
+ /**
27
+ * The filtered entries to display.
28
+ * @returns The filtered entries.
29
+ */
30
+ get filteredEntries ( ) : ExceptionListEntry [ ] {
31
+ return this . entries . filter ( this . filter ) ;
32
+ }
33
+
34
+ /**
35
+ * Determines if the table has global rules.
36
+ * @returns True if the table has global rules, false otherwise.
37
+ */
38
+ get hasGlobalRules ( ) : boolean {
39
+ return this . filteredEntries . some ( ( entry ) => entry . topLevelUrlPattern ?. length ) ;
40
+ }
37
41
38
42
static styles = css `
39
43
.table-container {
@@ -76,25 +80,13 @@ export class ExceptionsTable extends LitElement {
76
80
.hidden-col {
77
81
display: none;
78
82
}
79
- .show-col {
80
- display: table-cell;
81
- }
82
83
.badges {
83
84
display: flex;
84
85
flex-wrap: wrap;
85
86
gap: 0.3em;
86
87
}
87
88
` ;
88
89
89
- /**
90
- * Determines if a field should be shown based on the filterFields property.
91
- * @param field The field to check.
92
- * @returns The CSS class to apply to the field.
93
- */
94
- private getVisibilityClass ( field : keyof ExceptionListEntry ) : string {
95
- return this . filterFields . includes ( field ) ? "show-col" : "hidden-col" ;
96
- }
97
-
98
90
/**
99
91
* Capitalizes the first character of a string.
100
92
* @param str The string to capitalize.
@@ -109,21 +101,52 @@ export class ExceptionsTable extends LitElement {
109
101
* @param categories The categories to render.
110
102
* @returns The rendered badges.
111
103
*/
112
- private renderETPBadges ( categories ?: ( "standard" | "strict" | "custom" ) [ ] ) {
104
+ private renderETPBadges ( entry : ExceptionListEntry ) {
105
+ let categories = entry . filterContentBlockingCategories ;
106
+
113
107
if ( ! Array . isArray ( categories ) || categories . length === 0 ) {
114
- return html `< ui-badge type =" all " > All </ ui-badge > ` ;
108
+ return html `` ;
115
109
}
116
110
return html `
117
111
< span class ="badges ">
118
112
${ categories . map (
119
- ( cat ) => html `
120
- < ui-badge type ="etp " value ="${ cat } "> ${ this . capitalizeFirstChar ( cat ) } </ ui-badge >
121
- ` ,
113
+ ( cat ) => html ` < ui-badge type ="etp "> ETP-${ this . capitalizeFirstChar ( cat ) } </ ui-badge > ` ,
122
114
) }
123
115
</ span >
124
116
` ;
125
117
}
126
118
119
+ /**
120
+ * Renders the filters for an entry in a badge list.
121
+ * @param entry The entry to render the filters for.
122
+ * @returns The rendered filters.
123
+ */
124
+ private renderFilters ( entry : ExceptionListEntry ) {
125
+ const hasETPFilter =
126
+ Array . isArray ( entry . filterContentBlockingCategories ) &&
127
+ entry . filterContentBlockingCategories . length > 0 ;
128
+ const hasFilterExpression = ! ! entry . filter_expression ;
129
+ const hasPBMFilter = entry . isPrivateBrowsingOnly != null ;
130
+
131
+ if ( ! hasETPFilter && ! hasFilterExpression && ! hasPBMFilter ) {
132
+ return html `< span class ="badges "> -</ span > ` ;
133
+ }
134
+
135
+ return html `
136
+ < span class ="badges ">
137
+ ${ this . renderETPBadges ( entry ) }
138
+ ${ entry . filter_expression
139
+ ? html `< ui-badge @click =${ ( ) => this . onDetailClick ( entry ) } type ="filter"
140
+ > RS Filter</ ui-badge
141
+ > `
142
+ : "" }
143
+ ${ entry . isPrivateBrowsingOnly != null
144
+ ? html `< ui-badge type ="private "> PBM Only</ ui-badge > `
145
+ : "" }
146
+ </ span >
147
+ ` ;
148
+ }
149
+
127
150
/**
128
151
* Show the detail dialog for the selected entry.
129
152
* @param entry The entry to show the detail for.
@@ -142,46 +165,38 @@ export class ExceptionsTable extends LitElement {
142
165
< table >
143
166
< thead >
144
167
< tr >
145
- < th class ="${ this . getVisibilityClass ( "id" ) } "> ID</ th >
146
- < th class ="${ this . getVisibilityClass ( "bugIds" ) } "> Bugs</ th >
147
- < th class ="${ this . getVisibilityClass ( "category" ) } "> Category</ th >
148
- < th class ="${ this . getVisibilityClass ( "topLevelUrlPattern" ) } "> Top Site</ th >
149
- < th class ="${ this . getVisibilityClass ( "urlPattern" ) } "> Tracker</ th >
150
- < th class ="${ this . getVisibilityClass ( "classifierFeatures" ) } "> Classifier Features</ th >
151
- < th class ="${ this . getVisibilityClass ( "isPrivateBrowsingOnly" ) } "> Session Type</ th >
152
- < th class ="${ this . getVisibilityClass ( "filterContentBlockingCategories" ) } "
153
- > ETP Levels</ th
154
- >
155
- < th class ="${ this . getVisibilityClass ( "filter_expression" ) } "> Filter Expression</ th >
168
+ < th > Bugs</ th >
169
+ < th > Category</ th >
170
+ < th class ="${ this . hasGlobalRules ? "" : "hidden-col" } "> Top Site</ th >
171
+ < th > Tracker</ th >
172
+ < th > Classifier Features</ th >
173
+ < th > Filters</ th >
156
174
< th > Detail</ th >
157
175
</ tr >
158
176
</ thead >
159
177
< tbody >
160
- ${ this . entries . filter ( this . filter ) . map (
178
+ ${ this . filteredEntries . map (
161
179
( entry ) => html `
162
180
< tr >
163
- < td class ="${ this . getVisibilityClass ( "id" ) } "> ${ entry . id ?? "" } </ td >
164
- < td class ="${ this . getVisibilityClass ( "bugIds" ) } ">
181
+ < td >
165
182
< span class ="badges ">
166
183
${ Array . isArray ( entry . bugIds )
167
184
? entry . bugIds . map ( ( bugId ) => html `< bug-label bugId =${ bugId } > </ bug-label > ` )
168
185
: "" }
169
186
</ span >
170
187
</ td >
171
- < td class =" ${ this . getVisibilityClass ( "category" ) } " >
188
+ < td >
172
189
${ entry . category
173
190
? html `< ui-badge type ="category " value ="${ entry . category } "
174
191
> ${ this . capitalizeFirstChar ( entry . category ) } </ ui-badge
175
192
> `
176
193
: "" }
177
194
</ td >
178
- < td class ="${ this . getVisibilityClass ( "topLevelUrlPattern" ) } ">
195
+ < td class ="${ this . hasGlobalRules ? "" : "hidden-col" } ">
179
196
${ entry . topLevelUrlPattern ?? "" }
180
197
</ td >
181
- < td class ="${ this . getVisibilityClass ( "urlPattern" ) } "
182
- > ${ entry . urlPattern ?? "" } </ td
183
- >
184
- < td class ="${ this . getVisibilityClass ( "classifierFeatures" ) } ">
198
+ < td > ${ entry . urlPattern ?? "" } </ td >
199
+ < td >
185
200
< span class ="badges ">
186
201
${ Array . isArray ( entry . classifierFeatures )
187
202
? entry . classifierFeatures . map (
@@ -190,17 +205,7 @@ export class ExceptionsTable extends LitElement {
190
205
: "" }
191
206
</ span >
192
207
</ td >
193
- < td class ="${ this . getVisibilityClass ( "isPrivateBrowsingOnly" ) } ">
194
- ${ entry . isPrivateBrowsingOnly === true
195
- ? html `< ui-badge type ="private "> Private</ ui-badge > `
196
- : html `< ui-badge type ="all "> All Sessions</ ui-badge > ` }
197
- </ td >
198
- < td class ="${ this . getVisibilityClass ( "filterContentBlockingCategories" ) } ">
199
- ${ this . renderETPBadges ( entry . filterContentBlockingCategories ) }
200
- </ td >
201
- < td class ="${ this . getVisibilityClass ( "filter_expression" ) } "
202
- > ${ entry . filter_expression ?? "" } </ td
203
- >
208
+ < td > ${ this . renderFilters ( entry ) } </ td >
204
209
< td >
205
210
< button @click =${ ( ) => this . onDetailClick ( entry ) } > { }</ button >
206
211
</ td >
0 commit comments