Skip to content
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
34 changes: 32 additions & 2 deletions packages/app/src/features/projects/graph-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,42 @@ export function ProjectGraphFlow({ graphNodes, graphEdges, onOpen, onSelect, flo
}) {
const [selected, setSelected] = useState<string | null>(null);
const [openGroup, setOpenGroup] = useState<GraphConnection[] | null>(null), groupTrigger = useRef<HTMLButtonElement | null>(null), groupMenu = useRef<HTMLDivElement | null>(null);
const graphElement = useRef<HTMLDivElement | null>(null), flowInstance = useRef<ProjectFlowInstance | null>(null);
const twoFingerPan = useRef<{ x: number; y: number; viewport: { x: number; y: number; zoom: number } } | null>(null);
const onGroup = useCallback((connections: GraphConnection[], trigger: HTMLButtonElement) => { groupTrigger.current = trigger; setOpenGroup(connections); }, []);
useEffect(() => { if (!openGroup) return; const keydown = (event: KeyboardEvent) => { if (event.key === "Escape") { setOpenGroup(null); groupTrigger.current?.focus(); } }; const dismiss = (event: PointerEvent) => { if (!groupMenu.current?.contains(event.target as globalThis.Node) && !groupTrigger.current?.contains(event.target as globalThis.Node)) setOpenGroup(null); }; document.addEventListener("keydown", keydown); document.addEventListener("pointerdown", dismiss); return () => { document.removeEventListener("keydown", keydown); document.removeEventListener("pointerdown", dismiss); }; }, [openGroup]);
useEffect(() => {
const element = graphElement.current;
if (!element) return;
const midpoint = (touches: TouchList) => ({ x: (touches[0].clientX + touches[1].clientX) / 2, y: (touches[0].clientY + touches[1].clientY) / 2 });
const start = (event: TouchEvent) => {
if (event.touches.length !== 2 || (event.target instanceof Element && event.target.closest(".react-flow__controls, [data-graph-interactive], button"))) return;
const point = midpoint(event.touches), instance = flowInstance.current;
if (instance) twoFingerPan.current = { ...point, viewport: instance.getViewport() };
};
const move = (event: TouchEvent) => {
const startPoint = twoFingerPan.current, instance = flowInstance.current;
if (!startPoint || !instance || event.touches.length !== 2) return;
event.preventDefault();
const point = midpoint(event.touches);
void instance.setViewport({ x: startPoint.viewport.x + point.x - startPoint.x, y: startPoint.viewport.y + point.y - startPoint.y, zoom: startPoint.viewport.zoom }, { duration: 0 });
};
const end = (event: TouchEvent) => { if (event.touches.length < 2) twoFingerPan.current = null; };
element.addEventListener("touchstart", start, { passive: true });
element.addEventListener("touchmove", move, { passive: false });
element.addEventListener("touchend", end, { passive: true });
element.addEventListener("touchcancel", end, { passive: true });
return () => {
element.removeEventListener("touchstart", start);
element.removeEventListener("touchmove", move);
element.removeEventListener("touchend", end);
element.removeEventListener("touchcancel", end);
};
}, []);
const layout = useMemo(() => makeLayout(graphNodes, graphEdges, onOpen, onSelect, onGroup), [graphNodes, graphEdges, onOpen, onSelect, onGroup]);
const edges: FlowEdge[] = useMemo(() => layout.edges.map(edge => ({ ...edge, data: { ...edge.data!, selected: edge.id === selected } } as FlowEdge)), [layout.edges, selected]);
return <div role="region" aria-label={`Workflow graph with ${graphNodes.filter(node => node.type === "job").length} jobs and ${graphEdges.length} connections`} className="relative h-[min(68vh,700px)] min-h-[360px] w-full overflow-hidden rounded-xl border border-stone-200 bg-stone-50 dark:border-slate-800 dark:bg-slate-950">
<ReactFlow nodes={layout.nodes} edges={edges} nodeTypes={{ ...nodeTypes, bounds: BoundsNode }} edgeTypes={edgeTypes} onInit={flowRef} onNodeClick={(_, node) => node.type === "job" && onOpen(node.id)} onEdgeClick={(_, edge) => { setSelected(edge.id); edge.data?.onSelect(edge.data.connections[0]); }} onPaneClick={() => setSelected(null)} fitView fitViewOptions={{ padding: 0.18 }} minZoom={0.15} maxZoom={2} zoomOnScroll={false} nodesDraggable={false} nodesConnectable={false} elementsSelectable onlyRenderVisibleElements proOptions={{ hideAttribution: false }}>
return <div ref={graphElement} role="region" aria-label={`Workflow graph with ${graphNodes.filter(node => node.type === "job").length} jobs and ${graphEdges.length} connections`} className="project-graph-touch relative h-[min(68vh,700px)] min-h-[360px] w-full overflow-hidden rounded-xl border border-stone-200 bg-stone-50 dark:border-slate-800 dark:bg-slate-950">
<ReactFlow nodes={layout.nodes} edges={edges} nodeTypes={{ ...nodeTypes, bounds: BoundsNode }} edgeTypes={edgeTypes} onInit={instance => { flowInstance.current = instance; flowRef(instance); }} onNodeClick={(_, node) => node.type === "job" && onOpen(node.id)} onEdgeClick={(_, edge) => { setSelected(edge.id); edge.data?.onSelect(edge.data.connections[0]); }} onPaneClick={() => setSelected(null)} fitView fitViewOptions={{ padding: 0.18 }} minZoom={0.15} maxZoom={2} zoomOnScroll={false} panOnDrag={false} zoomOnPinch={false} nodesDraggable={false} nodesConnectable={false} elementsSelectable onlyRenderVisibleElements proOptions={{ hideAttribution: false }}>
<Background color="#cbd5e1" gap={24} size={1} /><Controls position="top-right" showInteractive={false} />
</ReactFlow>
{openGroup && <div ref={groupMenu} role="dialog" aria-label="Grouped connections" className="absolute left-3 top-3 z-50 max-h-[55vh] w-72 overflow-y-auto rounded-lg border border-stone-300 bg-white p-1 shadow-xl dark:border-slate-700 dark:bg-slate-900">{[...openGroup].sort((a, b) => a.label.localeCompare(b.label) || a.source.localeCompare(b.source) || a.target.localeCompare(b.target) || a.kind.localeCompare(b.kind) || a.id.localeCompare(b.id)).map(edge => <button key={edge.id} type="button" className="block w-full rounded px-3 py-2 text-left text-sm hover:bg-stone-100 focus:bg-stone-100 focus:outline-none dark:hover:bg-slate-800 dark:focus:bg-slate-800" onClick={() => { setSelected(edge.id); onSelect(edge); setOpenGroup(null); }}><span className="block font-medium">{edge.label || "Workflow"}</span><span className="block text-xs text-slate-600 dark:text-slate-400">{graphNodes.find(node => node.id === edge.source)?.label ?? graphNodes.find(node => node.id === edge.source)?.provider ?? "Unknown"} → {graphNodes.find(node => node.id === edge.target)?.label ?? graphNodes.find(node => node.id === edge.target)?.provider ?? "Unknown"}</span><span className="block text-xs text-slate-600 dark:text-slate-400">{edge.kind === "manual" ? "Manual invocation permission" : "Automatic trigger"} · {edge.enabled ? "Enabled" : "Disabled"}</span></button>)}</div>}
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
@keyframes trace-dot-pulse { 0%, 60%, 100% { opacity: .35; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Let one-finger vertical swipes scroll the page over the graph. */
.project-graph-touch .react-flow__pane { touch-action: pan-y; }

/* Template overlay shares the editable control's metrics, including wrapping and scroll. */
.template-editor { position: relative; min-width: 0; }
.template-editor pre, .template-editor textarea {
Expand Down
35 changes: 35 additions & 0 deletions packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,41 @@ test("project graph does not zoom when the desktop wheel scrolls over it", async
assert.equal(await viewport.getAttribute("style"), initialTransform);
await context.close();
});
test("mobile project graph leaves one-finger page scrolling and pans with two fingers", async () => {
const { page, context } = await contextFor({ viewport: { width: 390, height: 844 }, hasTouch: true });
await page.route("**/api/v1/job-summaries?**", route => route.fulfill({ json: { items: [], nextCursor: null } }));
await page.route(`**/api/v1/projects/${projectId}/graph`, route => route.fulfill({ json: {
nodes: [{ id: jobId, type: "job", label: "Build", jobKind: "Agent", enabled: true, runningCount: 0, concurrencyLimit: 1 }],
edges: [],
} }));
await page.goto(origin + `/projects/${projectId}`);
await page.getByRole("button", { name: "Graph", exact: true }).click();
const graph = page.getByRole("region", { name: /1 jobs and 0 connections/ });
await graph.waitFor();
const viewport = graph.locator(".react-flow__viewport");
const initialTransform = await viewport.getAttribute("style");
const gesture = await graph.evaluate(element => {
const pane = element.querySelector(".react-flow__pane");
const touch = (identifier, clientX, clientY) => new Touch({ identifier, target: pane, clientX, clientY });
const dispatch = (type, touches) => {
const event = new TouchEvent(type, { bubbles: true, cancelable: true, touches, changedTouches: touches });
pane.dispatchEvent(event);
return event;
};
const touchAction = getComputedStyle(pane).touchAction;
const first = touch(1, 100, 100), second = touch(2, 200, 100);
dispatch("touchstart", [first, second]);
const movedFirst = touch(1, 100, 180), movedSecond = touch(2, 200, 180);
const move = dispatch("touchmove", [movedFirst, movedSecond]);
dispatch("touchend", []);
return { touchAction, prevented: move.defaultPrevented };
});
await page.waitForFunction((before) => document.querySelector(".react-flow__viewport")?.getAttribute("style") !== before, initialTransform);
assert.equal(gesture.touchAction, "pan-y");
assert.equal(gesture.prevented, true);
assert.notEqual(await viewport.getAttribute("style"), initialTransform);
await context.close();
});
test("project graph renders dense cyclic, webhook and self-loop routes and fits their labels", async () => {
const { page, context } = await contextFor({ viewport: { width: 390, height: 844 } });
const ids = [jobId, "00000000-0000-4000-8000-000000000012", "00000000-0000-4000-8000-000000000013", "00000000-0000-4000-8000-000000000014"];
Expand Down
Loading