Skip to content

Commit

Permalink
add devMode (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihebi authored Jan 4, 2023
1 parent 4a56947 commit 3df385a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,31 @@ function SidebarSettings() {
store,
(state) => state.setShowAnnotations
);
const devMode = useStore(store, (state) => state.devMode);
const setDevMode = useStore(store, (state) => state.setDevMode);
return (
<Box>
<Box>
<Tooltip
title={"Enable DevMode, e.g., show pod IDs"}
disableInteractive
>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={devMode}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setDevMode(event.target.checked);
}}
/>
}
label="Dev Mode"
/>
</FormGroup>
</Tooltip>
<Tooltip title={"Enable Scoped Variables"} disableInteractive>
<FormGroup>
<FormControlLabel
Expand Down
15 changes: 15 additions & 0 deletions ui/src/components/nodes/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const CodeNode = memo<Props>(function ({
}) {
const store = useContext(RepoContext);
if (!store) throw new Error("Missing BearContext.Provider in the tree");
const devMode = useStore(store, (state) => state.devMode);
// const pod = useStore(store, (state) => state.pods[id]);
const wsRun = useStore(store, (state) => state.wsRun);
const clearResults = useStore(store, (s) => s.clearResults);
Expand Down Expand Up @@ -369,6 +370,20 @@ export const CodeNode = memo<Props>(function ({
/>
{/* The header of code pods. */}
<Box className="custom-drag-handle">
{devMode && (
<Box
sx={{
position: "absolute",
top: "-48px",
width: "50%",
userSelect: "text",
cursor: "auto",
}}
className="nodrag"
>
<pre>{id}</pre>
</Box>
)}
<Box
sx={{
position: "absolute",
Expand Down
11 changes: 11 additions & 0 deletions ui/src/lib/store/settingSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface SettingSlice {
setScopedVars: (b: boolean) => void;
showAnnotations?: boolean;
setShowAnnotations: (b: boolean) => void;
devMode?: boolean;
setDevMode: (b: boolean) => void;
}

export const createSettingSlice: StateCreator<MyState, [], [], SettingSlice> = (
Expand All @@ -30,4 +32,13 @@ export const createSettingSlice: StateCreator<MyState, [], [], SettingSlice> = (
// also write to local storage
localStorage.setItem("showAnnotations", JSON.stringify(b));
},
devMode: localStorage.getItem("devMode")
? JSON.parse(localStorage.getItem("devMode")!)
: false,
setDevMode: (b: boolean) => {
// set it
set({ devMode: b });
// also write to local storage
localStorage.setItem("devMode", JSON.stringify(b));
},
});

0 comments on commit 3df385a

Please sign in to comment.