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

Commit 0fca18f

Browse files
authored
feat(gui): new filter is:removed (#969)
* feat(gui): new filter `is:removed` * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 3046ba3 commit 0fca18f

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

api-editor/gui/src/features/filter/FilterHelpButton.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ export const FilterHelpButton = function () {
137137
.
138138
</ChakraText>
139139
</ListItem>
140+
<ListItem>
141+
<ChakraText>
142+
<strong>is:removed</strong>
143+
</ChakraText>
144+
<ChakraText>
145+
Displays only elements that will be removed. These are either annotated with @remove
146+
directly or have an ancestors with this annotation.
147+
</ChakraText>
148+
</ListItem>
140149
<ListItem>
141150
<ChakraText>
142151
<strong>usages:[operator][expected]</strong>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { PythonClass } from '../../packageData/model/PythonClass';
2+
import { PythonFunction } from '../../packageData/model/PythonFunction';
3+
import { PythonModule } from '../../packageData/model/PythonModule';
4+
import { PythonParameter } from '../../packageData/model/PythonParameter';
5+
import { PythonDeclaration } from '../../packageData/model/PythonDeclaration';
6+
import { UsageCountStore } from '../../usages/model/UsageCountStore';
7+
import { AbstractPythonFilter } from './AbstractPythonFilter';
8+
import { AnnotationStore, ReviewResult } from '../../annotations/versioning/AnnotationStoreV2';
9+
10+
/**
11+
* Keeps only declarations that have the @remove annotation directly or have an ancestor with this annotation.
12+
*/
13+
export class RemovedFilter 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 [...pythonDeclaration.ancestorsOrSelf()].some((ancestor) => {
40+
const annotation = annotations.removeAnnotations[ancestor.id];
41+
return annotation && !annotation.isRemoved && annotation.reviewResult !== ReviewResult.Wrong;
42+
});
43+
}
44+
}

api-editor/gui/src/features/filter/model/filterFactory.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { DoneFilter } from './DoneFilter';
1616
import { PythonParameterAssignment } from '../../packageData/model/PythonParameter';
1717
import { QualifiedNameStringFilter } from './QualifiedNameStringFilter';
1818
import { QualifiedNameRegexFilter } from './QualifiedNameRegexFilter';
19+
import { RemovedFilter } from './RemovedFilter';
1920

2021
/**
2122
* Creates a filter from the given string. This method handles conjunctions, negations, and non-negated tokens.
@@ -92,6 +93,9 @@ const fixedFilters: { [name: string]: AbstractPythonFilter } = {
9293
'annotation:@rename': new AnnotationFilter(AnnotationType.Rename),
9394
'annotation:@todo': new AnnotationFilter(AnnotationType.Todo),
9495
'annotation:@value': new AnnotationFilter(AnnotationType.Value),
96+
97+
// Removed
98+
'is:removed': new RemovedFilter(),
9599
};
96100

97101
/**

0 commit comments

Comments
 (0)