Skip to content

Commit

Permalink
Apply "Show Line Numbers" as toggle switch in sidebar (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
senwang86 committed Jun 22, 2023
1 parent 6939a4c commit ccf8a99
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
8 changes: 0 additions & 8 deletions ui/src/components/CanvasContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ export function CanvasContextMenu(props) {
<ListItemText>New Scope</ListItemText>
</MenuItem>
)}
<MenuItem onClick={flipShowLineNumbers} sx={ItemStyle}>
<ListItemIcon sx={{ color: "inherit" }}>
<FormatListNumberedIcon />
</ListItemIcon>
<ListItemText>
{showLineNumbers ? "Hide " : "Show "} Line Numbers
</ListItemText>
</MenuItem>
</MenuList>
</Box>
);
Expand Down
22 changes: 22 additions & 0 deletions ui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ function SidebarSettings() {
);
const devMode = useStore(store, (state) => state.devMode);
const setDevMode = useStore(store, (state) => state.setDevMode);
const showLineNumbers = useStore(store, (state) => state.showLineNumbers);
const setShowLineNumbers = useStore(
store,
(state) => state.setShowLineNumbers
);
const autoRunLayout = useStore(store, (state) => state.autoRunLayout);
const setAutoRunLayout = useStore(store, (state) => state.setAutoRunLayout);
const contextualZoom = useStore(store, (state) => state.contextualZoom);
Expand All @@ -57,6 +62,23 @@ function SidebarSettings() {
return (
<Box>
<Box>
<Tooltip title={"Show Line Numbers"} disableInteractive>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={showLineNumbers}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setShowLineNumbers(event.target.checked);
}}
/>
}
label="Show Line Numbers"
/>
</FormGroup>
</Tooltip>
<Tooltip
title={"Enable Debug Mode, e.g., show pod IDs"}
disableInteractive
Expand Down
12 changes: 11 additions & 1 deletion ui/src/lib/store/settingSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ export interface SettingSlice {
setDevMode: (b: boolean) => void;
autoRunLayout?: boolean;
setAutoRunLayout: (b: boolean) => void;

contextualZoomParams: Record<any, number>;
contextualZoom: boolean;
setContextualZoom: (b: boolean) => void;
level2fontsize: (level: number) => number;
showLineNumbers?: boolean;
setShowLineNumbers: (b: boolean) => void;
}

export const createSettingSlice: StateCreator<MyState, [], [], SettingSlice> = (
Expand Down Expand Up @@ -65,6 +66,15 @@ export const createSettingSlice: StateCreator<MyState, [], [], SettingSlice> = (
// also write to local storage
localStorage.setItem("contextualZoom", JSON.stringify(b));
},
showLineNumbers: localStorage.getItem("showLineNumbers")
? JSON.parse(localStorage.getItem("showLineNumbers")!)
: false,
setShowLineNumbers: (b: boolean) => {
// set it
set({ showLineNumbers: b });
// also write to local storage
localStorage.setItem("showLineNumbers", JSON.stringify(b));
},
// TODO Make it configurable.
contextualZoomParams: {
prev: 56,
Expand Down

0 comments on commit ccf8a99

Please sign in to comment.