Skip to content

Automate browser based workflows with AI

feat(SKY-11814): jump-to-start/end buttons for long workflows (#7104)

Celal Zamanoğlu3672af57da4c
diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
index c106e5379..5e2f38fdf 100644
--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
@@ -108,6 +108,7 @@ import {
} from "./paneFit";
import { WorkflowScopeContext } from "./WorkflowScopeContext";
import { FitViewControl } from "./controls/FitViewControl";
+import { FlowJumpControls } from "./controls/FlowJumpControls";
import { RedoControl } from "./controls/RedoControl";
import { ToggleInteractivityControl } from "./controls/ToggleInteractivityControl";
import { UndoControl } from "./controls/UndoControl";
@@ -2315,6 +2316,18 @@ function FlowRenderer({
<GlobalCollapseControl />
</Controls>
)}
+ {/*
+ Studio-only: the jumps land on the pane-fit anchor
+ viewports, which are the embedded pane's policy; the legacy
+ editors keep whole-graph fitView and the debugger pins the
+ viewport (constrainPan), so both are excluded. Mounted only
+ once the initial layout settled so pre-layout bounds can't
+ flash the buttons.
+ */}
+ {embedded &&
+ !readOnly &&
+ !flowIsConstrained &&
+ layoutPhase === "ready" && <FlowJumpControls nodes={nodes} />}
</ReactFlow>
</SortableBlockScope>
{/*
diff --git a/skyvern-frontend/src/routes/workflows/editor/controls/FlowJumpControls.test.tsx b/skyvern-frontend/src/routes/workflows/editor/controls/FlowJumpControls.test.tsx
new file mode 100644
index 000000000..f57b53614
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/editor/controls/FlowJumpControls.test.tsx
@@ -0,0 +1,226 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { getNodesBounds } from "@xyflow/react";
+import type { CSSProperties, ReactNode } from "react";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+
+import { TooltipProvider } from "@/components/ui/tooltip";
+
+import type { AppNode } from "../nodes";
+import { endAnchoredViewport, startAnchoredViewport } from "../paneFit";
+
+import { FlowJumpControls } from "./FlowJumpControls";
+
+// The studio shell provides the Radix tooltip context in production.
+function renderControls(nodes: Array<AppNode>) {
+ return render(
+ <TooltipProvider delayDuration={0}>
+ <FlowJumpControls nodes={nodes} />
+ </TooltipProvider>,
+ );
+}
+
+const mocks = vi.hoisted(() => ({
+ setViewport: vi.fn(),
+ getNodes: vi.fn((): Array<unknown> => []),
+ storeState: {
+ width: 800,
+ height: 600,
+ transform: [150, 24, 1] as [number, number, number],
+ domNode: null as HTMLElement | null,
+ },
+}));
+
+vi.mock("@xyflow/react", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@xyflow/react")>();
+ return {
+ ...actual,
+ Panel: ({
+ children,
+ position,
+ style,
+ }: {
+ children?: ReactNode;
+ position?: string;
+ style?: CSSProperties;
+ }) => (
+ <div data-testid={`panel-${position}`} style={style}>
+ {children}
+ </div>
+ ),
+ useReactFlow: () => ({
+ setViewport: mocks.setViewport,
+ getNodes: mocks.getNodes,
+ }),
+ useStore: (selector: (state: unknown) => unknown) =>
+ selector(mocks.storeState),
+ };
+});
+
+function makeNode(
+ id: string,
+ y: number,
+ height: number,
+ hidden = false,
+): AppNode {
+ return {
+ id,
+ type: "task",
+ position: { x: 0, y },
+ measured: { width: 480, height },
+ hidden,
+ data: {},
+ } as unknown as AppNode;
+}
+
+// 4000 world px tall: far taller than the 600px pane at any anchor zoom.
+const longFlow = [makeNode("head", 0, 100), makeNode("tail", 3900, 100)];
+const shortFlow = [makeNode("head", 0, 400)];
+const pane = { width: 800, height: 600 };
+
+function stubMatchMedia(reducedMotion: boolean) {
+ vi.stubGlobal(
+ "matchMedia",
+ vi.fn(() => ({ matches: reducedMotion })),
+ );
+}
+
+// jsdom pane containing a fake Controls stack, with layout stubbed: the pane
+// bottom sits at y=600 and the stack's top at y=420.
+function stubPaneWithControls() {
+ const pane = document.createElement("div");
+ pane.getBoundingClientRect = () =>
+ ({ top: 0, bottom: 600, left: 0, right: 800 }) as DOMRect;
+ const controls = document.createElement("div");
+ controls.className = "react-flow__controls";
+ controls.getBoundingClientRect = () =>
+ ({ top: 420, bottom: 585, left: 15, right: 41 }) as DOMRect;
+ pane.appendChild(controls);
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ return pane;
+}
+
+describe("FlowJumpControls", () => {
+ beforeEach(() => {
+ mocks.storeState.width = pane.width;
+ mocks.storeState.height = pane.height;
+ mocks.storeState.transform = [150, 24, 1];
+ mocks.storeState.domNode = null;
+ mocks.getNodes.mockReturnValue(longFlow);
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ mocks.setViewport.mockReset();
+ mocks.getNodes.mockReset();
+ });
+
+ test("a flow that fits the pane shows neither button", () => {
+ renderControls(shortFlow);
+ expect(screen.queryByRole("button", { name: "Jump to start" })).toBeNull();
+ expect(screen.queryByRole("button", { name: "Jump to end" })).toBeNull();
+ });
+
+ test("hidden nodes do not extend the flow into jumpable territory", () => {
+ renderControls([...shortFlow, makeNode("collapsed", 5000, 100, true)]);
+ expect(screen.queryByRole("button", { name: "Jump to start" })).toBeNull();
+ expect(screen.queryByRole("button", { name: "Jump to end" })).toBeNull();
+ });
+
+ test("at the flow's start only the jump to its end shows", () => {
+ renderControls(longFlow);
+ expect(screen.queryByRole("button", { name: "Jump to start" })).toBeNull();
+ expect(screen.getByRole("button", { name: "Jump to end" })).toBeInstanceOf(
+ HTMLButtonElement,
+ );
+ });
+
+ test("at the flow's end only the jump back to its start shows", () => {
+ mocks.storeState.transform = [150, 600 - 24 - 4000, 1];
+ renderControls(longFlow);
+ expect(
+ screen.getByRole("button", { name: "Jump to start" }),
+ ).toBeInstanceOf(HTMLButtonElement);
+ expect(screen.queryByRole("button", { name: "Jump to end" })).toBeNull();
+ });
+
+ test("scrolled mid-flow shows both jumps", () => {
+ mocks.storeState.transform = [150, -1700, 1];
+ renderControls(longFlow);
+ expect(
+ screen.getByRole("button", { name: "Jump to start" }),
+ ).toBeInstanceOf(HTMLButtonElement);
+ expect(screen.getByRole("button", { name: "Jump to end" })).toBeInstanceOf(
+ HTMLButtonElement,
+ );
+ });
+
+ test("both buttons mount on the left rail (top-left / bottom-left panels)", () => {
+ mocks.storeState.transform = [150, -1700, 1];
+ renderControls(longFlow);
+ expect(
+ screen
+ .getByTestId("panel-top-left")
+ .contains(screen.getByRole("button", { name: "Jump to start" })),
+ ).toBe(true);
+ expect(
+ screen
+ .getByTestId("panel-bottom-left")
+ .contains(screen.getByRole("button", { name: "Jump to end" })),
+ ).toBe(true);
+ });
+
+ test("the bottom panel clears the Controls stack by the measured height plus gap", () => {
+ mocks.storeState.domNode = stubPaneWithControls();
+ mocks.storeState.transform = [150, -1700, 1];
+ renderControls(longFlow);
+ // Pane bottom 600 - controls top 420 + 8px gap.
+ expect(screen.getByTestId("panel-bottom-left").style.marginBottom).toBe(
+ "188px",
+ );
+ });
+
+ test("without a Controls stack the bottom panel keeps its default inset", () => {
+ mocks.storeState.transform = [150, -1700, 1];
+ renderControls(longFlow);
+ expect(screen.getByTestId("panel-bottom-left").style.marginBottom).toBe("");
+ });
+
+ test("jump to end pans to the end anchor of the visible nodes", () => {
+ stubMatchMedia(false);
+ const hiddenOutlier = makeNode("collapsed", 9000, 100, true);
+ mocks.getNodes.mockReturnValue([...longFlow, hiddenOutlier]);
+ renderControls([...longFlow, hiddenOutlier]);
+
+ fireEvent.click(screen.getByRole("button", { name: "Jump to end" }));
+
+ expect(mocks.setViewport).toHaveBeenCalledTimes(1);
+ expect(mocks.setViewport).toHaveBeenCalledWith(
+ endAnchoredViewport({ pane, bounds: getNodesBounds(longFlow) }),
+ { duration: 150 },
+ );
+ });
+
+ test("jump to start pans to the start anchor, instant under reduced motion", () => {
+ stubMatchMedia(true);
+ mocks.storeState.transform = [150, 600 - 24 - 4000, 1];
+ renderControls(longFlow);
+
+ fireEvent.click(screen.getByRole("button", { name: "Jump to start" }));
+
+ expect(mocks.setViewport).toHaveBeenCalledTimes(1);
+ expect(mocks.setViewport).toHaveBeenCalledWith(
+ startAnchoredViewport({ pane, bounds: getNodesBounds(longFlow) }),
+ { duration: 0 },
+ );
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/editor/controls/FlowJumpControls.tsx b/skyvern-frontend/src/routes/workflows/editor/controls/FlowJumpControls.tsx
new file mode 100644
index 000000000..b5ed68b5c
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/editor/controls/FlowJumpControls.tsx
@@ -0,0 +1,163 @@
+import { PinBottomIcon, PinTopIcon } from "@radix-ui/react-icons";
+import {
+ getNodesBounds,
+ Panel,
+ useReactFlow,
+ useStore,
+ type ReactFlowState,
+} from "@xyflow/react";
+import { useCallback, useEffect, useMemo, useState } from "react";
+
+import { Button } from "@/components/ui/button";
+
+import { ControlTooltip } from "../../studio/ControlTooltip";
+import type { AppNode } from "../nodes";
+import {
+ endAnchoredViewport,
+ flowJumpVisibility,
+ paneRefitDuration,
+ startAnchoredViewport,
+} from "../paneFit";
+
+const selectWidth = (state: ReactFlowState) => state.width;
+const selectHeight = (state: ReactFlowState) => state.height;
+const selectViewportX = (state: ReactFlowState) => state.transform[0];
+const selectViewportY = (state: ReactFlowState) => state.transform[1];
+const selectZoom = (state: ReactFlowState) => state.transform[2];
+const selectDomNode = (state: ReactFlowState) => state.domNode;
+
+const JUMP_CONTROLS_GAP_PX = 8;
+
+const jumpButtonClass =
+ "h-7 w-7 border-border bg-background/70 text-muted-foreground backdrop-blur hover:bg-background/90 hover:text-foreground";
+
+/**
+ * Contextual jump-to-start / jump-to-end buttons for long flows, sharing the
+ * canvas's left rail (the zoom/fit Controls' vertical axis): jump-to-start at
+ * the top-left corner, jump-to-end directly above the Controls stack. Each
+ * shows only while its end of the flow is scrolled out of view, and both hide
+ * when the whole flow fits the pane. The jumps land on the same start/end-
+ * anchored viewports the studio pane-fit policy uses, so a jump reads like
+ * the initial load anchored at that end.
+ */
+export function FlowJumpControls({ nodes }: { nodes: Array<AppNode> }) {
+ const reactFlowInstance = useReactFlow();
+ const paneWidth = useStore(selectWidth);
+ const paneHeight = useStore(selectHeight);
+ const viewportX = useStore(selectViewportX);
+ const viewportY = useStore(selectViewportY);
+ const zoom = useStore(selectZoom);
+ const domNode = useStore(selectDomNode);
+
+ // Bottom inset that keeps the jump-to-end button stacked above the
+ // Controls panel with a constant gap. Measured (not a constant) because
+ // the stack's height changes at runtime: the undo/redo controls collapse
+ // while their history is empty.
+ const [controlsClearancePx, setControlsClearancePx] = useState<number | null>(
+ null,
+ );
+ useEffect(() => {
+ if (!domNode) {
+ setControlsClearancePx(null);
+ return;
+ }
+ const controls = domNode.querySelector(".react-flow__controls");
+ if (!controls) {
+ setControlsClearancePx(null);
+ return;
+ }
+ const update = () => {
+ // Distance from the pane bottom to the stack's top edge; folds in the
+ // panel's own bottom margin so the button needs no margin constant.
+ const clearance =
+ domNode.getBoundingClientRect().bottom -
+ controls.getBoundingClientRect().top +
+ JUMP_CONTROLS_GAP_PX;
+ setControlsClearancePx(clearance > 0 ? clearance : null);
+ };
+ update();
+ const observer = new ResizeObserver(update);
+ observer.observe(controls);
+ return () => {
+ observer.disconnect();
+ };
+ }, [domNode]);
+
+ const bounds = useMemo(() => {
+ const visibleNodes = nodes.filter((node) => !node.hidden);
+ return visibleNodes.length > 0 ? getNodesBounds(visibleNodes) : null;
+ }, [nodes]);
+
+ const { showJumpToStart, showJumpToEnd } =
+ bounds === null
+ ? { showJumpToStart: false, showJumpToEnd: false }
+ : flowJumpVisibility({
+ pane: { width: paneWidth, height: paneHeight },
+ viewport: { x: viewportX, y: viewportY, zoom },
+ bounds,
+ });
+
+ const jumpTo = useCallback(
+ (anchoredViewport: typeof startAnchoredViewport) => {
+ const visibleNodes = reactFlowInstance
+ .getNodes()
+ .filter((node) => !node.hidden);
+ if (visibleNodes.length === 0) {
+ return;
+ }
+ const viewport = anchoredViewport({
+ pane: { width: paneWidth, height: paneHeight },
+ bounds: getNodesBounds(visibleNodes),
+ });
+ if (viewport === null) {
+ return;
+ }
+ reactFlowInstance.setViewport(viewport, {
+ duration: paneRefitDuration(),
+ });
+ },
+ [reactFlowInstance, paneWidth, paneHeight],
+ );
+
+ return (
+ <>
+ {showJumpToStart && (
+ <Panel position="top-left">
+ <ControlTooltip content="Jump to start" side="right">
+ <Button
+ variant="outline"
+ size="icon"
+ className={jumpButtonClass}
+ aria-label="Jump to start"
+ onClick={() => jumpTo(startAnchoredViewport)}
+ >
+ <PinTopIcon className="h-4 w-4" />
+ </Button>
+ </ControlTooltip>
+ </Panel>
+ )}
+ {showJumpToEnd && (
+ <Panel
+ position="bottom-left"
+ style={
+ controlsClearancePx === null
+ ? undefined
+ : { marginBottom: controlsClearancePx }
+ }
+ >
+ <ControlTooltip content="Jump to end" side="right">
+ <Button
+ variant="outline"
+ size="icon"
+ className={jumpButtonClass}
+ aria-label="Jump to end"
+ onClick={() => jumpTo(endAnchoredViewport)}
+ >
+ <PinBottomIcon className="h-4 w-4" />
+ </Button>
+ </ControlTooltip>
+ </Panel>
+ )}
+ </>
+ );
+}
diff --git a/skyvern-frontend/src/routes/workflows/editor/paneFit.test.ts b/skyvern-frontend/src/routes/workflows/editor/paneFit.test.ts
index 84391346e..ff9f461d9 100644
--- a/skyvern-frontend/src/routes/workflows/editor/paneFit.test.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/paneFit.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, test } from "vitest";
import {
+ END_ANCHOR_BOTTOM_PX,
+ endAnchoredViewport,
+ flowJumpVisibility,
isMeaningfulPaneResize,
isViewportStranded,
PANE_RESIZE_EPSILON_PX,
@@ -188,6 +191,137 @@ describe("startAnchoredViewport", () => {
});
});
+describe("endAnchoredViewport", () => {
+ const longChain = { x: 0, y: 0, width: 500, height: 4000 };
+
+ test("anchors the flow end just above the pane bottom at 1:1 zoom", () => {
+ expect(
+ endAnchoredViewport({
+ pane: { width: 800, height: 600 },
+ bounds: longChain,
+ }),
+ ).toEqual({ x: 150, y: 600 - END_ANCHOR_BOTTOM_PX - 4000, zoom: 1 });
+ });
+
+ test("mirrors the start anchor's zoom and horizontal centering", () => {
+ const pane = { width: 424, height: 600 };
+ const start = startAnchoredViewport({ pane, bounds: longChain });
+ const end = endAnchoredViewport({ pane, bounds: longChain });
+ expect(end).not.toBeNull();
+ expect(end!.zoom).toBe(start!.zoom);
+ expect(end!.x).toBe(start!.x);
+ // Screen-space position of the flow's bottom edge.
+ expect((longChain.y + longChain.height) * end!.zoom + end!.y).toBeCloseTo(
+ pane.height - END_ANCHOR_BOTTOM_PX,
+ );
+ });
+
+ test("offset bounds still land the flow bottom at the bottom margin", () => {
+ const bounds = { x: -100, y: 300, width: 500, height: 2000 };
+ const pane = { width: 800, height: 600 };
+ const viewport = endAnchoredViewport({ pane, bounds });
+ expect(viewport).not.toBeNull();
+ expect(
+ (bounds.y + bounds.height) * viewport!.zoom + viewport!.y,
+ ).toBeCloseTo(pane.height - END_ANCHOR_BOTTOM_PX);
+ });
+
+ test("degenerate panes and empty flows return null", () => {
+ expect(
+ endAnchoredViewport({
+ pane: { width: 0, height: 0 },
+ bounds: longChain,
+ }),
+ ).toBeNull();
+ expect(
+ endAnchoredViewport({
+ pane: { width: 800, height: 600 },
+ bounds: { x: 0, y: 0, width: 0, height: 0 },
+ }),
+ ).toBeNull();
+ });
+});
+
+describe("flowJumpVisibility", () => {
+ const pane = { width: 800, height: 600 };
+ const longChain = { x: 0, y: 0, width: 500, height: 4000 };
+
+ test("a start-anchored long flow only offers the jump to its end", () => {
+ const viewport = startAnchoredViewport({ pane, bounds: longChain });
+ expect(
+ flowJumpVisibility({ pane, viewport: viewport!, bounds: longChain }),
+ ).toEqual({ showJumpToStart: false, showJumpToEnd: true });
+ });
+
+ test("an end-anchored long flow only offers the jump back to its start", () => {
+ const viewport = endAnchoredViewport({ pane, bounds: longChain });
+ expect(
+ flowJumpVisibility({ pane, viewport: viewport!, bounds: longChain }),
+ ).toEqual({ showJumpToStart: true, showJumpToEnd: false });
+ });
+
+ test("scrolled into the middle of a long flow offers both jumps", () => {
+ expect(
+ flowJumpVisibility({
+ pane,
+ viewport: { x: 150, y: -1700, zoom: 1 },
+ bounds: longChain,
+ }),
+ ).toEqual({ showJumpToStart: true, showJumpToEnd: true });
+ });
+
+ test("a flow that fits the pane shows neither button", () => {
+ const shortChain = { x: 0, y: 0, width: 500, height: 400 };
+ expect(
+ flowJumpVisibility({
+ pane,
+ viewport: { x: 150, y: START_ANCHOR_TOP_PX, zoom: 1 },
+ bounds: shortChain,
+ }),
+ ).toEqual({ showJumpToStart: false, showJumpToEnd: false });
+ });
+
+ test("a short flow panned out of view still shows neither button", () => {
+ const shortChain = { x: 0, y: 0, width: 500, height: 400 };
+ expect(
+ flowJumpVisibility({
+ pane,
+ viewport: { x: 150, y: -2000, zoom: 1 },
+ bounds: shortChain,
+ }),
+ ).toEqual({ showJumpToStart: false, showJumpToEnd: false });
+ });
+
+ test("zooming in far enough makes a short flow jumpable again", () => {
+ // 400 world px at zoom 2 = 800 screen px > the 600px pane.
+ const shortChain = { x: 0, y: 0, width: 500, height: 400 };
+ expect(
+ flowJumpVisibility({
+ pane,
+ viewport: { x: 0, y: -100, zoom: 2 },
+ bounds: shortChain,
+ }),
+ ).toEqual({ showJumpToStart: true, showJumpToEnd: true });
+ });
+
+ test("degenerate geometry shows neither button", () => {
+ expect(
+ flowJumpVisibility({
+ pane: { width: 0, height: 0 },
+ viewport: { x: 0, y: 0, zoom: 1 },
+ bounds: longChain,
+ }),
+ ).toEqual({ showJumpToStart: false, showJumpToEnd: false });
+ expect(
+ flowJumpVisibility({
+ pane,
+ viewport: { x: 0, y: 0, zoom: 1 },
+ bounds: { x: 0, y: 0, width: 0, height: 0 },
+ }),
+ ).toEqual({ showJumpToStart: false, showJumpToEnd: false });
+ });
+});
+
describe("paneRecenterViewport", () => {
const chain = { x: 0, y: 0, width: 500, height: 4000 };
diff --git a/skyvern-frontend/src/routes/workflows/editor/paneFit.ts b/skyvern-frontend/src/routes/workflows/editor/paneFit.ts
index 5aa44bf07..826e17818 100644
--- a/skyvern-frontend/src/routes/workflows/editor/paneFit.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/paneFit.ts
@@ -124,6 +124,66 @@ export function startAnchoredViewport({
};
}
+export const END_ANCHOR_BOTTOM_PX = 24;
+
+/**
+ * Mirror of `startAnchoredViewport` for the flow's END: same zoom rule and
+ * horizontal centering, with the flow's bottom edge anchored just above the
+ * pane bottom. Jumping between the two anchors keeps the zoom stable.
+ */
+export function endAnchoredViewport({
+ pane,
+ bounds,
+}: {
+ pane: Size;
+ bounds: Rect;
+}): Viewport | null {
+ const start = startAnchoredViewport({ pane, bounds });
+ if (start === null) {
+ return null;
+ }
+ return {
+ x: start.x,
+ y:
+ pane.height -
+ END_ANCHOR_BOTTOM_PX -
+ (bounds.y + bounds.height) * start.zoom,
+ zoom: start.zoom,
+ };
+}
+
+/**
+ * Which flow-jump buttons should show for the current viewport. Both hide
+ * when the whole flow fits the pane at the current zoom (no dead chrome);
+ * otherwise each shows only while its end of the flow is scrolled out of
+ * view.
+ */
+export function flowJumpVisibility({
+ pane,
+ viewport,
+ bounds,
+}: {
+ pane: Size;
+ viewport: Viewport;
+ bounds: Rect;
+}): { showJumpToStart: boolean; showJumpToEnd: boolean } {
+ if (
+ pane.width <= 0 ||
+ pane.height <= 0 ||
+ bounds.width <= 0 ||
+ bounds.height <= 0
+ ) {
+ return { showJumpToStart: false, showJumpToEnd: false };
+ }
+ const screenTop = bounds.y * viewport.zoom + viewport.y;
+ const screenHeight = bounds.height * viewport.zoom;
+ const flowTallerThanPane = screenHeight > pane.height;
+ return {
+ showJumpToStart: flowTallerThanPane && screenTop < 0,
+ showJumpToEnd: flowTallerThanPane && screenTop + screenHeight > pane.height,
+ };
+}
+
/**
* Viewport for a pane-layout change (panes opened/closed/reordered):
* re-fits horizontally at the start-anchor zoom while keeping the content