fix(yaml): round-trip show_port_numbers on export/import
YAML export wrote per-side handle counts but never the show_port_numbers toggle, so the option was lost on re-import while connection points survived. ha-relevant: maybe Fixes #272
This commit is contained in:
@@ -34,4 +34,7 @@ export interface YamlNode {
|
|||||||
bottomHandles?: number
|
bottomHandles?: number
|
||||||
leftHandles?: number
|
leftHandles?: number
|
||||||
rightHandles?: 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,4 +208,12 @@ describe('exportCanvasToYaml', () => {
|
|||||||
expect(entry).not.toHaveProperty('topHandles')
|
expect(entry).not.toHaveProperty('topHandles')
|
||||||
expect(entry).not.toHaveProperty('leftHandles')
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -368,4 +368,30 @@ describe('parseYamlToCanvas', () => {
|
|||||||
expect(edges[0].targetHandle).toBe('top-t')
|
expect(edges[0].targetHandle).toBe('top-t')
|
||||||
expect(nodes.find((n) => n.data.label === 'Switch')!.data.bottom_handles).toBe(3)
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ export function exportCanvasToYaml(nodes: Node<NodeData>[], edges: Edge<EdgeData
|
|||||||
// Custom connection-point counts, so imported edges land on real slots.
|
// Custom connection-point counts, so imported edges land on real slots.
|
||||||
attachHandleCounts(entry, d)
|
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,
|
// Parent relationship: if this node has a parentId in React Flow,
|
||||||
// encode it as a 'parent' connection using any virtual edge between them.
|
// encode it as a 'parent' connection using any virtual edge between them.
|
||||||
if (node.parentId) {
|
if (node.parentId) {
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ export function parseYamlToCanvas(
|
|||||||
...(yn.bottomHandles ? { bottom_handles: yn.bottomHandles } : {}),
|
...(yn.bottomHandles ? { bottom_handles: yn.bottomHandles } : {}),
|
||||||
...(yn.leftHandles ? { left_handles: yn.leftHandles } : {}),
|
...(yn.leftHandles ? { left_handles: yn.leftHandles } : {}),
|
||||||
...(yn.rightHandles ? { right_handles: yn.rightHandles } : {}),
|
...(yn.rightHandles ? { right_handles: yn.rightHandles } : {}),
|
||||||
|
// Restore the port-number toggle (issue #272).
|
||||||
|
...(yn.showPortNumbers ? { show_port_numbers: true } : {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
newNodes.push({
|
newNodes.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user