From e3e3c5cae4ec5b7c08ec61a0967a433ceed15653 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 04:19:55 +0100 Subject: [PATCH] Expose graph viewer selection control --- .../src/lib/EpiphanyGraphViewer.tsx | 30 ++++++++++++++----- web/epiphany-graph-viewer/src/lib/types.ts | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx b/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx index 31e38c0..99007dc 100644 --- a/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx +++ b/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx @@ -35,13 +35,15 @@ const PANEL_BORDER = "1px solid rgba(148, 163, 184, 0.18)"; export function EpiphanyGraphViewer({ state, initialGraph = "architecture", + selection: controlledSelection, style, className, title = "Epiphany Graph Viewer", + onSelectionChange, onCodeRefSelect, }: EpiphanyGraphViewerProps) { const [activeGraphKey, setActiveGraphKey] = useState(initialGraph); - const [selection, setSelection] = useState(null); + const [localSelection, setLocalSelection] = useState(null); const [layouts, setLayouts] = useState | null>(null); const [issues, setIssues] = useState([]); const [status, setStatus] = useState<"loading" | "ready" | "error">("loading"); @@ -64,6 +66,20 @@ export function EpiphanyGraphViewer({ startX: number; startY: number; } | null>(null); + const selection = controlledSelection === undefined ? localSelection : controlledSelection; + const updateSelection = (nextSelection: ViewerSelection | null) => { + if (controlledSelection === undefined) { + setLocalSelection(nextSelection); + } + onSelectionChange?.(nextSelection); + }; + + useEffect(() => { + if (!controlledSelection?.graphKey) { + return; + } + setActiveGraphKey(controlledSelection.graphKey); + }, [controlledSelection?.graphKey]); useEffect(() => { let cancelled = false; @@ -239,7 +255,7 @@ export function EpiphanyGraphViewer({ startTransition(() => { setActiveGraphKey("architecture"); if (selection?.graphKey && selection.graphKey !== "architecture") { - setSelection(null); + updateSelection(null); } }) } @@ -252,7 +268,7 @@ export function EpiphanyGraphViewer({ startTransition(() => { setActiveGraphKey("dataflow"); if (selection?.graphKey && selection.graphKey !== "dataflow") { - setSelection(null); + updateSelection(null); } }) } @@ -342,7 +358,7 @@ export function EpiphanyGraphViewer({ onPointerLeave={() => handlePointerUp(dragRef)} onClick={(event) => { if (event.target === event.currentTarget) { - setSelection(null); + updateSelection(null); } }} style={{ width: "100%", height: "100%", display: "block", cursor: dragRef.current?.active ? "grabbing" : "grab" }} @@ -372,7 +388,7 @@ export function EpiphanyGraphViewer({ strokeWidth={18} onClick={(event) => { event.stopPropagation(); - setSelection({ + updateSelection({ kind: "edge", graphKey: activeGraphKey, edgeId: edge.resolvedId, @@ -438,7 +454,7 @@ export function EpiphanyGraphViewer({ opacity={emphasis} onClick={(event) => { event.stopPropagation(); - setSelection({ + updateSelection({ kind: "node", graphKey: activeGraphKey, nodeId: node.id, @@ -710,7 +726,7 @@ export function EpiphanyGraphViewer({ onJump={(graphKey, nodeId) => { startTransition(() => { setActiveGraphKey(graphKey); - setSelection({ kind: "node", graphKey, nodeId }); + updateSelection({ kind: "node", graphKey, nodeId }); }); }} onCodeRefSelect={(codeRef) => onCodeRefSelect?.(codeRef, { graphKey: activeGraphKey, selection })} diff --git a/web/epiphany-graph-viewer/src/lib/types.ts b/web/epiphany-graph-viewer/src/lib/types.ts index 8495b98..ee3cb64 100644 --- a/web/epiphany-graph-viewer/src/lib/types.ts +++ b/web/epiphany-graph-viewer/src/lib/types.ts @@ -68,9 +68,11 @@ export type ViewerSelection = export interface EpiphanyGraphViewerProps { state: EpiphanyGraphsState; initialGraph?: GraphKey; + selection?: ViewerSelection | null; style?: CSSProperties; className?: string; title?: string; + onSelectionChange?: (selection: ViewerSelection | null) => void; onCodeRefSelect?: ( codeRef: EpiphanyCodeRef, context: {