Skip to content

Commit de0e89f

Browse files
committed
file-tree: keep "" features option; update_by_features
1 parent b2d072e commit de0e89f

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

os-checks/pages/file-tree.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const selectedPkg = ref<string | null>(null);
6868
const selectedChecker = ref<string | null>(null);
6969
const selectedKind = ref<string | null>(null);
7070
const selectedTarget = ref(ALL_TARGETS);
71-
const selectedFeatures = ref("");
71+
const selectedFeatures = ref<string | null>(null);
7272
const displayFilters = ref(true);
7373
7474
const got = ref<Get>(getEmpty());
@@ -128,9 +128,11 @@ function get_ck_kinds(ck: string | null): string[] | null {
128128
}
129129
return null;
130130
}
131+
// switch to another Get
131132
watch(got, g => {
132-
// reset pkg since it's less likely to see the same selected pkg in another repo
133+
// reset pkg and features since it's less likely to see the same selected pkg in another repo
133134
selectedPkg.value = null;
135+
selectedFeatures.value = null;
134136
135137
// reset kind if the diagnositc is empty
136138
selectedKind.value = Dropdown.find_kind(selectedKind.value, g);
@@ -148,11 +150,17 @@ watch(got, g => {
148150
}
149151
if (reset_checker) selectedChecker.value = null;
150152
});
153+
154+
// watch selection changes
151155
watch(
152-
() => ({ pkg: selectedPkg.value, kind: selectedKind.value, ck: selectedChecker.value, g: got.value }),
153-
({ pkg, kind, ck, g }) => {
156+
() => ({
157+
pkg: selectedPkg.value, feat: selectedFeatures.value,
158+
kind: selectedKind.value, ck: selectedChecker.value, g: got.value
159+
}),
160+
({ pkg, feat, kind, ck, g }) => {
154161
const target = cloneDeep(g);
155162
163+
Dropdown.update_by_features(feat, target);
156164
Dropdown.update_by_pkg(pkg, target);
157165
158166
const ck_kinds = get_ck_kinds(ck);

os-checks/shared/file-tree/dropdown.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
157156
export function update_by_kind(kind: string, g: Get) {
158157
update_by_checker([kind], g);
159158
}

0 commit comments

Comments
 (0)