feat: editable container selector to detach/re-parent a nested node

When a node is nested in a container, the detail panel now shows a
Container selector. Pick another container to move it, or "None" to
detach it back to the canvas (clears parentId).

- store: setNodeParent(childId, parentId|null) — attach/detach/re-parent
  via absolute coords, container_mode-only targets, history snapshot
- DetailPanel: Container <select>, shown only for nested nodes

ha-relevant: yes
This commit is contained in:
Pouzor
2026-06-11 15:39:49 +02:00
parent 2058e453ff
commit 10b981ad1d
4 changed files with 220 additions and 1 deletions
@@ -43,6 +43,7 @@ const mockStore = {
createGroup: vi.fn(),
ungroup: vi.fn(),
removeFromGroup: vi.fn(),
setNodeParent: vi.fn(),
}
function setupStore(overrides = {}) {
@@ -138,6 +139,50 @@ describe('MultiSelectPanel', () => {
})
})
describe('DetailPanel container selector', () => {
beforeEach(() => vi.clearAllMocks())
function makeContainer(id: string, label: string) {
return { id, type: 'proxmox', position: { x: 0, y: 0 }, data: { label, type: 'proxmox', status: 'online', services: [], container_mode: true } }
}
it('does not show the container selector for a top-level node', () => {
const n1 = makeNode('n1')
setupStore({ nodes: [n1], selectedNodeId: 'n1', selectedNodeIds: ['n1'] })
renderPanel()
expect(screen.queryByLabelText('Container')).toBeNull()
})
it('shows the container selector for a nested node, defaulting to its parent', () => {
const px = makeContainer('px1', 'Proxmox')
const child = makeNode('n1', { parentId: 'px1' })
setupStore({ nodes: [px, child], selectedNodeId: 'n1', selectedNodeIds: ['n1'] })
renderPanel()
expect((screen.getByLabelText('Container') as HTMLSelectElement).value).toBe('px1')
})
it('detaches the node when "None" is selected', () => {
const setNodeParent = vi.fn()
const px = makeContainer('px1', 'Proxmox')
const child = makeNode('n1', { parentId: 'px1' })
setupStore({ nodes: [px, child], selectedNodeId: 'n1', selectedNodeIds: ['n1'], setNodeParent })
renderPanel()
fireEvent.change(screen.getByLabelText('Container'), { target: { value: '' } })
expect(setNodeParent).toHaveBeenCalledWith('n1', null)
})
it('re-parents the node when another container is selected', () => {
const setNodeParent = vi.fn()
const px1 = makeContainer('px1', 'Proxmox A')
const px2 = makeContainer('px2', 'Proxmox B')
const child = makeNode('n1', { parentId: 'px1' })
setupStore({ nodes: [px1, px2, child], selectedNodeId: 'n1', selectedNodeIds: ['n1'], setNodeParent })
renderPanel()
fireEvent.change(screen.getByLabelText('Container'), { target: { value: 'px2' } })
expect(setNodeParent).toHaveBeenCalledWith('n1', 'px2')
})
})
describe('GroupDetailPanel', () => {
beforeEach(() => vi.clearAllMocks())