Skip to content

Commit 1d0033e

Browse files
authored
add result focus button and mode (#298)
1 parent 9c79840 commit 1d0033e

File tree

1 file changed

+45
-42
lines changed

1 file changed

+45
-42
lines changed

ui/src/components/nodes/Code.tsx

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function Timer({ lastExecutedAt }) {
7575
return <Box>Last executed: {timeDifference(new Date(), lastExecutedAt)}</Box>;
7676
}
7777

78-
export const ResultBlock = memo<any>(function ResultBlock({ id }) {
78+
export const ResultBlock = memo<any>(function ResultBlock({ id, layout }) {
7979
const store = useContext(RepoContext)!;
8080
const result = useStore(store, (state) => state.pods[id].result);
8181
const error = useStore(store, (state) => state.pods[id].error);
@@ -90,10 +90,43 @@ export const ResultBlock = memo<any>(function ResultBlock({ id }) {
9090
(state) => state.pods[id].lastExecutedAt
9191
);
9292
const [showOutput, setShowOutput] = useState(true);
93+
const hasResult = useStore(
94+
store,
95+
(state) =>
96+
state.pods[id]?.running ||
97+
state.pods[id]?.result ||
98+
state.pods[id]?.error ||
99+
state.pods[id]?.stdout ||
100+
state.pods[id]?.stderr
101+
);
102+
const [resultScroll, setResultScroll] = useState(false);
93103
const clearResults = useStore(store, (state) => state.clearResults);
104+
if (!hasResult) return <></>;
94105
return (
95106
<Box
107+
// This ID is used for autolayout.
108+
//
109+
// TODO save result box position to DB.
110+
id={layout === "right" ? `result-${id}-right` : `result-${id}-bottom`}
111+
// This also prevents the wheel event from bubbling up to the parent.
112+
// onWheelCapture={(e) => {
113+
// e.stopPropagation();
114+
// }}
115+
className={showOutput && resultScroll ? "nowheel" : ""}
96116
sx={{
117+
border:
118+
showOutput && resultScroll ? "solid 1px red" : "solid 1px #d6dee6",
119+
borderRadius: "4px",
120+
position: "absolute",
121+
top: layout === "right" ? 0 : "100%",
122+
left: layout === "right" ? "100%" : 0,
123+
...(layout === "right"
124+
? { minWidth: "250px" }
125+
: { maxWidth: "100%", minWidth: "100%" }),
126+
boxSizing: "border-box",
127+
backgroundColor: "white",
128+
zIndex: 100,
129+
padding: "0 10px",
97130
userSelect: "text",
98131
cursor: "auto",
99132
}}
@@ -174,6 +207,15 @@ export const ResultBlock = memo<any>(function ResultBlock({ id }) {
174207
variant="text"
175208
aria-label="outlined primary button group"
176209
>
210+
<Button
211+
onClick={() => {
212+
setResultScroll(!resultScroll);
213+
}}
214+
variant="text"
215+
size="small"
216+
>
217+
{resultScroll ? "Unfocus" : "Focus"}
218+
</Button>
177219
<Button
178220
onClick={() => {
179221
setShowOutput(!showOutput);
@@ -432,7 +474,6 @@ export const CodeNode = memo<NodeProps>(function ({
432474
const devMode = useStore(store, (state) => state.devMode);
433475
// right, bottom
434476
const [layout, setLayout] = useState("bottom");
435-
const isRightLayout = layout === "right";
436477
const setPodName = useStore(store, (state) => state.setPodName);
437478
const setPodGeo = useStore(store, (state) => state.setPodGeo);
438479
const getPod = useStore(store, (state) => state.getPod);
@@ -444,15 +485,6 @@ export const CodeNode = memo<NodeProps>(function ({
444485
const updateView = useStore(store, (state) => state.updateView);
445486
const isCutting = useStore(store, (state) => state.cuttingIds.has(id));
446487

447-
const showResult = useStore(
448-
store,
449-
(state) =>
450-
state.pods[id]?.running ||
451-
state.pods[id]?.result ||
452-
state.pods[id]?.error ||
453-
state.pods[id]?.stdout ||
454-
state.pods[id]?.stderr
455-
);
456488
const nodesMap = useStore(store, (state) => state.ydoc.getMap<Node>("pods"));
457489
const autoLayoutROOT = useStore(store, (state) => state.autoLayoutROOT);
458490
useEffect(() => {
@@ -757,37 +789,8 @@ export const CodeNode = memo<NodeProps>(function ({
757789
}}
758790
>
759791
<MyMonaco id={id} fontSize={fontSize} />
760-
{showResult && (
761-
<Box
762-
className={"nowheel"}
763-
// This ID is used for autolayout.
764-
//
765-
// TODO save result box position to DB.
766-
id={
767-
isRightLayout ? `result-${id}-right` : `result-${id}-bottom`
768-
}
769-
// This also prevents the wheel event from bubbling up to the parent.
770-
// onWheelCapture={(e) => {
771-
// e.stopPropagation();
772-
// }}
773-
sx={{
774-
border: "solid 1px #d6dee6",
775-
borderRadius: "4px",
776-
position: "absolute",
777-
top: isRightLayout ? 0 : "100%",
778-
left: isRightLayout ? "100%" : 0,
779-
...(isRightLayout
780-
? { minWidth: "250px" }
781-
: { maxWidth: "100%", minWidth: "100%" }),
782-
boxSizing: "border-box",
783-
backgroundColor: "white",
784-
zIndex: 100,
785-
padding: "0 10px",
786-
}}
787-
>
788-
<ResultBlock id={id} />
789-
</Box>
790-
)}
792+
793+
<ResultBlock id={id} layout={layout} />
791794
</Box>
792795
</Box>
793796
)}

0 commit comments

Comments
 (0)