Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add button to control output #71

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions ui/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {

// 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.

function ResultBlock({ pod, id }) {
function ResultBlock({ pod, id, showOutput = true }) {
const store = useContext(RepoContext);
if (!store) throw new Error("Missing BearContext.Provider in the tree");
const wsRun = useStore(store, (state) => state.wsRun);
Expand Down Expand Up @@ -231,7 +231,7 @@ function ResultBlock({ pod, id }) {
)}

{pod.running && <CircularProgress />}
<Box overflow="scroll" maxHeight="145px" border="1px">
{ showOutput && <Box overflow="scroll" maxHeight="145px" border="1px">
{/* <Box bgcolor="lightgray">Error</Box> */}
{pod.stdout && (
<Box whiteSpace="pre-wrap" sx={{fontSize: 10}}>
Expand All @@ -255,7 +255,7 @@ function ResultBlock({ pod, id }) {
</Box>
</Box>
)}
</Box>
</Box>}
</Box>
);
}
Expand All @@ -270,6 +270,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
const [frame] = React.useState({
translate: [0, 0],
});
const [showOutput,setShowOutput] = useState(true);
// right, bottom
const [layout, setLayout] = useState("bottom");
const isRightLayout = layout === "right";
Expand Down Expand Up @@ -307,6 +308,8 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
case ToolTypes.layout:
setLayout(layout === "bottom" ? "right" : "bottom");
break;
case ToolTypes.fold:
setShowOutput(!showOutput);
}
};

Expand Down Expand Up @@ -353,7 +356,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
{/* The header of code pods. */}
<Box className="custom-drag-handle">
<Box sx={styles["pod-index"]}>[{pod.index}]</Box>
<ToolBox data={{ id }} onRunTask={runToolBoxTask}></ToolBox>
<ToolBox data={{ id, showOutput }} onRunTask={runToolBoxTask}></ToolBox>
</Box>
<Box
sx={{
Expand Down Expand Up @@ -404,7 +407,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
padding: "0 10px",
}}
>
<ResultBlock pod={pod} id={id} />
<ResultBlock pod={pod} id={id} showOutput={showOutput}/>
</Box>
)}
</Box>
Expand Down
33 changes: 25 additions & 8 deletions ui/src/components/Toolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { Tooltip, Box, IconButton } from "@mui/material";
import PlayCircleOutlineIcon from "@mui/icons-material/PlayCircleOutline";
import DeleteIcon from "@mui/icons-material/Delete";
import ViewComfyIcon from "@mui/icons-material/ViewComfy";
import UnfoldLessIcon from "@mui/icons-material/UnfoldLess";
import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore";

export enum ToolTypes {
delete,
play,
layout,
fold,
}
export default function ToolBox({
visible = true,
Expand Down Expand Up @@ -43,14 +46,14 @@ export default function ToolBox({
</IconButton>
</Tooltip>
<Tooltip title="Delete">
<IconButton
size="small"
onClick={() => {
onRunTask && onRunTask(ToolTypes.delete, data);
}}
>
<DeleteIcon fontSize="inherit" />
</IconButton>
<IconButton
size="small"
onClick={() => {
onRunTask && onRunTask(ToolTypes.delete, data);
}}
>
<DeleteIcon fontSize="inherit" />
</IconButton>
</Tooltip>
<Tooltip title="Change layout">
<IconButton
Expand All @@ -62,6 +65,20 @@ export default function ToolBox({
<ViewComfyIcon fontSize="inherit" />
</IconButton>
</Tooltip>
<Tooltip title={data.showOutput ? "Fold output" : "Unfold output"}>
<IconButton
size="small"
onClick={() => {
onRunTask && onRunTask(ToolTypes.fold, data);
}}
>
{data.showOutput ? (
<UnfoldLessIcon fontSize="inherit" />
) : (
<UnfoldMoreIcon fontSize="inherit" />
)}
</IconButton>
</Tooltip>
</Box>
);
}