diff --git a/packages/dashboard/src/components/CodeViewer.tsx b/packages/dashboard/src/components/CodeViewer.tsx new file mode 100644 index 0000000..9d45b7a --- /dev/null +++ b/packages/dashboard/src/components/CodeViewer.tsx @@ -0,0 +1,114 @@ +import Editor from "@monaco-editor/react"; +import { useDashboardStore } from "../store"; + +const extensionToLanguage: Record = { + ts: "typescript", + tsx: "typescript", + js: "javascript", + jsx: "javascript", + py: "python", + go: "go", + rs: "rust", + rb: "ruby", + java: "java", + kt: "kotlin", + cs: "csharp", + cpp: "cpp", + c: "c", + swift: "swift", + php: "php", + json: "json", + yaml: "yaml", + yml: "yaml", + md: "markdown", + html: "html", + css: "css", + sql: "sql", + sh: "shell", + bash: "shell", +}; + +function getLanguage(filePath: string | undefined): string { + if (!filePath) return "plaintext"; + const ext = filePath.split(".").pop()?.toLowerCase() ?? ""; + return extensionToLanguage[ext] ?? "plaintext"; +} + +export default function CodeViewer() { + const graph = useDashboardStore((s) => s.graph); + const selectedNodeId = useDashboardStore((s) => s.selectedNodeId); + + const node = graph?.nodes.find((n) => n.id === selectedNodeId) ?? null; + + if (!node) { + return ( +
+

+ Select a node to view its source code +

+
+ ); + } + + const language = getLanguage(node.filePath); + const lineInfo = node.lineRange + ? `Lines ${node.lineRange[0]}-${node.lineRange[1]}` + : "Full file"; + + const placeholderCode = [ + `// ${node.name}`, + `// Type: ${node.type}`, + `// File: ${node.filePath ?? "unknown"}`, + `// ${lineInfo}`, + `//`, + `// Summary:`, + `// ${node.summary}`, + `//`, + `// Note: Source code display requires file content access.`, + `// In a full integration, this panel will show the actual`, + `// source code from the analyzed project.`, + "", + ...(node.tags.length > 0 + ? [`// Tags: ${node.tags.join(", ")}`] + : []), + ...(node.languageNotes + ? [`//`, `// Language Notes:`, `// ${node.languageNotes}`] + : []), + ].join("\n"); + + return ( +
+
+ + {node.type} + + + {node.name} + + {node.filePath && ( + + {node.filePath} + + )} +
+ +
+ +
+
+ ); +}