From 71320391f3b59a57345dd9a66aa68f762c54e558 Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Fri, 6 Nov 2026 02:02:36 +0000 Subject: [PATCH] Fix project job graph rendering and panning --- packages/app/src/features/projects/graph.tsx | 41 ++++++++++++++++---- packages/app/test/jobs.browser.test.mjs | 12 +++++- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/packages/app/src/features/projects/graph.tsx b/packages/app/src/features/projects/graph.tsx index d20dbd2b..8eb11f6b 100644 --- a/packages/app/src/features/projects/graph.tsx +++ b/packages/app/src/features/projects/graph.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from "react"; +import { useMemo, useRef, useState, type PointerEvent } from "react"; import { useNavigate } from "@tanstack/react-router"; import { useQuery } from "@tanstack/react-query"; import { api } from "factorize-api-client"; @@ -35,10 +35,37 @@ export function ProjectGraph({ projectId }: { projectId: string }) { // for labels and crossing connections to remain readable. for (const [column, ids] of columns) ids.forEach((id, row) => positions.set(id, { x: 300 + column * 340, y: 110 + row * 200 })); graph.nodes.filter(node => node.type === "webhook").forEach((node, row) => positions.set(node.id, { x: 35, y: 110 + row * 190 })); - const width = Math.max(900, ...[...positions.values()].map(p => p.x + 190)), height = Math.max(400, ...[...positions.values()].map(p => p.y + 110)); + const width = Math.max(900, ...[...positions.values()].map(p => p.x + 240)), height = Math.max(400, ...[...positions.values()].map(p => p.y + 110)); return { positions, width, height }; }, [query.data]); - const [drag, setDrag] = useState<{ x: number; y: number } | null>(null); + const pointers = useRef(new Map()); + const lastPanCenter = useRef<{ x: number; y: number } | null>(null); + const graphPointerDown = (event: PointerEvent) => { + if ((event.target as Element).closest("[data-graph-interactive]")) return; + pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY, type: event.pointerType }); + const active = [...pointers.current.values()], touch = active.some(pointer => pointer.type === "touch"); + if (touch ? active.filter(pointer => pointer.type === "touch").length >= 2 : true) { + const center = active.reduce((point, pointer) => ({ x: point.x + pointer.x / active.length, y: point.y + pointer.y / active.length }), { x: 0, y: 0 }); + lastPanCenter.current = center; + } + }; + const graphPointerMove = (event: PointerEvent) => { + if (!pointers.current.has(event.pointerId)) return; + pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY, type: event.pointerType }); + const active = [...pointers.current.values()], touch = active.some(pointer => pointer.type === "touch"); + if (touch && active.filter(pointer => pointer.type === "touch").length < 2) return; + if (!lastPanCenter.current) return; + const center = active.reduce((point, pointer) => ({ x: point.x + pointer.x / active.length, y: point.y + pointer.y / active.length }), { x: 0, y: 0 }); + const previous = lastPanCenter.current; + setOffset(current => ({ x: current.x + center.x - previous.x, y: current.y + center.y - previous.y })); + lastPanCenter.current = center; + }; + const graphPointerUp = (event: PointerEvent) => { + pointers.current.delete(event.pointerId); + const active = [...pointers.current.values()], touchCount = active.filter(pointer => pointer.type === "touch").length; + if (!active.length || (active.some(pointer => pointer.type === "touch") && touchCount < 2)) lastPanCenter.current = null; + else if (lastPanCenter.current) lastPanCenter.current = active.reduce((point, pointer) => ({ x: point.x + pointer.x / active.length, y: point.y + pointer.y / active.length }), { x: 0, y: 0 }); + }; if (query.isPending) return

Loading project graph…

; if (query.error) return
{query.error.message}
; if (!query.data?.nodes.length) return

No jobs in this project yet.

; @@ -62,7 +89,7 @@ export function ProjectGraph({ projectId }: { projectId: string }) { Drag to pan. Select a job to open it. -
{ if (event.target === event.currentTarget) { event.currentTarget.setPointerCapture(event.pointerId); setDrag({ x: event.clientX - offset.x, y: event.clientY - offset.y }); } }} onPointerMove={event => { if (drag) setOffset({ x: event.clientX - drag.x, y: event.clientY - drag.y }); }} onPointerUp={() => setDrag(null)}> +
node.type === "job").length} jobs and ${graph.edges.length} connections`} viewBox={`0 0 ${layout.width} ${layout.height}`} className="h-[min(68vh,700px)] min-h-[360px] w-full touch-none" preserveAspectRatio="xMidYMid meet"> @@ -70,7 +97,7 @@ export function ProjectGraph({ projectId }: { projectId: string }) { const [leftId, rightId] = JSON.parse(pair) as [string, string], left = layout.positions.get(leftId), right = layout.positions.get(rightId); if (!left || !right) return null; const leftNode = graph.nodes.find(node => node.id === leftId), rightNode = graph.nodes.find(node => node.id === rightId); - const leftWidth = leftNode?.type === "webhook" ? 145 : 170, rightWidth = rightNode?.type === "webhook" ? 145 : 170; + const leftWidth = leftNode?.type === "webhook" ? 145 : 220, rightWidth = rightNode?.type === "webhook" ? 145 : 220; const leftIsLeft = left.x <= right.x, from = leftIsLeft ? left : right, to = leftIsLeft ? right : left; const fromId = leftIsLeft ? leftId : rightId, toId = leftIsLeft ? rightId : leftId; const startWidth = leftIsLeft ? leftWidth : rightWidth, endX = to.x; @@ -78,9 +105,9 @@ export function ProjectGraph({ projectId }: { projectId: string }) { const muted = edges.every(edge => !edge.enabled), label = [...new Set(edges.map(edge => edge.label).filter(Boolean))].join(" · "); const stroke = muted ? "#a8a29e" : edges.length === 1 && edges[0].kind === "manual" ? "#7c3aed" : edges.length === 1 && edges[0].kind === "webhook" ? "#0284c7" : "#0f766e"; const groupId = edges.map(edge => edge.id).sort().join("|"); - return setSelectedEdge(edges[0])} className="cursor-pointer" role="button" tabIndex={0} aria-label={`${label || "Workflow"} connection${edges.length > 1 ? `, ${edges.length} triggers` : ""}`} onKeyDown={event => { if (event.key === "Enter" || event.key === " ") setSelectedEdge(edges[0]); }}> edge.id === selectedEdge.id) ? 4 : 2} strokeDasharray={muted ? "6 5" : undefined} markerStart={reverse ? "url(#graph-arrow-start)" : undefined} markerEnd={forward ? "url(#graph-arrow)" : undefined}/>{label}; + return setSelectedEdge(edges[0])} className="cursor-pointer" role="button" tabIndex={0} aria-label={`${label || "Workflow"} connection${edges.length > 1 ? `, ${edges.length} triggers` : ""}`} onKeyDown={event => { if (event.key === "Enter" || event.key === " ") setSelectedEdge(edges[0]); }}> edge.id === selectedEdge.id) ? 4 : 2} strokeDasharray={muted ? "6 5" : undefined} markerStart={reverse ? "url(#graph-arrow-start)" : undefined} markerEnd={forward ? "url(#graph-arrow)" : undefined}/>{label}; })} - {graph.nodes.map(node => { const p = layout.positions.get(node.id)!; const isJob = node.type === "job", muted = isJob && !node.enabled, active = isJob && (node.runningCount ?? 0) > 0, height = isJob ? 92 : 70; return 1 ? `, ${node.runningCount}/${node.concurrencyLimit} active` : ""}` : ", not running"}` : node.label} onClick={() => isJob && void navigate({ to: "/jobs/$jobId", params: { jobId: node.id } })} onKeyDown={event => { if (isJob && (event.key === "Enter" || event.key === " ")) void navigate({ to: "/jobs/$jobId", params: { jobId: node.id } }); }}>{isJob ? node.jobKind : node.provider}{node.label.length > 19 ? node.label.slice(0, 18) + "…" : node.label}{isJob && <>{active ? `Running${node.concurrencyLimit && node.concurrencyLimit > 1 ? ` · ${node.runningCount}/${node.concurrencyLimit}` : ""}` : "Not running"}}; })} + {graph.nodes.map(node => { const p = layout.positions.get(node.id)!; const isJob = node.type === "job", muted = isJob && !node.enabled, active = isJob && (node.runningCount ?? 0) > 0, height = isJob ? 112 : 70, title = node.label.length > 22 ? node.label.slice(0, 21) + "…" : node.label; return 1 ? `, ${node.runningCount}/${node.concurrencyLimit} active` : ""}` : ", not running"}` : node.label} onClick={() => isJob && void navigate({ to: "/jobs/$jobId", params: { jobId: node.id } })} onKeyDown={event => { if (isJob && (event.key === "Enter" || event.key === " ")) void navigate({ to: "/jobs/$jobId", params: { jobId: node.id } }); }}>{isJob ? <>{node.jobKind}{title}{active ? `Running${node.concurrencyLimit && node.concurrencyLimit > 1 ? ` · ${node.runningCount}/${node.concurrencyLimit}` : ""}` : "Not running"} : <>{node.provider}{node.label.length > 19 ? node.label.slice(0, 18) + "…" : node.label}}; })}
diff --git a/packages/app/test/jobs.browser.test.mjs b/packages/app/test/jobs.browser.test.mjs index 671c982f..588c144b 100644 --- a/packages/app/test/jobs.browser.test.mjs +++ b/packages/app/test/jobs.browser.test.mjs @@ -90,7 +90,7 @@ test("project graph preserves disabled and multiple connections and navigates to ], edges: [ { id: "lifecycle-a", source: jobId, target: secondJob, label: "Failed, Stopped", kind: "lifecycle", enabled: false }, { id: "idle-a", source: jobId, target: secondJob, label: "Idle", kind: "idle", enabled: false }, - { id: "manual-a", source: jobId, target: secondJob, label: "Manual", kind: "manual", enabled: false }, + { id: "manual-a", source: secondJob, target: jobId, label: "Manual", kind: "manual", enabled: false }, { id: "lifecycle-reverse", source: secondJob, target: jobId, label: "Succeeded", kind: "lifecycle", enabled: true }, ], } })); @@ -104,7 +104,15 @@ test("project graph preserves disabled and multiple connections and navigates to assert.equal(await page.getByRole("button", { name: /connection, 4 triggers/ }).count(), 1); assert.equal(await combined.locator("path").getAttribute("marker-start"), "url(#graph-arrow-start)"); assert.equal(await combined.locator("path").getAttribute("marker-end"), "url(#graph-arrow)"); - await page.getByRole("link", { name: "Code: Deploy, disabled" }).click(); + assert.equal(await page.getByRole("link", { name: "Deploy, disabled, not running" }).count(), 1); + const svg = page.getByRole("img", { name: /2 jobs and 4 connections/ }); + const svgBox = await svg.boundingBox(); + await page.mouse.move(svgBox.x + svgBox.width / 2, svgBox.y + svgBox.height / 2); + await page.mouse.down(); + await page.mouse.move(svgBox.x + svgBox.width / 2 + 25, svgBox.y + svgBox.height / 2 + 20); + await page.mouse.up(); + assert.match(await svg.locator(":scope > g").getAttribute("transform"), /^translate\(25 20\) scale\(1\)$/); + await page.getByRole("link", { name: "Deploy, disabled, not running" }).click(); await page.waitForURL(new RegExp(`/jobs/${secondJob}`)); await context.close(); });