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

Commit 903f584

Browse files
feat: hide private declarations by default and prevent annotating them (#423)
* feat: hide private declarations by default and prevent annotating them * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]> Co-authored-by: paul0314 <[email protected]>
1 parent e5e8916 commit 903f584

13 files changed

+100
-31
lines changed

api-editor/client/src/common/MenuBar.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ import {
4646
import AnnotatedPythonPackageBuilder from '../features/annotatedPackageData/model/AnnotatedPythonPackageBuilder';
4747
import { PythonFilter } from '../features/packageData/model/PythonFilter';
4848
import PythonPackage from '../features/packageData/model/PythonPackage';
49-
import { togglePackageDataImportDialog } from '../features/packageData/packageDataSlice';
49+
import {
50+
selectShowPrivateDeclarations,
51+
togglePackageDataImportDialog,
52+
toggleShowPrivateDeclarations,
53+
} from '../features/packageData/packageDataSlice';
5054
import { Setter } from './util/types';
5155

5256
interface MenuBarProps {
@@ -251,6 +255,13 @@ const MenuBar: React.FC<MenuBarProps> = function ({
251255
</Box>
252256
<Button onClick={exportAnnotations}>Export</Button>
253257
<DeleteAllAnnotations />
258+
<Button
259+
onClick={() => dispatch(toggleShowPrivateDeclarations())}
260+
>
261+
{useAppSelector(selectShowPrivateDeclarations)
262+
? 'Hide private declarations'
263+
: 'Show private declarations'}
264+
</Button>
254265
<Button onClick={toggleColorMode}>
255266
Toggle {colorMode === 'light' ? 'dark' : 'light'}
256267
</Button>

api-editor/client/src/features/packageData/model/PythonClass.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default class PythonClass extends PythonDeclaration {
5151
return this.methods;
5252
}
5353

54+
isPublicDeclaration(): boolean {
55+
return this.isPublic;
56+
}
57+
5458
toString(): string {
5559
let result = '';
5660

api-editor/client/src/features/packageData/model/PythonDeclaration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default abstract class PythonDeclaration {
1212
return this.name;
1313
}
1414

15+
isPublicDeclaration(): boolean {
16+
return true;
17+
}
18+
1519
path(): string[] {
1620
let current: Optional<PythonDeclaration> = this;
1721
const result: string[] = [];

api-editor/client/src/features/packageData/model/PythonFunction.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export default class PythonFunction extends PythonDeclaration {
6262
return this.parameters;
6363
}
6464

65+
isPublicDeclaration(): boolean {
66+
return this.isPublic;
67+
}
68+
6569
getUniqueName(): string {
6670
return this.uniqueName;
6771
}

api-editor/client/src/features/packageData/model/PythonParameter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export default class PythonParameter extends PythonDeclaration {
4949
return [];
5050
}
5151

52+
isPublicDeclaration(): boolean {
53+
return this.isPublic;
54+
}
55+
5256
isExplicitParameter(): boolean {
5357
const containingFunction = this.parent();
5458
if (!containingFunction) {

api-editor/client/src/features/packageData/packageDataSlice.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface PackageDataState {
77
};
88
treeViewScrollOffset: number;
99
showImportDialog: boolean;
10+
showPrivateDeclarations: boolean;
1011
}
1112

1213
// Initial state -------------------------------------------------------------------------------------------------------
@@ -15,6 +16,7 @@ const initialState: PackageDataState = {
1516
expandedInTreeView: {},
1617
treeViewScrollOffset: 0,
1718
showImportDialog: false,
19+
showPrivateDeclarations: false,
1820
};
1921

2022
// Slice ---------------------------------------------------------------------------------------------------------------
@@ -36,6 +38,9 @@ const packageDataSlice = createSlice({
3638
toggleImportDialog(state) {
3739
state.showImportDialog = !state.showImportDialog;
3840
},
41+
toggleShowPrivateDeclarations(state) {
42+
state.showPrivateDeclarations = !state.showPrivateDeclarations;
43+
},
3944
},
4045
});
4146

@@ -44,6 +49,7 @@ export const {
4449
toggleIsExpanded: toggleIsExpandedInTreeView,
4550
setScrollOffset: setTreeViewScrollOffset,
4651
toggleImportDialog: togglePackageDataImportDialog,
52+
toggleShowPrivateDeclarations,
4753
} = actions;
4854
export default reducer;
4955

@@ -59,3 +65,5 @@ export const selectTreeViewScrollOffset = (state: RootState): number =>
5965
selectPackageData(state).treeViewScrollOffset;
6066
export const selectShowPackageDataImportDialog = (state: RootState): boolean =>
6167
selectPackageData(state).showImportDialog;
68+
export const selectShowPrivateDeclarations = (state: RootState): boolean =>
69+
selectPackageData(state).showPrivateDeclarations;

api-editor/client/src/features/packageData/selectionView/ClassView.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ const ClassView: React.FC<ClassViewProps> = function ({ pythonClass }) {
2424
<Stack spacing={4}>
2525
<HStack>
2626
<Heading as="h3" size="lg">
27-
{pythonClass.name}
27+
{pythonClass.name}{' '}
28+
{!pythonClass.isPublic && '(private)'}
2829
</Heading>
29-
<AnnotationDropdown
30-
target={id}
31-
showMove
32-
showRename
33-
showUnused
34-
/>
30+
{pythonClass.isPublic && (
31+
<AnnotationDropdown
32+
target={id}
33+
showMove
34+
showRename
35+
showUnused
36+
/>
37+
)}
3538
</HStack>
3639

3740
<AnnotationView target={id} />

api-editor/client/src/features/packageData/selectionView/FunctionView.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,25 @@ const FunctionView: React.FC<FunctionViewProps> = function ({
3838
<Stack spacing={4}>
3939
<HStack>
4040
<Heading as="h3" size="lg">
41-
{pythonFunction.name}
41+
{pythonFunction.name}{' '}
42+
{!pythonFunction.isPublic && '(private)'}
4243
</Heading>
43-
<AnnotationDropdown
44-
target={id}
45-
showCalledAfter={hasRemainingCalledAfters}
46-
showGroup={
47-
pythonFunction.explicitParameters().length >= 2
48-
}
49-
showMove={
50-
pythonFunction.containingModuleOrClass instanceof
51-
PythonModule
52-
}
53-
showPure
54-
showRename
55-
showUnused
56-
/>
44+
{pythonFunction.isPublic && (
45+
<AnnotationDropdown
46+
target={id}
47+
showCalledAfter={hasRemainingCalledAfters}
48+
showGroup={
49+
pythonFunction.explicitParameters().length >= 2
50+
}
51+
showMove={
52+
pythonFunction.containingModuleOrClass instanceof
53+
PythonModule
54+
}
55+
showPure
56+
showRename
57+
showUnused
58+
/>
59+
)}
5760
</HStack>
5861

5962
<AnnotationView target={id} />

api-editor/client/src/features/packageData/selectionView/ParameterNode.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ const ParameterNode: React.FC<ParameterNodeProps> = function ({
3131
<HStack>
3232
{isTitle ? (
3333
<Heading as="h3" size="lg">
34-
{pythonParameter.name}
34+
{pythonParameter.name}{' '}
35+
{!pythonParameter.isPublic && '(private)'}
3536
</Heading>
3637
) : (
3738
<Heading as="h4" size="sm">
38-
{pythonParameter.name}
39+
{pythonParameter.name}{' '}
40+
{!pythonParameter.isPublic && '(private)'}
3941
</Heading>
4042
)}
41-
{isExplicitParameter && (
43+
{pythonParameter.isPublic && isExplicitParameter && (
4244
<AnnotationDropdown
4345
target={id}
4446
showAttribute={isConstructorParameter}

api-editor/client/src/features/packageData/treeView/ClassNode.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { FaChalkboard } from 'react-icons/fa';
33
import { isEmptyList } from '../../../common/util/listOperations';
44
import PythonClass from '../model/PythonClass';
55
import TreeNode from './TreeNode';
6+
import { useAppSelector } from '../../../app/hooks';
7+
import { selectShowPrivateDeclarations } from '../packageDataSlice';
68

79
interface ClassNodeProps {
810
pythonClass: PythonClass;
911
}
1012

1113
const ClassNode: React.FC<ClassNodeProps> = function ({ pythonClass }) {
12-
const hasMethods = !isEmptyList(pythonClass.methods);
14+
let methods = pythonClass.methods;
15+
if (!useAppSelector(selectShowPrivateDeclarations)) {
16+
methods = methods.filter((it) => it.isPublic);
17+
}
18+
const hasMethods = !isEmptyList(methods);
1319

1420
return (
1521
<TreeNode

api-editor/client/src/features/packageData/treeView/FunctionNode.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { FaCogs } from 'react-icons/fa';
33
import { isEmptyList } from '../../../common/util/listOperations';
44
import PythonFunction from '../model/PythonFunction';
55
import TreeNode from './TreeNode';
6+
import { useAppSelector } from '../../../app/hooks';
7+
import { selectShowPrivateDeclarations } from '../packageDataSlice';
68

79
interface FunctionNodeProps {
810
pythonFunction: PythonFunction;
@@ -11,7 +13,11 @@ interface FunctionNodeProps {
1113
const FunctionNode: React.FC<FunctionNodeProps> = function ({
1214
pythonFunction,
1315
}) {
14-
const hasParameters = !isEmptyList(pythonFunction.parameters);
16+
let parameters = pythonFunction.parameters;
17+
if (!useAppSelector(selectShowPrivateDeclarations)) {
18+
parameters = parameters.filter((it) => it.isPublic);
19+
}
20+
const hasParameters = !isEmptyList(parameters);
1521

1622
return (
1723
<TreeNode

api-editor/client/src/features/packageData/treeView/ModuleNode.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ import { FaArchive } from 'react-icons/fa';
33
import { isEmptyList } from '../../../common/util/listOperations';
44
import PythonModule from '../model/PythonModule';
55
import TreeNode from './TreeNode';
6+
import { useAppSelector } from '../../../app/hooks';
7+
import { selectShowPrivateDeclarations } from '../packageDataSlice';
68

79
interface ModuleNodeProps {
810
pythonModule: PythonModule;
911
}
1012

1113
const ModuleNode: React.FC<ModuleNodeProps> = function ({ pythonModule }) {
12-
const hasClasses = !isEmptyList(pythonModule.classes);
13-
const hasFunctions = !isEmptyList(pythonModule.functions);
14+
let classes = pythonModule.classes;
15+
if (!useAppSelector(selectShowPrivateDeclarations)) {
16+
classes = classes.filter((it) => it.isPublic);
17+
}
18+
const hasClasses = !isEmptyList(classes);
19+
let functions = pythonModule.functions;
20+
if (!useAppSelector(selectShowPrivateDeclarations)) {
21+
functions = functions.filter((it) => it.isPublic);
22+
}
23+
const hasFunctions = !isEmptyList(functions);
1424
const hasChildren = hasClasses || hasFunctions;
1525

1626
return (

api-editor/client/src/features/packageData/treeView/TreeView.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import PythonPackage from '../model/PythonPackage';
1111
import PythonParameter from '../model/PythonParameter';
1212
import {
1313
selectAllExpandedInTreeView,
14+
selectShowPrivateDeclarations,
1415
selectTreeViewScrollOffset,
1516
setTreeViewScrollOffset,
1617
} from '../packageDataSlice';
@@ -31,7 +32,10 @@ const TreeView: React.FC<TreeViewProps> = memo(({ pythonPackage }) => {
3132
const dispatch = useAppDispatch();
3233
const allExpanded = useAppSelector(selectAllExpandedInTreeView);
3334

34-
const children = walkChildrenInPreorder(allExpanded, pythonPackage);
35+
let children = walkChildrenInPreorder(allExpanded, pythonPackage);
36+
if (!useAppSelector(selectShowPrivateDeclarations)) {
37+
children = children.filter((it) => it.isPublicDeclaration());
38+
}
3539
const previousScrollOffset = useAppSelector(selectTreeViewScrollOffset);
3640

3741
// Keep a reference to the last FixedSizeList before everything is dismounted

0 commit comments

Comments
 (0)