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

Commit 2622d18

Browse files
authored
feat(gui): breadcrumbs for selected element (#786)
* feat(gui): breadcrumbs for selected element * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 8733928 commit 2622d18

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

api-editor/gui/src/features/menuBar/MenuBar.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
MenuItemOption,
1313
MenuList,
1414
MenuOptionGroup,
15+
Spacer,
1516
useColorMode,
1617
} from '@chakra-ui/react';
1718
import React from 'react';
@@ -57,6 +58,7 @@ import {
5758
} from '../packageData/apiSlice';
5859
import { selectUsages } from '../usages/usageSlice';
5960
import { useLocation, useNavigate } from 'react-router-dom';
61+
import { SelectionBreadcrumbs } from './SelectionBreadcrumbs';
6062

6163
interface MenuBarProps {
6264
displayInferErrors: (errors: string[]) => void;
@@ -424,6 +426,12 @@ export const MenuBar: React.FC<MenuBarProps> = function ({ displayInferErrors })
424426
</Menu>
425427
</Box>
426428
</HStack>
429+
430+
<Spacer />
431+
432+
<HStack>
433+
<SelectionBreadcrumbs />
434+
</HStack>
427435
</Flex>
428436
);
429437
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Breadcrumb, BreadcrumbItem } from '@chakra-ui/react';
2+
import React from 'react';
3+
import { Link as RouterLink, useLocation } from 'react-router-dom';
4+
import { useAppSelector } from '../../app/hooks';
5+
import { selectRawPythonPackage } from '../packageData/apiSlice';
6+
import { PythonPackage } from '../packageData/model/PythonPackage';
7+
8+
export const SelectionBreadcrumbs = function () {
9+
const pythonPackage = useAppSelector(selectRawPythonPackage);
10+
const selectedDeclaration = pythonPackage.getDeclarationById(useLocation().pathname.split('/').splice(1).join('/'));
11+
12+
if (!selectedDeclaration || selectedDeclaration instanceof PythonPackage) {
13+
return null;
14+
}
15+
16+
const declarations = [...selectedDeclaration.ancestorsOrSelf()].reverse().splice(1);
17+
18+
return (
19+
<Breadcrumb>
20+
{declarations.map((it) => (
21+
<BreadcrumbItem>
22+
<RouterLink to={it.id}>{it.name}</RouterLink>
23+
</BreadcrumbItem>
24+
))}
25+
</Breadcrumb>
26+
);
27+
};

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export abstract class PythonDeclaration {
1515
return this.name;
1616
}
1717

18+
*ancestorsOrSelf(): Generator<PythonDeclaration> {
19+
let current: Optional<PythonDeclaration> = this;
20+
while (current) {
21+
yield current;
22+
current = current.parent();
23+
}
24+
}
25+
1826
*descendantsOrSelf(): Generator<PythonDeclaration> {
1927
yield this;
2028
for (const child of this.children()) {

0 commit comments

Comments
 (0)