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

Commit 1e468ad

Browse files
authored
feat(gui): button to expand tree view up to matched nodes (#629)
* fix(gui): make selection view info full width again * feat(gui): button to expand tree view up to matched nodes * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 935fe6a commit 1e468ad

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

api-editor/gui/src/features/packageData/selectionView/ActionBar.tsx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AnnotationStore, selectAnnotations } from '../../annotations/annotation
77
import { useNavigate } from 'react-router';
88
import { useAppDispatch, useAppSelector } from '../../../app/hooks';
99
import { UsageCountStore } from '../../usages/model/UsageCountStore';
10-
import { setAllCollapsedInTreeView, setAllExpandedInTreeView } from '../../ui/uiSlice';
10+
import { setAllCollapsedInTreeView, setAllExpandedInTreeView, setExactlyExpandedInTreeView } from '../../ui/uiSlice';
1111

1212
interface ActionBarProps {
1313
declaration: PythonDeclaration;
@@ -21,6 +21,8 @@ export const ActionBar: React.FC<ActionBarProps> = function ({ declaration, pyth
2121
const navigate = useNavigate();
2222

2323
const annotations = useAppSelector(selectAnnotations);
24+
const isMatched = (node: PythonDeclaration): boolean =>
25+
pythonFilter.shouldKeepDeclaration(node, annotations, usages);
2426

2527
return (
2628
<HStack borderTop={1} layerStyle="subtleBorder" padding="0.5em 1em" marginTop={0} w="100%">
@@ -86,6 +88,14 @@ export const ActionBar: React.FC<ActionBarProps> = function ({ declaration, pyth
8688
>
8789
Collapse Selected
8890
</Button>
91+
<Button
92+
accessKey="m"
93+
onClick={() => {
94+
dispatch(setExactlyExpandedInTreeView(getMatchedNodesAndParents(pythonPackage, isMatched)));
95+
}}
96+
>
97+
Expand Matched
98+
</Button>
8999
</HStack>
90100
);
91101
};
@@ -190,3 +200,42 @@ const getDescendants = function (current: PythonDeclaration): string[] {
190200
}
191201
return childrenList;
192202
};
203+
204+
const getMatchedNodesAndParents = function (
205+
pythonPackage: PythonPackage,
206+
isMatched: (declaration: PythonDeclaration) => boolean,
207+
): string[] {
208+
return doGetMatchedNodesAndParents(pythonPackage, isMatched).nodesToExpand;
209+
};
210+
211+
interface DoGetMatchedNodesAndParentsResult {
212+
nodesToExpand: string[];
213+
subtreeShouldBeExpanded: boolean;
214+
}
215+
216+
const doGetMatchedNodesAndParents = function (
217+
current: PythonDeclaration,
218+
isMatched: (declaration: PythonDeclaration) => boolean,
219+
): DoGetMatchedNodesAndParentsResult {
220+
const nodesToExpand: string[] = [];
221+
let shouldExpandThisNode = false;
222+
223+
for (const child of current.children()) {
224+
const { nodesToExpand: childrenNodesToExpand, subtreeShouldBeExpanded } = doGetMatchedNodesAndParents(
225+
child,
226+
isMatched,
227+
);
228+
229+
nodesToExpand.push(...childrenNodesToExpand);
230+
shouldExpandThisNode ||= subtreeShouldBeExpanded;
231+
}
232+
233+
if (shouldExpandThisNode) {
234+
nodesToExpand.push(current.pathAsString());
235+
}
236+
237+
return {
238+
nodesToExpand,
239+
subtreeShouldBeExpanded: isMatched(current) || shouldExpandThisNode,
240+
};
241+
};

api-editor/gui/src/features/packageData/selectionView/SelectionView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const SelectionView: React.FC<SelectionViewProps> = function ({ pythonPac
2929

3030
return (
3131
<VStack h="100%" spacing={0}>
32-
<Box flexGrow={1} overflowY="auto">
32+
<Box flexGrow={1} overflowY="auto" width="100%">
3333
<Box padding={4}>
3434
{declaration instanceof PythonFunction && <FunctionView pythonFunction={declaration} />}
3535
{declaration instanceof PythonClass && <ClassView pythonClass={declaration} />}

api-editor/gui/src/features/ui/uiSlice.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ const uiSlice = createSlice({
228228
delete state.expandedInTreeView[item];
229229
}
230230
},
231+
setExactlyExpandedInTreeView(state, action: PayloadAction<string[]>) {
232+
const all = action.payload;
233+
state.expandedInTreeView = {};
234+
for (const item of all) {
235+
state.expandedInTreeView[item] = true;
236+
}
237+
},
231238
setTreeViewScrollOffset(state, action: PayloadAction<number>) {
232239
state.treeViewScrollOffset = action.payload;
233240
},
@@ -267,6 +274,7 @@ export const {
267274
toggleIsExpandedInTreeView,
268275
setAllExpandedInTreeView,
269276
setAllCollapsedInTreeView,
277+
setExactlyExpandedInTreeView,
270278
setTreeViewScrollOffset,
271279
setHeatMapMode,
272280

0 commit comments

Comments
 (0)