Skip to content

Commit 72c07a3

Browse files
Implement support for new filterKey
1 parent 049b4c2 commit 72c07a3

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

extensions/ql-vscode/src/pure/variant-analysis-filter-sort.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
RepositoryWithMetadata,
44
} from "../variant-analysis/shared/repository";
55
import { parseDate } from "./date";
6+
import { assertNever } from "./helpers-pure";
67

78
export enum FilterKey {
89
All = "all",
@@ -40,9 +41,31 @@ export function matchesFilter(
4041
return true;
4142
}
4243

43-
return item.repository.fullName
44-
.toLowerCase()
45-
.includes(filterSortState.searchValue.toLowerCase());
44+
return (
45+
matchesSearch(item.repository, filterSortState.searchValue) &&
46+
matchesFilterKey(item.resultCount, filterSortState.filterKey)
47+
);
48+
}
49+
50+
function matchesSearch(
51+
repository: SortableRepository,
52+
searchValue: string,
53+
): boolean {
54+
return repository.fullName.toLowerCase().includes(searchValue.toLowerCase());
55+
}
56+
57+
function matchesFilterKey(
58+
resultCount: number | undefined,
59+
filterKey: FilterKey,
60+
): boolean {
61+
switch (filterKey) {
62+
case FilterKey.All:
63+
return true;
64+
case FilterKey.WithResults:
65+
return resultCount !== undefined && resultCount > 0;
66+
default:
67+
assertNever(filterKey);
68+
}
4669
}
4770

4871
type SortableRepository = Pick<Repository, "fullName"> &

0 commit comments

Comments
 (0)