use Splitter for debugger layout (#3383)

This commit is contained in:
Jonathan Dobson
2025-09-06 13:49:54 -07:00
committed by GitHub
parent 2e7cc94a9e
commit 68a88706f7
4 changed files with 347 additions and 187 deletions

View File

@@ -3,7 +3,71 @@ import { useMountEffect } from "@/hooks/useMountEffect";
import { cn } from "@/util/utils"; import { cn } from "@/util/utils";
import { useOnChange } from "@/hooks/useOnChange"; import { useOnChange } from "@/hooks/useOnChange";
function Handle({
direction,
isDragging,
onDoubleClick,
}: {
direction: "vertical" | "horizontal";
isDragging: boolean;
onDoubleClick?: () => void;
}) {
return (
<div
className={cn(
"absolute flex h-[1.25rem] w-[10px] flex-wrap items-center justify-center gap-[2px] bg-slate-800 pb-1 pt-1",
{
"cursor-col-resize": direction === "vertical",
"cursor-row-resize": direction === "horizontal",
"bg-slate-700": isDragging,
},
)}
onDoubleClick={() => onDoubleClick?.()}
>
<div className="flex w-full items-center justify-center gap-[0.15rem]">
<div
className={cn("h-[2px] w-[2px] rounded-full bg-[#666]", {
"bg-[#222]": isDragging,
})}
/>
<div
className={cn("h-[2px] w-[2px] rounded-full bg-[#666]", {
"bg-[#222]": isDragging,
})}
/>
</div>
<div className="flex w-full items-center justify-center gap-[0.15rem]">
<div
className={cn("h-[2px] w-[2px] rounded-full bg-[#666]", {
"bg-[#222]": isDragging,
})}
/>
<div
className={cn("h-[2px] w-[2px] rounded-full bg-[#666]", {
"bg-[#222]": isDragging,
})}
/>
</div>
<div className="flex w-full items-center justify-center gap-[0.15rem]">
<div
className={cn("h-[2px] w-[2px] rounded-full bg-[#666]", {
"bg-[#222]": isDragging,
})}
/>
<div
className={cn("h-[2px] w-[2px] rounded-full bg-[#666]", {
"bg-[#222]": isDragging,
})}
/>
</div>
</div>
);
}
interface Props { interface Props {
className?: string;
classNameLeft?: string;
classNameRight?: string;
/** /**
* The direction of the splitter. If "vertical", the split bar is vertical, * The direction of the splitter. If "vertical", the split bar is vertical,
* etc. * etc.
@@ -38,6 +102,10 @@ interface Props {
* key. * key.
*/ */
storageKey?: string; storageKey?: string;
/**
* Callback fired when the splitter is resized
*/
onResize?: () => void;
} }
type SizingTarget = "left" | "right" | "top" | "bottom"; type SizingTarget = "left" | "right" | "top" | "bottom";
@@ -196,7 +264,16 @@ const setStoredSizing = (
localStorage.setItem(key, sizing); localStorage.setItem(key, sizing);
}; };
function Splitter({ children, direction, split, storageKey }: Props) { function Splitter({
children,
className,
classNameLeft,
classNameRight,
direction,
split,
storageKey,
onResize,
}: Props) {
if (!Array.isArray(children) || children.length !== 2) { if (!Array.isArray(children) || children.length !== 2) {
throw new Error("Splitter must have exactly two children"); throw new Error("Splitter must have exactly two children");
} }
@@ -240,7 +317,9 @@ function Splitter({ children, direction, split, storageKey }: Props) {
const newWidth = (newPixelPos / maxSize) * 100; const newWidth = (newPixelPos / maxSize) * 100;
const clampedWidth = Math.max(0, Math.min(newWidth, 100)); const clampedWidth = Math.max(0, Math.min(newWidth, 100));
setIsClosed(false);
setSplitPosition(clampedWidth); setSplitPosition(clampedWidth);
onResize?.();
}; };
const onMouseUp = () => { const onMouseUp = () => {
@@ -248,6 +327,7 @@ function Splitter({ children, direction, split, storageKey }: Props) {
document.body.classList.remove("no-select-global"); document.body.classList.remove("no-select-global");
document.removeEventListener("mousemove", onMouseMove); document.removeEventListener("mousemove", onMouseMove);
document.removeEventListener("mouseup", onMouseUp); document.removeEventListener("mouseup", onMouseUp);
onResize?.();
}; };
document.addEventListener("mousemove", onMouseMove); document.addEventListener("mousemove", onMouseMove);
@@ -255,6 +335,9 @@ function Splitter({ children, direction, split, storageKey }: Props) {
}; };
const [splitPosition, setSplitPosition] = useState<number>(50); const [splitPosition, setSplitPosition] = useState<number>(50);
const [isClosed, setIsClosed] = useState(false);
const [closedSplitPosition, setClosedSplitPosition] =
useState<number>(splitPosition);
const [isDragging, setIsDragging] = useState(false); const [isDragging, setIsDragging] = useState(false);
useMountEffect(() => { useMountEffect(() => {
@@ -287,21 +370,51 @@ function Splitter({ children, direction, split, storageKey }: Props) {
} }
}); });
/**
* A "snap" is:
* - if the splitter is not "closed", then "close it"
* - if the splitter is "closed", then "open it"
*
* "closed" depends on the `split` prop definition. For instance, if the
* `split` prop has `left` defined, then "closing" is the `left` side
* resizing down to 0.
*
* When "closing", the current splitPosition should be memorized and then
* returned to when an "open" happens.
*/
const snap = () => {
if (isClosed) {
setSplitPosition(closedSplitPosition);
} else {
setClosedSplitPosition(splitPosition);
setSplitPosition(0);
}
setIsClosed(!isClosed);
onResize?.();
};
return ( return (
<div <div
className={cn( className={cn(
"splitter flex h-full w-full overflow-hidden", "splitter flex h-full w-full overflow-hidden",
direction === "vertical" ? "flex-row" : "flex-col", direction === "vertical" ? "flex-row" : "flex-col",
className || "",
)} )}
ref={containerRef} ref={containerRef}
> >
{direction === "vertical" ? ( {direction === "vertical" ? (
<> <>
<div <div
className={cn("left h-full", { className={cn(
"left h-full",
{
"pointer-events-none cursor-col-resize select-none opacity-80": "pointer-events-none cursor-col-resize select-none opacity-80":
isDragging, isDragging,
})} "overflow-x-hidden": direction === "vertical",
"overflow-y-hidden": direction !== "vertical",
},
classNameLeft,
)}
style={{ style={{
width: `calc(${splitPosition}% - (${splitterThickness} / 2))`, width: `calc(${splitPosition}% - (${splitterThickness} / 2))`,
}} }}
@@ -310,16 +423,34 @@ function Splitter({ children, direction, split, storageKey }: Props) {
</div> </div>
<div <div
className={cn( className={cn(
"splitter-bar z-[0] h-full w-[5px] cursor-col-resize bg-[#ccc] opacity-10 hover:opacity-90", "splitter-bar relative z-[0] flex h-full w-[10px] cursor-col-resize items-center justify-center opacity-50 hover:opacity-100",
{ "opacity-90": isDragging }, { "opacity-90": isDragging },
)} )}
onMouseDown={onMouseDown} onMouseDown={onMouseDown}
></div> onDoubleClick={snap}
>
<div <div
className={cn("right h-full", { className={cn("h-full w-[2px] bg-slate-800", {
"bg-slate-700": isDragging,
})}
/>
<Handle
direction={direction}
isDragging={isDragging}
onDoubleClick={snap}
/>
</div>
<div
className={cn(
"right h-full",
{
"pointer-events-none cursor-col-resize select-none opacity-80": "pointer-events-none cursor-col-resize select-none opacity-80":
isDragging, isDragging,
})} "overflow-x-hidden": direction === "vertical",
"overflow-y-hidden": direction !== "vertical",
},
classNameRight,
)}
style={{ style={{
width: `calc(100% - ${splitPosition}% - (${splitterThickness} / 2))`, width: `calc(100% - ${splitPosition}% - (${splitterThickness} / 2))`,
}} }}

View File

@@ -221,6 +221,7 @@ function convertToParametersYAML(
type Props = { type Props = {
hideBackground?: boolean; hideBackground?: boolean;
hideControls?: boolean;
nodes: Array<AppNode>; nodes: Array<AppNode>;
edges: Array<Edge>; edges: Array<Edge>;
setNodes: (nodes: Array<AppNode>) => void; setNodes: (nodes: Array<AppNode>) => void;
@@ -233,10 +234,12 @@ type Props = {
onDebuggableBlockCountChange?: (count: number) => void; onDebuggableBlockCountChange?: (count: number) => void;
onMouseDownCapture?: () => void; onMouseDownCapture?: () => void;
zIndex?: number; zIndex?: number;
onContainerResize?: number;
}; };
function FlowRenderer({ function FlowRenderer({
hideBackground = false, hideBackground = false,
hideControls = false,
nodes, nodes,
edges, edges,
setNodes, setNodes,
@@ -249,6 +252,7 @@ function FlowRenderer({
onDebuggableBlockCountChange, onDebuggableBlockCountChange,
onMouseDownCapture, onMouseDownCapture,
zIndex, zIndex,
onContainerResize,
}: Props) { }: Props) {
const reactFlowInstance = useReactFlow(); const reactFlowInstance = useReactFlow();
const debugStore = useDebugStore(); const debugStore = useDebugStore();
@@ -485,14 +489,34 @@ function FlowRenderer({
useAutoPan(editorElementRef, nodes); useAutoPan(editorElementRef, nodes);
useEffect(() => {
doLayout(nodes, edges);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onContainerResize]);
const zoomLock = 1 as const; const zoomLock = 1 as const;
const yLockMax = 140 as const; const yLockMax = 140 as const;
/** /**
* TODO(jdo): hack * TODO(jdo): hack
*
* Locks the x position of the flow to an ideal x based on the ideal width
* of the flow. The ideal width is based on differently-width'd blocks.
*/ */
const getXLock = () => { const getXLock = () => {
const rect = editorElementRef.current?.getBoundingClientRect();
if (!rect) {
return 24; return 24;
}
const width = rect.width;
const hasLoopBlock = nodes.some((node) => node.type === "loop");
const hasHttpBlock = nodes.some((node) => node.type === "http_request");
const idealWidth = hasHttpBlock ? 580 : hasLoopBlock ? 498 : 475;
const split = (width - idealWidth) / 2;
return Math.max(24, split);
}; };
useOnChange(debugStore.isDebugMode, (newValue) => { useOnChange(debugStore.isDebugMode, (newValue) => {
@@ -673,7 +697,7 @@ function FlowRenderer({
{!hideBackground && ( {!hideBackground && (
<Background variant={BackgroundVariant.Dots} bgColor="#020617" /> <Background variant={BackgroundVariant.Dots} bgColor="#020617" />
)} )}
<Controls position="bottom-left" /> {!hideControls && <Controls position="bottom-left" />}
</ReactFlow> </ReactFlow>
</BlockActionContext.Provider> </BlockActionContext.Provider>
</div> </div>

View File

@@ -28,6 +28,7 @@ import {
PowerButton, PowerButton,
ReloadButton, ReloadButton,
} from "@/components/FloatingWindow"; } from "@/components/FloatingWindow";
import { Splitter } from "@/components/Splitter";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@@ -127,6 +128,7 @@ function Workspace({
const [showPowerButton, setShowPowerButton] = useState(true); const [showPowerButton, setShowPowerButton] = useState(true);
const [reloadKey, setReloadKey] = useState(0); const [reloadKey, setReloadKey] = useState(0);
const [windowResizeTrigger, setWindowResizeTrigger] = useState(0); const [windowResizeTrigger, setWindowResizeTrigger] = useState(0);
const [containerResizeTrigger, setContainerResizeTrigger] = useState(0);
const [isReloading, setIsReloading] = useState(false); const [isReloading, setIsReloading] = useState(false);
const credentialGetter = useCredentialGetter(); const credentialGetter = useCredentialGetter();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@@ -206,10 +208,10 @@ function Workspace({
const hasLoopBlock = nodes.some((node) => node.type === "loop"); const hasLoopBlock = nodes.some((node) => node.type === "loop");
const hasHttpBlock = nodes.some((node) => node.type === "http_request"); const hasHttpBlock = nodes.some((node) => node.type === "http_request");
const workflowWidth = hasHttpBlock const workflowWidth = hasHttpBlock
? "39rem" ? "35.1rem"
: hasLoopBlock : hasLoopBlock
? "34.25rem" ? "31.25rem"
: "33rem"; : "30rem";
/** /**
* Open a new tab (not window) with the browser session URL. * Open a new tab (not window) with the browser session URL.
@@ -762,16 +764,18 @@ function Workspace({
{/* infinite canvas, sub panels, browser, and timeline when in debug mode */} {/* infinite canvas, sub panels, browser, and timeline when in debug mode */}
{showBrowser && ( {showBrowser && (
<div className="relative flex h-full w-full overflow-hidden overflow-x-hidden"> <div className="relative flex h-full w-full overflow-hidden overflow-x-hidden">
{/* infinite canvas */} <Splitter
<div className="splittah"
className="skyvern-split-left h-full" classNameLeft="flex items-center justify-center"
style={{ direction="vertical"
width: workflowWidth, split={{ left: workflowWidth }}
maxWidth: workflowWidth, onResize={() => setContainerResizeTrigger((prev) => prev + 1)}
}}
> >
{/* infinite canvas */}
<div className="skyvern-split-left h-full w-full">
<FlowRenderer <FlowRenderer
hideBackground={true} hideBackground={true}
hideControls={true}
nodes={nodes} nodes={nodes}
edges={edges} edges={edges}
setNodes={setNodes} setNodes={setNodes}
@@ -780,19 +784,12 @@ function Workspace({
onEdgesChange={onEdgesChange} onEdgesChange={onEdgesChange}
initialTitle={initialTitle} initialTitle={initialTitle}
workflow={workflow} workflow={workflow}
onContainerResize={containerResizeTrigger}
/> />
</div> </div>
{/* divider*/}
<div className="mt-[8rem] h-[calc(100%_-_8rem)] w-[1px] bg-slate-800" />
{/* browser & timeline & sub-panels in debug mode */} {/* browser & timeline & sub-panels in debug mode */}
<div <div className="skyvern-split-right relative flex h-full items-end justify-center bg-[#020617] p-4 pl-6">
className="skyvern-split-right relative flex h-full items-end justify-center bg-[#020617] p-4 pl-6"
style={{
width: `calc(100% - ${workflowWidth})`,
}}
>
{/* sub panels */} {/* sub panels */}
{workflowPanelState.active && ( {workflowPanelState.active && (
<div <div
@@ -871,7 +868,9 @@ function Workspace({
"mr-16": !blockLabel, "mr-16": !blockLabel,
})} })}
> >
{showPowerButton && <PowerButton onClick={() => cycle()} />} {showPowerButton && (
<PowerButton onClick={() => cycle()} />
)}
<ReloadButton <ReloadButton
isReloading={isReloading} isReloading={isReloading}
onClick={() => reload()} onClick={() => reload()}
@@ -951,6 +950,7 @@ function Workspace({
</div> </div>
</div> </div>
</div> </div>
</Splitter>
</div> </div>
)} )}
</div> </div>

View File

@@ -21,3 +21,8 @@
.react-flow__handle-bottom { .react-flow__handle-bottom {
bottom: 3px; bottom: 3px;
} }
.react-flow__attribution {
background-color: rgb(2 6 23);
color: white;
}