Expose graph viewer selection control
This commit is contained in:
parent
c42ab624c2
commit
e3e3c5cae4
2 changed files with 25 additions and 7 deletions
|
|
@ -35,13 +35,15 @@ const PANEL_BORDER = "1px solid rgba(148, 163, 184, 0.18)";
|
||||||
export function EpiphanyGraphViewer({
|
export function EpiphanyGraphViewer({
|
||||||
state,
|
state,
|
||||||
initialGraph = "architecture",
|
initialGraph = "architecture",
|
||||||
|
selection: controlledSelection,
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
title = "Epiphany Graph Viewer",
|
title = "Epiphany Graph Viewer",
|
||||||
|
onSelectionChange,
|
||||||
onCodeRefSelect,
|
onCodeRefSelect,
|
||||||
}: EpiphanyGraphViewerProps) {
|
}: EpiphanyGraphViewerProps) {
|
||||||
const [activeGraphKey, setActiveGraphKey] = useState<GraphKey>(initialGraph);
|
const [activeGraphKey, setActiveGraphKey] = useState<GraphKey>(initialGraph);
|
||||||
const [selection, setSelection] = useState<ViewerSelection | null>(null);
|
const [localSelection, setLocalSelection] = useState<ViewerSelection | null>(null);
|
||||||
const [layouts, setLayouts] = useState<Record<GraphKey, GraphLayout> | null>(null);
|
const [layouts, setLayouts] = useState<Record<GraphKey, GraphLayout> | null>(null);
|
||||||
const [issues, setIssues] = useState<EpiphanyValidationIssue[]>([]);
|
const [issues, setIssues] = useState<EpiphanyValidationIssue[]>([]);
|
||||||
const [status, setStatus] = useState<"loading" | "ready" | "error">("loading");
|
const [status, setStatus] = useState<"loading" | "ready" | "error">("loading");
|
||||||
|
|
@ -64,6 +66,20 @@ export function EpiphanyGraphViewer({
|
||||||
startX: number;
|
startX: number;
|
||||||
startY: number;
|
startY: number;
|
||||||
} | null>(null);
|
} | 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(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
@ -239,7 +255,7 @@ export function EpiphanyGraphViewer({
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
setActiveGraphKey("architecture");
|
setActiveGraphKey("architecture");
|
||||||
if (selection?.graphKey && selection.graphKey !== "architecture") {
|
if (selection?.graphKey && selection.graphKey !== "architecture") {
|
||||||
setSelection(null);
|
updateSelection(null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +268,7 @@ export function EpiphanyGraphViewer({
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
setActiveGraphKey("dataflow");
|
setActiveGraphKey("dataflow");
|
||||||
if (selection?.graphKey && selection.graphKey !== "dataflow") {
|
if (selection?.graphKey && selection.graphKey !== "dataflow") {
|
||||||
setSelection(null);
|
updateSelection(null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -342,7 +358,7 @@ export function EpiphanyGraphViewer({
|
||||||
onPointerLeave={() => handlePointerUp(dragRef)}
|
onPointerLeave={() => handlePointerUp(dragRef)}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
if (event.target === event.currentTarget) {
|
if (event.target === event.currentTarget) {
|
||||||
setSelection(null);
|
updateSelection(null);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
style={{ width: "100%", height: "100%", display: "block", cursor: dragRef.current?.active ? "grabbing" : "grab" }}
|
style={{ width: "100%", height: "100%", display: "block", cursor: dragRef.current?.active ? "grabbing" : "grab" }}
|
||||||
|
|
@ -372,7 +388,7 @@ export function EpiphanyGraphViewer({
|
||||||
strokeWidth={18}
|
strokeWidth={18}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
setSelection({
|
updateSelection({
|
||||||
kind: "edge",
|
kind: "edge",
|
||||||
graphKey: activeGraphKey,
|
graphKey: activeGraphKey,
|
||||||
edgeId: edge.resolvedId,
|
edgeId: edge.resolvedId,
|
||||||
|
|
@ -438,7 +454,7 @@ export function EpiphanyGraphViewer({
|
||||||
opacity={emphasis}
|
opacity={emphasis}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
setSelection({
|
updateSelection({
|
||||||
kind: "node",
|
kind: "node",
|
||||||
graphKey: activeGraphKey,
|
graphKey: activeGraphKey,
|
||||||
nodeId: node.id,
|
nodeId: node.id,
|
||||||
|
|
@ -710,7 +726,7 @@ export function EpiphanyGraphViewer({
|
||||||
onJump={(graphKey, nodeId) => {
|
onJump={(graphKey, nodeId) => {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
setActiveGraphKey(graphKey);
|
setActiveGraphKey(graphKey);
|
||||||
setSelection({ kind: "node", graphKey, nodeId });
|
updateSelection({ kind: "node", graphKey, nodeId });
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onCodeRefSelect={(codeRef) => onCodeRefSelect?.(codeRef, { graphKey: activeGraphKey, selection })}
|
onCodeRefSelect={(codeRef) => onCodeRefSelect?.(codeRef, { graphKey: activeGraphKey, selection })}
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,11 @@ export type ViewerSelection =
|
||||||
export interface EpiphanyGraphViewerProps {
|
export interface EpiphanyGraphViewerProps {
|
||||||
state: EpiphanyGraphsState;
|
state: EpiphanyGraphsState;
|
||||||
initialGraph?: GraphKey;
|
initialGraph?: GraphKey;
|
||||||
|
selection?: ViewerSelection | null;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
onSelectionChange?: (selection: ViewerSelection | null) => void;
|
||||||
onCodeRefSelect?: (
|
onCodeRefSelect?: (
|
||||||
codeRef: EpiphanyCodeRef,
|
codeRef: EpiphanyCodeRef,
|
||||||
context: {
|
context: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue