Skip to content

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

fix(canvas): seed a group child near its group and refuse nested groups

Pouzor59079d90ca69
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 85fcaa7..8b0f9dc 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -498,7 +498,9 @@ export default function App() {
// parent the LXC/VM stays a free node (linked by a virtual edge) — setting
// extent:'parent' on a non-container would trap it inside the parent's tiny
// bounding box with no way to drag it out (issue #205 follow-up).
- const nestInParent = !!parentNode?.data.container_mode
+ // A visual group nests too, so it seeds its position the same way — mirrors
+ // the condition in the store's addNode, which is the authority here.
+ const nestInParent = !!parentNode?.data.container_mode || parentNode?.data.type === 'group'
// Seed an ABSOLUTE position near the container's top-left; addNode converts
// it to container-relative. addNode is the single authority for parentId /
// extent, so we don't set them here.
diff --git a/frontend/src/components/modals/__tests__/NodeModal.test.tsx b/frontend/src/components/modals/__tests__/NodeModal.test.tsx
index 0d2a753..e01b6df 100644
--- a/frontend/src/components/modals/__tests__/NodeModal.test.tsx
+++ b/frontend/src/components/modals/__tests__/NodeModal.test.tsx
@@ -443,12 +443,21 @@ describe('NodeModal', () => {
expect((onSubmit.mock.calls[0][0] as Partial<NodeData>).parent_id).toBe('g1')
})
- it('offers a group as a parent for a plain node', () => {
+ it('offers a group as a parent option for a plain node', () => {
renderModal({
initial: { ...BASE, type: 'server' },
parentCandidates: [{ id: 'g1', label: 'My Group', type: 'group' }],
})
- expect(screen.getByText('Parent Container')).toBeDefined()
+ const option = screen.getByRole('option', { name: 'My Group' }) as HTMLOptionElement
+ expect(option.value).toBe('g1')
+ })
+
+ it('does not offer a group as a parent for another group', () => {
+ renderModal({
+ initial: { ...BASE, type: 'group' },
+ parentCandidates: [{ id: 'g1', label: 'My Group', type: 'group' }],
+ })
+ expect(screen.queryByText('Parent Container')).toBeNull()
})
// ── Appearance ────────────────────────────────────────────────────────
diff --git a/frontend/src/utils/__tests__/virtualEdgeParent.test.ts b/frontend/src/utils/__tests__/virtualEdgeParent.test.ts
index 36938a6..1e9779e 100644
--- a/frontend/src/utils/__tests__/virtualEdgeParent.test.ts
+++ b/frontend/src/utils/__tests__/virtualEdgeParent.test.ts
@@ -37,6 +37,11 @@ describe('isValidParentNode', () => {
expect(isValidParentNode('lxc', { type: 'proxmox' })).toBe(true)
})
+ it('rejects a group or a zone as the child of a group', () => {
+ expect(isValidParentNode('group', { type: 'group' })).toBe(false)
+ expect(isValidParentNode('groupRect', { type: 'group' })).toBe(false)
+ })
+
it('rejects a non-container node that no type rule allows', () => {
expect(isValidParentNode('server', { type: 'proxmox', container_mode: false })).toBe(false)
expect(isValidParentNode('server', { type: 'groupRect' })).toBe(false)
diff --git a/frontend/src/utils/virtualEdgeParent.ts b/frontend/src/utils/virtualEdgeParent.ts
index 126ba0a..d772dec 100644
--- a/frontend/src/utils/virtualEdgeParent.ts
+++ b/frontend/src/utils/virtualEdgeParent.ts
@@ -29,13 +29,14 @@ export function getValidParentTypes(childType: NodeType): NodeType[] {
*
* A visual group holds any node type — the type rules above only govern
* virtual (container) nesting, so they'd wrongly reject a grouped node and
- * drop it out of its group on the next edit.
+ * drop it out of its group on the next edit. Groups and zones are excluded as
+ * children, matching what the drag-onto-a-group path accepts.
*/
export function isValidParentNode(
childType: NodeType,
parent: { type: NodeType; container_mode?: boolean },
): boolean {
- if (parent.type === 'group') return true
+ if (parent.type === 'group') return childType !== 'group' && childType !== 'groupRect'
return getValidParentTypes(childType).includes(parent.type) || parent.container_mode === true
}