Skip to content

Commit 2f57e0f

Browse files
refactor: ArgNavBar to own file
1 parent ff7253e commit 2f57e0f

File tree

2 files changed

+82
-76
lines changed

2 files changed

+82
-76
lines changed

src/web/src/views/workspace/ArgumentNavigation.tsx

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from "react";
2-
import { Box, Button, ButtonBase, styled, Typography, TypographyProps } from "@mui/material";
3-
import ArrowBackIosIcon from "@mui/icons-material/ArrowBackIos";
2+
import { Box, Button, styled, Typography, TypographyProps } from "@mui/material";
43
import EditIcon from "@mui/icons-material/Edit";
54
import ImportExportIcon from "@mui/icons-material/ImportExport";
65
import {
@@ -12,6 +11,7 @@ import {
1211
StableTypography,
1312
} from "./WSEditorTheme";
1413
import ArgumentPropsReviewer from "./ArgumentPropsReviewer";
14+
import ArgNavBar, { type ArgIdx } from "./argument/ArgNavBar";
1515
import type { CMDArg, ClsArgDefinitionMap } from "./WSEditorCommandArgumentsContent";
1616

1717
interface CMDArgBase {
@@ -51,11 +51,6 @@ interface CMDNumberArg extends CMDArg {
5151
};
5252
}
5353

54-
interface ArgIdx {
55-
var: string;
56-
displayKey: string;
57-
}
58-
5954
interface ArgumentNavigationProps {
6055
commandUrl: string;
6156
args: CMDArg[];
@@ -66,29 +61,13 @@ interface ArgumentNavigationProps {
6661
onAddSubcommand: (arg: CMDArg, argIdxStack: ArgIdx[]) => void;
6762
}
6863

69-
interface ArgNavBarProps {
70-
argIdxStack: ArgIdx[];
71-
onChangeArgIdStack: (end: number) => void;
72-
}
73-
7464
interface ArgumentReviewerProps {
7565
arg: CMDArg;
7666
depth: number;
7767
onEdit: () => void;
7868
onUnwrap: () => void;
7969
}
8070

81-
const NavBarItemTypography = styled(Typography)<TypographyProps>(({ theme }) => ({
82-
color: theme.palette.primary.main,
83-
fontFamily: "'Work Sans', sans-serif",
84-
fontSize: 14,
85-
fontWeight: 400,
86-
}));
87-
88-
const NavBarItemHightLightedTypography = styled(NavBarItemTypography)<TypographyProps>(() => ({
89-
color: "#5d64cf",
90-
}));
91-
9271
const ArgNameTypography = styled(Typography)<TypographyProps>(({ theme }) => ({
9372
color: theme.palette.primary.main,
9473
fontFamily: "'Roboto Condensed', sans-serif",
@@ -174,58 +153,6 @@ const spliceArgOptionsString = (arg: CMDArg, depth: number) => {
174153
return optionsString;
175154
};
176155

177-
const ArgNavBar: React.FC<ArgNavBarProps> = ({ argIdxStack, onChangeArgIdStack }) => {
178-
return (
179-
<React.Fragment>
180-
<Box
181-
sx={{
182-
flexGrow: 1,
183-
display: "flex",
184-
flexDirection: "row",
185-
alignItems: "center",
186-
justifyContent: "flex-start",
187-
mt: 1,
188-
mb: 0.5,
189-
mr: 2,
190-
}}
191-
>
192-
<ButtonBase
193-
key="Back"
194-
onClick={() => {
195-
onChangeArgIdStack(0);
196-
}}
197-
>
198-
<ArrowBackIosIcon sx={{ fontSize: 14 }} />
199-
</ButtonBase>
200-
{argIdxStack.slice(0, -1).map((argIdx: ArgIdx, index: number) => (
201-
<ButtonBase
202-
key={`${index}`}
203-
onClick={() => {
204-
onChangeArgIdStack(index + 1);
205-
}}
206-
>
207-
<NavBarItemTypography sx={{ flexShrink: 0 }}>
208-
{index > 0 ? `.${argIdx.displayKey}` : argIdx.displayKey}
209-
</NavBarItemTypography>
210-
</ButtonBase>
211-
))}
212-
<ButtonBase
213-
key={`${argIdxStack.length - 1}`}
214-
onClick={() => {
215-
onChangeArgIdStack(argIdxStack.length);
216-
}}
217-
>
218-
<NavBarItemHightLightedTypography sx={{ flexShrink: 0 }}>
219-
{argIdxStack.length > 1
220-
? `.${argIdxStack[argIdxStack.length - 1].displayKey}`
221-
: argIdxStack[argIdxStack.length - 1].displayKey}
222-
</NavBarItemHightLightedTypography>
223-
</ButtonBase>
224-
</Box>
225-
</React.Fragment>
226-
);
227-
};
228-
229156
const ArgumentReviewer: React.FC<ArgumentReviewerProps> = ({ arg, depth, onEdit, onUnwrap }) => {
230157
const [choices, setChoices] = useState<string[]>([]);
231158

@@ -612,4 +539,4 @@ const ArgumentNavigation: React.FC<ArgumentNavigationProps> = ({
612539
};
613540

614541
export default ArgumentNavigation;
615-
export type { ArgumentNavigationProps, ArgIdx, ArgumentReviewerProps, ArgNavBarProps };
542+
export type { ArgumentNavigationProps, ArgumentReviewerProps };
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from "react";
2+
import { Box, ButtonBase, styled, Typography, TypographyProps } from "@mui/material";
3+
import ArrowBackIosIcon from "@mui/icons-material/ArrowBackIos";
4+
5+
interface ArgIdx {
6+
var: string;
7+
displayKey: string;
8+
}
9+
10+
interface ArgNavBarProps {
11+
argIdxStack: ArgIdx[];
12+
onChangeArgIdStack: (end: number) => void;
13+
}
14+
15+
const NavBarItemTypography = styled(Typography)<TypographyProps>(({ theme }) => ({
16+
color: theme.palette.primary.main,
17+
fontFamily: "'Work Sans', sans-serif",
18+
fontSize: 14,
19+
fontWeight: 400,
20+
}));
21+
22+
const NavBarItemHightLightedTypography = styled(NavBarItemTypography)<TypographyProps>(() => ({
23+
color: "#5d64cf",
24+
}));
25+
26+
const ArgNavBar: React.FC<ArgNavBarProps> = ({ argIdxStack, onChangeArgIdStack }) => {
27+
return (
28+
<React.Fragment>
29+
<Box
30+
sx={{
31+
flexGrow: 1,
32+
display: "flex",
33+
flexDirection: "row",
34+
alignItems: "center",
35+
justifyContent: "flex-start",
36+
mt: 1,
37+
mb: 0.5,
38+
mr: 2,
39+
}}
40+
>
41+
<ButtonBase
42+
key="Back"
43+
onClick={() => {
44+
onChangeArgIdStack(0);
45+
}}
46+
>
47+
<ArrowBackIosIcon sx={{ fontSize: 14 }} />
48+
</ButtonBase>
49+
{argIdxStack.slice(0, -1).map((argIdx: ArgIdx, index: number) => (
50+
<ButtonBase
51+
key={`${index}`}
52+
onClick={() => {
53+
onChangeArgIdStack(index + 1);
54+
}}
55+
>
56+
<NavBarItemTypography sx={{ flexShrink: 0 }}>
57+
{index > 0 ? `.${argIdx.displayKey}` : argIdx.displayKey}
58+
</NavBarItemTypography>
59+
</ButtonBase>
60+
))}
61+
<ButtonBase
62+
key={`${argIdxStack.length - 1}`}
63+
onClick={() => {
64+
onChangeArgIdStack(argIdxStack.length);
65+
}}
66+
>
67+
<NavBarItemHightLightedTypography sx={{ flexShrink: 0 }}>
68+
{argIdxStack.length > 1
69+
? `.${argIdxStack[argIdxStack.length - 1].displayKey}`
70+
: argIdxStack[argIdxStack.length - 1].displayKey}
71+
</NavBarItemHightLightedTypography>
72+
</ButtonBase>
73+
</Box>
74+
</React.Fragment>
75+
);
76+
};
77+
78+
export default ArgNavBar;
79+
export type { ArgNavBarProps, ArgIdx };

0 commit comments

Comments
 (0)