Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(yaml): round-trip show_port_numbers on export/import

Pouzor16d6348cec5c
diff --git a/frontend/src/types/yaml.ts b/frontend/src/types/yaml.ts
index 02758f0..8e1e78e 100644
--- a/frontend/src/types/yaml.ts
+++ b/frontend/src/types/yaml.ts
@@ -34,4 +34,7 @@ export interface YamlNode {
bottomHandles?: number
leftHandles?: number
rightHandles?: number
+ // Whether port-number labels are shown next to connection points. Only written
+ // when enabled so the toggle round-trips through export/import (issue #272).
+ showPortNumbers?: boolean
}
diff --git a/frontend/src/utils/__tests__/exportYaml.test.ts b/frontend/src/utils/__tests__/exportYaml.test.ts
index 83a4ff2..c87afa6 100644
--- a/frontend/src/utils/__tests__/exportYaml.test.ts
+++ b/frontend/src/utils/__tests__/exportYaml.test.ts
@@ -208,4 +208,12 @@ describe('exportCanvasToYaml', () => {
expect(entry).not.toHaveProperty('topHandles')
expect(entry).not.toHaveProperty('leftHandles')
})
+
+ it('exports showPortNumbers only when enabled (issue #272)', () => {
+ const on = (yaml.load(exportCanvasToYaml([makeNode({ label: 'On', type: 'server', show_port_numbers: true })], [])) as Record<string, unknown>[])[0]
+ expect(on.showPortNumbers).toBe(true)
+
+ const off = (yaml.load(exportCanvasToYaml([makeNode({ label: 'Off', type: 'server', show_port_numbers: false })], [])) as Record<string, unknown>[])[0]
+ expect(off).not.toHaveProperty('showPortNumbers')
+ })
})
diff --git a/frontend/src/utils/__tests__/importYaml.test.ts b/frontend/src/utils/__tests__/importYaml.test.ts
index 6b4db95..dfc481e 100644
--- a/frontend/src/utils/__tests__/importYaml.test.ts
+++ b/frontend/src/utils/__tests__/importYaml.test.ts
@@ -368,4 +368,30 @@ describe('parseYamlToCanvas', () => {
expect(edges[0].targetHandle).toBe('top-t')
expect(nodes.find((n) => n.data.label === 'Switch')!.data.bottom_handles).toBe(3)
})
+
+ // Regression for issue #272.
+ it('restores the show-port-numbers toggle from YAML', () => {
+ const yaml = `
+- nodeType: server
+ label: "Server"
+ showPortNumbers: true
+`
+ const { nodes } = parseYamlToCanvas(yaml, empty, emptyEdges)
+ expect(nodes.find((n) => n.data.label === 'Server')!.data.show_port_numbers).toBe(true)
+ })
+
+ it('round-trips show-port-numbers through export → import (issue #272)', () => {
+ const on: Node<NodeData> = {
+ id: 'on', type: 'server', position: { x: 0, y: 0 },
+ data: { label: 'On', type: 'server', status: 'online', services: [], show_port_numbers: true },
+ }
+ const off: Node<NodeData> = {
+ id: 'off', type: 'server', position: { x: 0, y: 0 },
+ data: { label: 'Off', type: 'server', status: 'online', services: [] },
+ }
+ const yamlStr = exportCanvasToYaml([on, off], [])
+ const { nodes } = parseYamlToCanvas(yamlStr, empty, emptyEdges)
+ expect(nodes.find((n) => n.data.label === 'On')!.data.show_port_numbers).toBe(true)
+ expect(nodes.find((n) => n.data.label === 'Off')!.data.show_port_numbers).toBeUndefined()
+ })
})
diff --git a/frontend/src/utils/exportYaml.ts b/frontend/src/utils/exportYaml.ts
index f2a9772..75ef513 100644
--- a/frontend/src/utils/exportYaml.ts
+++ b/frontend/src/utils/exportYaml.ts
@@ -92,6 +92,9 @@ export function exportCanvasToYaml(nodes: Node<NodeData>[], edges: Edge<EdgeData
// Custom connection-point counts, so imported edges land on real slots.
attachHandleCounts(entry, d)
+ // Preserve the port-number toggle so it survives a round-trip (issue #272).
+ if (d.show_port_numbers) entry.showPortNumbers = true
+
// Parent relationship: if this node has a parentId in React Flow,
// encode it as a 'parent' connection using any virtual edge between them.
if (node.parentId) {
diff --git a/frontend/src/utils/importYaml.ts b/frontend/src/utils/importYaml.ts
index 5332d48..9c1ea00 100644
--- a/frontend/src/utils/importYaml.ts
+++ b/frontend/src/utils/importYaml.ts
@@ -79,6 +79,8 @@ export function parseYamlToCanvas(
...(yn.bottomHandles ? { bottom_handles: yn.bottomHandles } : {}),
...(yn.leftHandles ? { left_handles: yn.leftHandles } : {}),
...(yn.rightHandles ? { right_handles: yn.rightHandles } : {}),
+ // Restore the port-number toggle (issue #272).
+ ...(yn.showPortNumbers ? { show_port_numbers: true } : {}),
}
newNodes.push({