@@ -9,19 +9,14 @@ export class Dropdown {
99 map : KindCheckerMap ;
1010 checkers : DropDownOptions ;
1111 features : DropDownOptions ;
12- // has non-empty features
13- has_features : boolean ;
1412
1513 /** called when a new fileTree is created */
1614 constructor ( g : Get , map : KindCheckerMap ) {
1715 this . pkgs = gen_pkgs ( g ) ;
1816 this . kinds = gen_kinds ( g ) ;
1917 this . map = map ; // map is supposed to never change
2018 this . checkers = gen_checkers ( this . kinds , map ) ;
21- const { has, opt } = gen_features ( g ) ;
22- console . log ( has , opt ) ;
23- this . has_features = has ;
24- this . features = opt ;
19+ this . features = gen_features ( g ) ;
2520 }
2621
2722 /** called when a fitler is changed */
@@ -31,10 +26,7 @@ export class Dropdown {
3126 options . pkgs . counts [ ALL_PKGS ] = this . pkgs . counts [ ALL_PKGS ] ;
3227 options . kinds . counts [ ALL_KINDS ] = this . kinds . counts [ ALL_KINDS ] ;
3328 options . checkers . counts [ ALL_CHECKERS ] = this . checkers . counts [ ALL_CHECKERS ] ;
34-
35- if ( this . has_features )
36- options . features . counts [ ALL_FEATURES_SETS ] = this . features . counts [ ALL_FEATURES_SETS ] ;
37-
29+ options . features . counts [ ALL_FEATURES_SETS ] = this . features . counts [ ALL_FEATURES_SETS ] ;
3830 return options ;
3931 }
4032
@@ -49,6 +41,10 @@ export class Dropdown {
4941 if ( pkg && pkg !== ALL_PKGS ) update_by_pkg ( pkg , g ) ;
5042 }
5143
44+ static update_by_features ( feat : string | null , g : Get ) {
45+ if ( feat !== null && feat !== ALL_FEATURES_SETS ) update_by_features ( feat , g ) ;
46+ }
47+
5248 static update_by_kind ( kind : string | null , g : Get ) {
5349 if ( kind && kind !== ALL_KINDS ) update_by_kind ( kind , g ) ;
5450 }
@@ -128,7 +124,7 @@ export function gen_targets(targets: Targets): DropDownOptions {
128124 return counts_to_options ( counts ) ;
129125}
130126
131- function gen_features ( g : Get ) : { opt : DropDownOptions , has : boolean } {
127+ function gen_features ( g : Get ) : DropDownOptions {
132128 let counts : Counts = { } ;
133129 for ( const data of g . fileTree . data ) {
134130 for ( const reports of data . raw_reports ) {
@@ -138,14 +134,7 @@ function gen_features(g: Get): { opt: DropDownOptions, has: boolean } {
138134 else counts [ feat ] = len ;
139135 }
140136 }
141- // if no feat or only empty feat, treat it as no option
142- const len = Object . entries ( counts ) . length ;
143- const has_features = ! ( len === 0 || ( len === 1 && counts [ "" ] ) ) ;
144- // ALL_FEATURES_SETS must only apply to has non-empty features
145- return {
146- opt : has_features ? counts_to_options ( counts , ALL_FEATURES_SETS ) : emptyOptions ( ) ,
147- has : has_features
148- } ;
137+ return counts_to_options ( counts , ALL_FEATURES_SETS ) ;
149138}
150139
151140// filters update Get: got2 is updated in place; got is deep cloned
@@ -154,6 +143,16 @@ export function update_by_pkg(pkg: string, g: Get) {
154143 g . fileTree . data = g . fileTree . data . filter ( val => val . pkg === pkg ) ;
155144}
156145
146+ export function update_by_features ( feat : string , g : Get ) {
147+ for ( const data of g . fileTree . data ) {
148+ // only keep feat
149+ data . raw_reports = data . raw_reports . filter ( r => r . features === feat ) ;
150+ data . count = data . raw_reports . length ;
151+ }
152+ // only keep non-zero nodes
153+ g . fileTree . data = g . fileTree . data . filter ( d => d . count !== 0 ) ;
154+ }
155+
157156export function update_by_kind ( kind : string , g : Get ) {
158157 update_by_checker ( [ kind ] , g ) ;
159158}
0 commit comments