From 6038d0576a521dc4f3154514d5b5df679dbd741f Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 4 Jun 2022 19:37:59 +0200 Subject: [PATCH] feat(gui): parameter assignment filter (#540) * feat(gui): parse filters for usages/usefulness * feat(gui): update filter help text * feat(gui): pass usage data around * feat(gui): implement usage filter * feat(gui): implement usefulness filter * style: apply automatic fixes of linters * feat(gui): implement assignedBy filters * style: apply automatic fixes of linters * fix: build error * style: apply automatic fixes of linters * fix: linter errors * fix: build error Co-authored-by: lars-reimann --- .../gui/src/common/FilterHelpButton.tsx | 9 ++++ .../model/AnnotatedPythonParameter.ts | 3 ++ .../packageData/model/PythonParameter.ts | 1 + .../filters/ParameterAssignmentFilter.ts | 43 +++++++++++++++++++ .../model/filters/filterFactory.ts | 12 ++++++ 5 files changed, 68 insertions(+) create mode 100644 api-editor/gui/src/features/packageData/model/filters/ParameterAssignmentFilter.ts diff --git a/api-editor/gui/src/common/FilterHelpButton.tsx b/api-editor/gui/src/common/FilterHelpButton.tsx index db99d8e3f..453684fc5 100644 --- a/api-editor/gui/src/common/FilterHelpButton.tsx +++ b/api-editor/gui/src/common/FilterHelpButton.tsx @@ -46,6 +46,15 @@ export const FilterHelpButton = function () { of public, internal. + + + is:[assignedBy] + + + Displays only parameters that are assigned in the given manner. Replace [assignedBy] + with one of implicit, positionOnly, positionOrName, nameOnly. + + name:xy diff --git a/api-editor/gui/src/features/annotatedPackageData/model/AnnotatedPythonParameter.ts b/api-editor/gui/src/features/annotatedPackageData/model/AnnotatedPythonParameter.ts index 6ce9ea320..a98392511 100644 --- a/api-editor/gui/src/features/annotatedPackageData/model/AnnotatedPythonParameter.ts +++ b/api-editor/gui/src/features/annotatedPackageData/model/AnnotatedPythonParameter.ts @@ -26,6 +26,9 @@ export default class AnnotatedPythonParameter { this.qualifiedName = qualifiedName; this.defaultValue = defaultValue; switch (assignedBy) { + case PythonParameterAssignment.IMPLICIT: + this.assignedBy = 'IMPLICIT'; + break; case PythonParameterAssignment.NAME_ONLY: this.assignedBy = 'NAME_ONLY'; break; diff --git a/api-editor/gui/src/features/packageData/model/PythonParameter.ts b/api-editor/gui/src/features/packageData/model/PythonParameter.ts index 6cccad906..0c3fb1f31 100644 --- a/api-editor/gui/src/features/packageData/model/PythonParameter.ts +++ b/api-editor/gui/src/features/packageData/model/PythonParameter.ts @@ -4,6 +4,7 @@ import PythonFunction from './PythonFunction'; import PythonModule from './PythonModule'; export enum PythonParameterAssignment { + IMPLICIT, POSITION_ONLY, POSITION_OR_NAME, NAME_ONLY, diff --git a/api-editor/gui/src/features/packageData/model/filters/ParameterAssignmentFilter.ts b/api-editor/gui/src/features/packageData/model/filters/ParameterAssignmentFilter.ts new file mode 100644 index 000000000..301e70db3 --- /dev/null +++ b/api-editor/gui/src/features/packageData/model/filters/ParameterAssignmentFilter.ts @@ -0,0 +1,43 @@ +import AbstractPythonFilter from './AbstractPythonFilter'; +import PythonModule from '../PythonModule'; +import PythonClass from '../PythonClass'; +import PythonFunction from '../PythonFunction'; +import { AnnotationsState } from '../../../annotations/annotationSlice'; +import { UsageCountStore } from '../../../usages/model/UsageCountStore'; +import PythonParameter, { PythonParameterAssignment } from '../PythonParameter'; + +export default class ParameterAssignmentFilter extends AbstractPythonFilter { + constructor(readonly assignedBy: PythonParameterAssignment) { + super(); + } + + shouldKeepModule(_pythonModule: PythonModule, _annotations: AnnotationsState, _usages: UsageCountStore): boolean { + return false; + } + + shouldKeepClass(_pythonClass: PythonClass, _annotations: AnnotationsState, _usages: UsageCountStore): boolean { + return false; + } + + shouldKeepFunction( + _pythonFunction: PythonFunction, + _annotations: AnnotationsState, + _usages: UsageCountStore, + ): boolean { + return false; + } + + shouldKeepParameter( + pythonParameter: PythonParameter, + _annotations: AnnotationsState, + _usages: UsageCountStore, + ): boolean { + if (this.assignedBy === PythonParameterAssignment.IMPLICIT) { + return !pythonParameter.isExplicitParameter(); + } else if (!pythonParameter.isExplicitParameter()) { + return false; + } else { + return pythonParameter.assignedBy === this.assignedBy; + } + } +} diff --git a/api-editor/gui/src/features/packageData/model/filters/filterFactory.ts b/api-editor/gui/src/features/packageData/model/filters/filterFactory.ts index 8555fd784..80b3249b2 100644 --- a/api-editor/gui/src/features/packageData/model/filters/filterFactory.ts +++ b/api-editor/gui/src/features/packageData/model/filters/filterFactory.ts @@ -9,6 +9,8 @@ import AnnotationFilter, { AnnotationType } from './AnnotationFilter'; import UsageFilter from './UsageFilter'; import UsefulnessFilter from './UsefulnessFilter'; import { equals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual } from './comparisons'; +import ParameterAssignmentFilter from './ParameterAssignmentFilter'; +import { PythonParameterAssignment } from '../PythonParameter'; /** * Creates a filter from the given string. This method handles conjunctions, negations, and non-negated tokens. @@ -69,6 +71,16 @@ const parsePositiveToken = function (token: string): Optional