From 5ea7866c002bf89effa6cdbf6543a1f1d3ab72c7 Mon Sep 17 00:00:00 2001 From: Lum1104 Date: Thu, 2 Apr 2026 12:57:46 +0800 Subject: [PATCH] fix(dashboard): fix mutable state, theme API, store pattern, and type imports in DomainGraphView Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/components/DomainGraphView.tsx | 95 +++++++++---------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/understand-anything-plugin/packages/dashboard/src/components/DomainGraphView.tsx b/understand-anything-plugin/packages/dashboard/src/components/DomainGraphView.tsx index 3b3bdfb..bb2b2a5 100644 --- a/understand-anything-plugin/packages/dashboard/src/components/DomainGraphView.tsx +++ b/understand-anything-plugin/packages/dashboard/src/components/DomainGraphView.tsx @@ -11,10 +11,12 @@ import type { Edge, Node } from "@xyflow/react"; import "@xyflow/react/dist/style.css"; import DomainClusterNode from "./DomainClusterNode"; +import type { DomainClusterFlowNode } from "./DomainClusterNode"; import FlowNode from "./FlowNode"; +import type { FlowFlowNode } from "./FlowNode"; import StepNode from "./StepNode"; +import type { StepFlowNode } from "./StepNode"; import { useDashboardStore } from "../store"; -import { useTheme } from "../themes/index.ts"; import { applyDagreLayout } from "../utils/layout"; import type { KnowledgeGraph, GraphNode } from "@understand-anything/core/types"; @@ -24,14 +26,12 @@ const nodeTypes = { "step-node": StepNode, }; -// Dimensions for domain-specific nodes -const DOMAIN_NODE_DIMENSIONS = new Map(); - function getDomainMeta(node: GraphNode): Record | undefined { return (node as any).domainMeta; } function buildDomainOverview(graph: KnowledgeGraph): { nodes: Node[]; edges: Edge[] } { + const dims = new Map(); const domainNodes = graph.nodes.filter((n) => n.type === "domain"); // Count flows per domain @@ -42,7 +42,7 @@ function buildDomainOverview(graph: KnowledgeGraph): { nodes: Node[]; edges: Edg } } - const rfNodes: Node[] = domainNodes.map((node) => { + const rfNodes: DomainClusterFlowNode[] = domainNodes.map((node) => { const meta = getDomainMeta(node); const data = { label: node.name, @@ -52,7 +52,7 @@ function buildDomainOverview(graph: KnowledgeGraph): { nodes: Node[]; edges: Edg businessRules: meta?.businessRules as string[] | undefined, domainId: node.id, }; - DOMAIN_NODE_DIMENSIONS.set(node.id, { width: 320, height: 180 }); + dims.set(node.id, { width: 320, height: 180 }); return { id: node.id, type: "domain-cluster" as const, @@ -73,7 +73,7 @@ function buildDomainOverview(graph: KnowledgeGraph): { nodes: Node[]; edges: Edg animated: true, })); - return applyDagreLayout(rfNodes, rfEdges, "LR", DOMAIN_NODE_DIMENSIONS); + return applyDagreLayout(rfNodes, rfEdges, "LR", dims); } function buildDomainDetail( @@ -108,40 +108,39 @@ function buildDomainDetail( const dims = new Map(); - const rfNodes: Node[] = [ - ...flowNodes.map((node) => { - const meta = getDomainMeta(node); - dims.set(node.id, { width: 260, height: 120 }); - return { - id: node.id, - type: "flow-node" as const, - position: { x: 0, y: 0 }, - data: { - label: node.name, - summary: node.summary, - entryPoint: meta?.entryPoint as string | undefined, - entryType: meta?.entryType as string | undefined, - stepCount: stepCountMap.get(node.id) ?? 0, - flowId: node.id, - }, - }; - }), - ...stepNodes.map((node) => { - dims.set(node.id, { width: 200, height: 90 }); - return { - id: node.id, - type: "step-node" as const, - position: { x: 0, y: 0 }, - data: { - label: node.name, - summary: node.summary, - filePath: node.filePath, - stepId: node.id, - order: Math.round((stepOrderMap.get(node.id) ?? 0) * 10), - }, - }; - }), - ]; + const flowRfNodes: FlowFlowNode[] = flowNodes.map((node) => { + const meta = getDomainMeta(node); + dims.set(node.id, { width: 260, height: 120 }); + return { + id: node.id, + type: "flow-node" as const, + position: { x: 0, y: 0 }, + data: { + label: node.name, + summary: node.summary, + entryPoint: meta?.entryPoint as string | undefined, + entryType: meta?.entryType as string | undefined, + stepCount: stepCountMap.get(node.id) ?? 0, + flowId: node.id, + }, + }; + }); + const stepRfNodes: StepFlowNode[] = stepNodes.map((node) => { + dims.set(node.id, { width: 200, height: 90 }); + return { + id: node.id, + type: "step-node" as const, + position: { x: 0, y: 0 }, + data: { + label: node.name, + summary: node.summary, + filePath: node.filePath, + stepId: node.id, + order: Math.round((stepOrderMap.get(node.id) ?? 0) * 10), + }, + }; + }); + const rfNodes: Node[] = [...flowRfNodes, ...stepRfNodes]; const rfEdges: Edge[] = stepEdges.map((e) => ({ id: `${e.source}-${e.target}`, @@ -158,7 +157,6 @@ function DomainGraphViewInner() { const domainGraph = useDashboardStore((s) => s.domainGraph); const activeDomainId = useDashboardStore((s) => s.activeDomainId); const navigateToDomain = useDashboardStore((s) => s.navigateToDomain); - const theme = useTheme(); const { nodes, edges } = useMemo(() => { if (!domainGraph) return { nodes: [], edges: [] }; @@ -192,7 +190,7 @@ function DomainGraphViewInner() {