Skip to content

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

fix(canvas): give a valueless property label the full node width

Pouzor9bc02d61c200
diff --git a/frontend/src/components/canvas/nodes/BaseNode.tsx b/frontend/src/components/canvas/nodes/BaseNode.tsx
index 294418b..ee53082 100644
--- a/frontend/src/components/canvas/nodes/BaseNode.tsx
+++ b/frontend/src/components/canvas/nodes/BaseNode.tsx
@@ -146,11 +146,12 @@ export function BaseNode({ id, data, selected, icon: typeIcon, width, height }:
<div className="flex flex-col gap-1 px-2.5 py-1.5 overflow-hidden">
{visibleProperties.map((prop) => {
const Icon = resolvePropertyIcon(prop.icon)
+ const hasValue = Boolean(prop.value.trim())
return (
<div key={prop.key} className="flex items-center gap-1 font-mono text-[10px] min-w-0 overflow-hidden" style={{ color: theme.colors.nodeSubtextColor }}>
{Icon && <Icon size={9} className="shrink-0" />}
- <span className="truncate max-w-15 shrink-0" title={prop.key}>{prop.key}</span>
- {prop.value.trim() && (
+ <span className={hasValue ? 'truncate max-w-15 shrink-0' : 'truncate min-w-0'} title={prop.key}>{prop.key}</span>
+ {hasValue && (
<span className="truncate min-w-0" title={prop.value}>· {prop.value}</span>
)}
</div>
diff --git a/frontend/src/components/canvas/nodes/ProxmoxGroupNode.tsx b/frontend/src/components/canvas/nodes/ProxmoxGroupNode.tsx
index e56acd1..adb2e91 100644
--- a/frontend/src/components/canvas/nodes/ProxmoxGroupNode.tsx
+++ b/frontend/src/components/canvas/nodes/ProxmoxGroupNode.tsx
@@ -107,6 +107,7 @@ export function ProxmoxGroupNode(props: NodeProps<Node<NodeData>>) {
{/* Properties */}
{data.properties?.filter((p) => p.visible).map((prop, i, arr) => {
const Icon = resolvePropertyIcon(prop.icon)
+ const hasValue = Boolean(prop.value.trim())
return (
<div
key={prop.key}
@@ -119,8 +120,8 @@ export function ProxmoxGroupNode(props: NodeProps<Node<NodeData>>) {
}}
>
{Icon && <Icon size={9} className="shrink-0" />}
- <span className="truncate max-w-15 shrink-0" title={prop.key}>{prop.key}</span>
- {prop.value.trim() && (
+ <span className={hasValue ? 'truncate max-w-15 shrink-0' : 'truncate min-w-0'} title={prop.key}>{prop.key}</span>
+ {hasValue && (
<span className="truncate min-w-0" title={prop.value}>· {prop.value}</span>
)}
</div>
diff --git a/frontend/src/components/canvas/nodes/__tests__/BaseNode.properties.test.tsx b/frontend/src/components/canvas/nodes/__tests__/BaseNode.properties.test.tsx
new file mode 100644
index 0000000..bff8772
--- /dev/null
+++ b/frontend/src/components/canvas/nodes/__tests__/BaseNode.properties.test.tsx
@@ -0,0 +1,62 @@
+/**
+ * A property with no value gives its whole line to the label.
+ *
+ * The label is capped at max-w-15 so a long key cannot crowd out the value
+ * beside it. With no value there is nothing to protect, and keeping the cap
+ * truncated the label against empty space (issue #361).
+ */
+import { describe, it, expect, vi } from 'vitest'
+import { render } from '@testing-library/react'
+import { ReactFlowProvider } from '@xyflow/react'
+import { Server } from 'lucide-react'
+import { BaseNode } from '../BaseNode'
+import type { NodeData, NodeProperty } from '@/types'
+
+vi.mock('@/stores/canvasStore', async () => {
+ const actual = await vi.importActual<typeof import('@/stores/canvasStore')>('@/stores/canvasStore')
+ return {
+ ...actual,
+ useCanvasStore: (selector: (s: Record<string, unknown>) => unknown) =>
+ selector({ hideIp: false, serviceStatuses: {} }),
+ }
+})
+
+function renderNode(properties: NodeProperty[]) {
+ const data: NodeData = { label: 'NAS', type: 'nas', status: 'online', properties }
+ return render(
+ <ReactFlowProvider>
+ <BaseNode
+ {...({ id: 'n1', data, selected: false, icon: Server } as React.ComponentProps<typeof BaseNode>)}
+ />
+ </ReactFlowProvider>,
+ )
+}
+
+function labelOf(container: HTMLElement, key: string) {
+ return [...container.querySelectorAll('span')].find((s) => s.textContent === key)
+}
+
+const prop = (key: string, value: string): NodeProperty => ({ key, value, visible: true })
+
+describe('BaseNode properties', () => {
+ it('drops the label width cap when the value is empty', () => {
+ const { container } = renderNode([prop('A very long property label', '')])
+ const label = labelOf(container, 'A very long property label')
+ expect(label).toBeDefined()
+ expect(label!.className).not.toContain('max-w-15')
+ expect(label!.className).toContain('min-w-0')
+ })
+
+ it('treats a whitespace-only value as empty', () => {
+ const { container } = renderNode([prop('Label', ' ')])
+ const label = labelOf(container, 'Label')
+ expect(label!.className).not.toContain('max-w-15')
+ })
+
+ it('keeps the cap when a value shares the line', () => {
+ const { container } = renderNode([prop('Label', '42')])
+ const label = labelOf(container, 'Label')
+ expect(label!.className).toContain('max-w-15')
+ expect(container.textContent).toContain('· 42')
+ })
+})