Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
refactor(toolbar): drop the MD clipboard export from the canvas header
Pouzor2f9889921efc
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex e36a10f..1e3db0c 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -6,8 +6,6 @@ import { serializeNode, serializeEdge, deserializeApiNode, deserializeApiEdge, mimport { generateUUID } from '@/utils/uuid'import { getCenteredPosition } from '@/utils/viewportCenter'import { resolveVirtualEdgeParent } from '@/utils/virtualEdgeParent'-import { generateMarkdownTable } from '@/utils/exportMarkdown'-import { copyToClipboard } from '@/utils/clipboard'import { getDesignIdFromUrl, setDesignIdInUrl } from '@/utils/designUrl'import { useDocsUrlSync } from '@/hooks/useDocsUrlSync'import { withBase } from '@/utils/basePath'@@ -794,16 +792,6 @@ export default function App() {toast.success('Canvas auto-arranged')}, [nodes, edges, applyLayout])- const handleExportMd = useCallback(async () => {- const md = generateMarkdownTable(nodes)- if (!md) { toast.error('No nodes to export'); return }- if (await copyToClipboard(md)) {- toast.success('Markdown table copied to clipboard')- } else {- toast.error('Markdown copy failed')- }- }, [nodes])-const handleExportYaml = useCallback(() => {if (nodes.length === 0) { toast.error('No nodes to export'); return }const content = exportCanvasToYaml(nodes, edges)@@ -1187,7 +1175,6 @@ export default function App() {onUndo={undo}onRedo={redo}onShortcuts={() => setShortcutsOpen(true)}- onExportMd={handleExportMd}onExportYaml={handleExportYaml}onImportYaml={handleImportYaml}onViewOnly={handleViewOnly}diff --git a/frontend/src/components/panels/Toolbar.tsx b/frontend/src/components/panels/Toolbar.tsxindex d02a01a..c44f4a7 100644--- a/frontend/src/components/panels/Toolbar.tsx+++ b/frontend/src/components/panels/Toolbar.tsx@@ -1,5 +1,5 @@import { useRef } from 'react'-import { Save, LayoutDashboard, Download, Palette, Undo2, Redo2, HelpCircle, Table2, FileDown, Upload, Eye } from 'lucide-react'+import { Save, LayoutDashboard, Download, Palette, Undo2, Redo2, HelpCircle, FileDown, Upload, Eye } from 'lucide-react'import { Button } from '@/components/ui/button'import { Logo } from '@/components/ui/Logo'import { useCanvasStore } from '@/stores/canvasStore'@@ -17,13 +17,12 @@ interface ToolbarProps {onUndo: () => voidonRedo: () => voidonShortcuts: () => void- onExportMd: () => voidonExportYaml: () => voidonImportYaml: (content: string) => voidonViewOnly: () => void}-export function Toolbar({ onSave, onAutoLayout, onExport, onChangeStyle, onUndo, onRedo, onShortcuts, onExportMd, onExportYaml, onImportYaml, onViewOnly }: ToolbarProps) {+export function Toolbar({ onSave, onAutoLayout, onExport, onChangeStyle, onUndo, onRedo, onShortcuts, onExportYaml, onImportYaml, onViewOnly }: ToolbarProps) {const { hasUnsavedChanges: canvasDirty, past, future } = useCanvasStore()const isRack = useDesignStore((s) => s.activeDesignType) === 'rack'const rackDirty = useRackStore((s) => s.hasUnsavedChanges)@@ -98,11 +97,6 @@ export function Toolbar({ onSave, onAutoLayout, onExport, onChangeStyle, onUndo,<Button size="sm" variant="ghost" className="gap-1.5 text-muted-foreground hover:text-foreground cursor-pointer hover:bg-[#21262d]" onClick={onExport} title="Download canvas as PNG"><FileDown size={14} /> PNG</Button>- {!isRack && (- <Button size="sm" variant="ghost" className="gap-1.5 text-muted-foreground hover:text-foreground cursor-pointer hover:bg-[#21262d]" onClick={onExportMd} title="Copy inventory as Markdown table">- <Table2 size={14} /> MD- </Button>- )}{/* Live view reads backend/localStorage canvas; pointless in standalonewhere the editor already shows the only (localStorage) copy. Rackcanvases have no live view yet. */}diff --git a/frontend/src/components/panels/__tests__/Toolbar.test.tsx b/frontend/src/components/panels/__tests__/Toolbar.test.tsxindex 8fcc1a9..35dedbc 100644--- a/frontend/src/components/panels/__tests__/Toolbar.test.tsx+++ b/frontend/src/components/panels/__tests__/Toolbar.test.tsx@@ -28,7 +28,6 @@ const defaultProps = {onUndo: vi.fn(),onRedo: vi.fn(),onShortcuts: vi.fn(),- onExportMd: vi.fn(),onExportYaml: vi.fn(),onImportYaml: vi.fn(),onViewOnly: vi.fn(),@@ -116,6 +115,6 @@ describe('Toolbar (standalone)', () => {expect(screen.queryByText('View')).not.toBeInTheDocument()// Other actions remain.expect(screen.getByText('Save')).toBeInTheDocument()- expect(screen.getByText('MD')).toBeInTheDocument()+ expect(screen.getByText('PNG')).toBeInTheDocument()})})diff --git a/frontend/src/utils/__tests__/exportMarkdown.test.ts b/frontend/src/utils/__tests__/exportMarkdown.test.tsdeleted file mode 100644index edd52a1..0000000--- a/frontend/src/utils/__tests__/exportMarkdown.test.ts+++ /dev/null@@ -1,93 +0,0 @@-import { describe, it, expect } from 'vitest'-import { generateMarkdownTable } from '../exportMarkdown'-import type { Node } from '@xyflow/react'-import type { NodeData } from '@/types'--const makeNode = (overrides: Partial<NodeData> = {}, id = '1'): Node<NodeData> => ({- id,- type: overrides.type ?? 'server',- position: { x: 0, y: 0 },- data: { label: 'Test', type: 'server', status: 'online', services: [], ...overrides },-})--describe('generateMarkdownTable', () => {- it('returns empty string for empty node list', () => {- expect(generateMarkdownTable([])).toBe('')- })-- it('excludes groupRect nodes', () => {- const nodes = [makeNode({ type: 'groupRect', label: 'Zone' })]- expect(generateMarkdownTable(nodes)).toBe('')- })-- it('generates header + separator + row', () => {- const nodes = [makeNode({ label: 'Router', type: 'router', ip: '192.168.1.1', status: 'online' })]- const md = generateMarkdownTable(nodes)- const lines = md.split('\n')- expect(lines[0]).toContain('Label')- expect(lines[0]).toContain('IP')- expect(lines[1]).toContain('---')- expect(lines[2]).toContain('Router')- expect(lines[2]).toContain('192.168.1.1')- })-- it('uses — for missing fields', () => {- const nodes = [makeNode({ label: 'Node', type: 'generic', ip: undefined, hostname: undefined })]- const md = generateMarkdownTable(nodes)- expect(md).toContain('—')- })-- it('lists services as name:port pairs', () => {- const nodes = [makeNode({- label: 'Server',- services: [{ port: 80, protocol: 'tcp', service_name: 'nginx' }, { port: 443, protocol: 'tcp', service_name: 'https' }],- })]- const md = generateMarkdownTable(nodes)- expect(md).toContain('nginx:80')- expect(md).toContain('https:443')- })-- it('escapes pipe characters in cell values', () => {- const nodes = [makeNode({ label: 'A|B' })]- const md = generateMarkdownTable(nodes)- expect(md).toContain('A\\|B')- })-- it('escapes backslashes before pipes so the escape char is not ambiguous', () => {- const nodes = [makeNode({ label: 'A\\|B' })]- const md = generateMarkdownTable(nodes)- // backslash doubled, then the literal pipe escaped- expect(md).toContain('A\\\\\\|B')- })-- it('collapses newlines in cell values so they do not break the table', () => {- const nodes = [makeNode({ label: 'line1\nline2', hostname: 'a\r\nb' })]- const lines = generateMarkdownTable(nodes).split('\n')- // header + separator + exactly one data row (no extra line from the value)- expect(lines).toHaveLength(3)- expect(lines[2]).toContain('line1 line2')- expect(lines[2]).toContain('a b')- })-- it('escapes pipe characters inside service names', () => {- const nodes = [makeNode({- label: 'Server',- services: [{ port: 80, protocol: 'tcp', service_name: 'web|proxy' }],- })]- const lines = generateMarkdownTable(nodes).split('\n')- // header + separator + exactly one data row — the pipe must not add a column- expect(lines).toHaveLength(3)- expect(lines[2]).toContain('web\\|proxy')- })-- it('generates one row per non-groupRect node', () => {- const nodes = [- makeNode({ type: 'server', label: 'A' }, '1'),- makeNode({ type: 'router', label: 'B' }, '2'),- makeNode({ type: 'groupRect', label: 'Zone' }, '3'),- ]- const lines = generateMarkdownTable(nodes).split('\n')- // header + separator + 2 data rows- expect(lines).toHaveLength(4)- })-})diff --git a/frontend/src/utils/exportMarkdown.ts b/frontend/src/utils/exportMarkdown.tsdeleted file mode 100644index 7205b9f..0000000--- a/frontend/src/utils/exportMarkdown.ts+++ /dev/null@@ -1,49 +0,0 @@-import type { Node } from '@xyflow/react'-import type { NodeData } from '@/types'--const EMPTY = '—'--function cell(v: string | null | undefined): string {- if (!v) return EMPTY- // Escape backslashes first, then pipes, and collapse newlines so they don't break the table- return v- .replace(/\\/g, '\\\\')- .replace(/\|/g, '\\|')- .replace(/\r?\n/g, ' ')-}--export function generateMarkdownTable(nodes: Node<NodeData>[]): string {- const rows = nodes- .filter((n) => n.data.type !== 'groupRect')- .map((n) => {- const d = n.data- const services = d.services?.length- ? d.services.map((s) => {- const port = s.port != null ? `:${s.port}` : ''- const path = s.path?.trim() ? s.path.trim() : ''- return `${s.service_name}${port}${path}`- }).join(', ')- : EMPTY- return [- cell(d.label),- cell(d.type),- cell(d.ip),- cell(d.hostname),- cell(d.status),- cell(services),- ]- })-- if (rows.length === 0) return ''-- const headers = ['Label', 'Type', 'IP', 'Hostname', 'Status', 'Services']- const separator = headers.map(() => '---')-- const lines = [- `| ${headers.join(' | ')} |`,- `| ${separator.join(' | ')} |`,- ...rows.map((r) => `| ${r.join(' | ')} |`),- ]-- return lines.join('\n')-}