Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit b99ea82

Browse files
authored
feat(gui): filter is:done (#685)
* feat(gui): filter `is:done` * style: apply automatic fixes of linters * feat(gui): increase min width of filter help button Co-authored-by: lars-reimann <[email protected]>
1 parent 40ee293 commit b99ea82

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ yarn.lock
1818
report/
1919

2020
# Compilation/build outputs
21+
bin/
2122
build/
2223
coverage/
2324
dist/

api-editor/gui/src/common/FilterHelpButton.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const FilterHelpButton = function () {
2222
<PopoverTrigger>
2323
<IconButton variant="ghost" icon={<Icon name="help" />} aria-label="help" />
2424
</PopoverTrigger>
25-
<PopoverContent minWidth={462} fontSize="sm" marginRight={2}>
25+
<PopoverContent minWidth={600} fontSize="sm" marginRight={2}>
2626
<PopoverArrow />
2727
<PopoverCloseButton />
2828
<PopoverHeader>Filter Options</PopoverHeader>
@@ -46,6 +46,15 @@ export const FilterHelpButton = function () {
4646
of <em>public, internal</em>.
4747
</ChakraText>
4848
</ListItem>
49+
<ListItem>
50+
<ChakraText>
51+
<strong>is:done</strong>
52+
</ChakraText>
53+
<ChakraText>
54+
Displays only elements that are marked as complete and where all annotations are
55+
marked as correct.
56+
</ChakraText>
57+
</ListItem>
4958
<ListItem>
5059
<ChakraText>
5160
<strong>is:complete</strong>

api-editor/gui/src/features/annotations/annotationSlice.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,10 @@ export const selectTodo =
969969
export const selectNumberOfAnnotations =
970970
(target: string) =>
971971
(state: RootState): number => {
972-
return Object.values(selectAnnotationStore(state)).reduce((acc, annotations) => {
973-
if (target in annotations) {
972+
return Object.entries(selectAnnotationStore(state)).reduce((acc, [annotationType, annotations]) => {
973+
if (annotationType === 'completes') {
974+
return acc;
975+
} else if (target in annotations) {
974976
return acc + 1;
975977
} else {
976978
return acc;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { PythonClass } from '../PythonClass';
2+
import { PythonFunction } from '../PythonFunction';
3+
import { PythonModule } from '../PythonModule';
4+
import { PythonParameter } from '../PythonParameter';
5+
import { AbstractPythonFilter } from './AbstractPythonFilter';
6+
import { PythonDeclaration } from '../PythonDeclaration';
7+
import { Annotation, AnnotationStore } from '../../../annotations/annotationSlice';
8+
import { UsageCountStore } from '../../../usages/model/UsageCountStore';
9+
10+
/**
11+
* Keeps only declarations that are marked as complete and all annotations as correct.
12+
*/
13+
export class DoneFilter extends AbstractPythonFilter {
14+
shouldKeepModule(pythonModule: PythonModule, annotations: AnnotationStore, usages: UsageCountStore): boolean {
15+
return this.shouldKeepDeclaration(pythonModule, annotations, usages);
16+
}
17+
18+
shouldKeepClass(pythonClass: PythonClass, annotations: AnnotationStore, usages: UsageCountStore): boolean {
19+
return this.shouldKeepDeclaration(pythonClass, annotations, usages);
20+
}
21+
22+
shouldKeepFunction(pythonFunction: PythonFunction, annotations: AnnotationStore, usages: UsageCountStore): boolean {
23+
return this.shouldKeepDeclaration(pythonFunction, annotations, usages);
24+
}
25+
26+
shouldKeepParameter(
27+
pythonParameter: PythonParameter,
28+
annotations: AnnotationStore,
29+
usages: UsageCountStore,
30+
): boolean {
31+
return this.shouldKeepDeclaration(pythonParameter, annotations, usages);
32+
}
33+
34+
shouldKeepDeclaration(
35+
pythonDeclaration: PythonDeclaration,
36+
annotations: AnnotationStore,
37+
_usages: UsageCountStore,
38+
): boolean {
39+
return (
40+
pythonDeclaration.id in annotations.completes &&
41+
this.getAnnotationsForTarget(pythonDeclaration.id, annotations).every(
42+
(annotation) => (annotation.reviewers?.length ?? 0) > 0,
43+
)
44+
);
45+
}
46+
47+
private getAnnotationsForTarget(target: string, annotationStore: AnnotationStore): Annotation[] {
48+
return Object.entries(annotationStore).flatMap(([key, value]) => {
49+
if (!(target in value)) {
50+
return [];
51+
}
52+
53+
if (key === 'calledAfters' || key === 'groups') {
54+
return Object.values(value[target]);
55+
} else if (key === 'completes') {
56+
return [];
57+
} else {
58+
return [value[target]];
59+
}
60+
});
61+
}
62+
}

api-editor/gui/src/features/packageData/model/filters/filterFactory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ParameterAssignmentFilter } from './ParameterAssignmentFilter';
1313
import { PythonParameterAssignment } from '../PythonParameter';
1414
import { RequiredOrOptional, RequiredOrOptionalFilter } from './RequiredOrOptionalFilter';
1515
import { NameRegexFilter } from './NameRegexFilter';
16+
import { DoneFilter } from './DoneFilter';
1617

1718
/**
1819
* Creates a filter from the given string. This method handles conjunctions, negations, and non-negated tokens.
@@ -89,6 +90,10 @@ const parsePositiveToken = function (token: string): Optional<AbstractPythonFilt
8990
case 'is:nameonly':
9091
return new ParameterAssignmentFilter(PythonParameterAssignment.NAME_ONLY);
9192

93+
// Done
94+
case 'is:done':
95+
return new DoneFilter();
96+
9297
// Annotations
9398
case 'annotation:any':
9499
return new AnnotationFilter(AnnotationType.Any);

0 commit comments

Comments
 (0)