Skip to content

Commit af3e99b

Browse files
authored
feat: add button to control output (#71)
1 parent cee4600 commit af3e99b

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

ui/src/components/Canvas.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
189189

190190
// FIXME: the resultblock is rendered every time the parent codeNode changes (e.g., dragging), we may set the result number as a state of a pod to memoize the resultblock.
191191

192-
function ResultBlock({ pod, id }) {
192+
function ResultBlock({ pod, id, showOutput = true }) {
193193
const store = useContext(RepoContext);
194194
if (!store) throw new Error("Missing BearContext.Provider in the tree");
195195
const wsRun = useStore(store, (state) => state.wsRun);
@@ -232,7 +232,7 @@ function ResultBlock({ pod, id }) {
232232
)}
233233

234234
{pod.running && <CircularProgress />}
235-
<Box overflow="scroll" maxHeight="145px" border="1px">
235+
{ showOutput && <Box overflow="scroll" maxHeight="145px" border="1px">
236236
{/* <Box bgcolor="lightgray">Error</Box> */}
237237
{pod.stdout && (
238238
<Box whiteSpace="pre-wrap" sx={{fontSize: 10}}>
@@ -256,7 +256,7 @@ function ResultBlock({ pod, id }) {
256256
</Box>
257257
</Box>
258258
)}
259-
</Box>
259+
</Box>}
260260
</Box>
261261
);
262262
}
@@ -271,6 +271,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
271271
const [frame] = React.useState({
272272
translate: [0, 0],
273273
});
274+
const [showOutput,setShowOutput] = useState(true);
274275
// right, bottom
275276
const [layout, setLayout] = useState("bottom");
276277
const isRightLayout = layout === "right";
@@ -325,6 +326,8 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
325326
case ToolTypes.layout:
326327
setLayout(layout === "bottom" ? "right" : "bottom");
327328
break;
329+
case ToolTypes.fold:
330+
setShowOutput(!showOutput);
328331
}
329332
};
330333

@@ -378,7 +381,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
378381
{/* The header of code pods. */}
379382
<Box className="custom-drag-handle">
380383
<Box sx={styles["pod-index"]}>[{pod.index}]</Box>
381-
<ToolBox data={{ id }} onRunTask={runToolBoxTask}></ToolBox>
384+
<ToolBox data={{ id, showOutput }} onRunTask={runToolBoxTask}></ToolBox>
382385
</Box>
383386
<Box
384387
sx={{
@@ -430,7 +433,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
430433
padding: "0 10px",
431434
}}
432435
>
433-
<ResultBlock pod={pod} id={id} />
436+
<ResultBlock pod={pod} id={id} showOutput={showOutput}/>
434437
</Box>
435438
)}
436439
</Box>

ui/src/components/Toolbox.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { Tooltip, Box, IconButton } from "@mui/material";
22
import PlayCircleOutlineIcon from "@mui/icons-material/PlayCircleOutline";
33
import DeleteIcon from "@mui/icons-material/Delete";
44
import ViewComfyIcon from "@mui/icons-material/ViewComfy";
5+
import UnfoldLessIcon from "@mui/icons-material/UnfoldLess";
6+
import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore";
57

68
export enum ToolTypes {
79
delete,
810
play,
911
layout,
12+
fold,
1013
}
1114
export default function ToolBox({
1215
visible = true,
@@ -43,14 +46,14 @@ export default function ToolBox({
4346
</IconButton>
4447
</Tooltip>
4548
<Tooltip title="Delete">
46-
<IconButton
47-
size="small"
48-
onClick={() => {
49-
onRunTask && onRunTask(ToolTypes.delete, data);
50-
}}
51-
>
52-
<DeleteIcon fontSize="inherit" />
53-
</IconButton>
49+
<IconButton
50+
size="small"
51+
onClick={() => {
52+
onRunTask && onRunTask(ToolTypes.delete, data);
53+
}}
54+
>
55+
<DeleteIcon fontSize="inherit" />
56+
</IconButton>
5457
</Tooltip>
5558
<Tooltip title="Change layout">
5659
<IconButton
@@ -62,6 +65,20 @@ export default function ToolBox({
6265
<ViewComfyIcon fontSize="inherit" />
6366
</IconButton>
6467
</Tooltip>
68+
<Tooltip title={data.showOutput ? "Fold output" : "Unfold output"}>
69+
<IconButton
70+
size="small"
71+
onClick={() => {
72+
onRunTask && onRunTask(ToolTypes.fold, data);
73+
}}
74+
>
75+
{data.showOutput ? (
76+
<UnfoldLessIcon fontSize="inherit" />
77+
) : (
78+
<UnfoldMoreIcon fontSize="inherit" />
79+
)}
80+
</IconButton>
81+
</Tooltip>
6582
</Box>
6683
);
6784
}

0 commit comments

Comments
 (0)