Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
feat(inventory): group the device sheet by what a reader is after
Pouzorbe2c5ce7e290
diff --git a/frontend/src/components/modals/InventoryDeviceModal.tsx b/frontend/src/components/modals/InventoryDeviceModal.tsxindex ba1bdac..1d37f59 100644--- a/frontend/src/components/modals/InventoryDeviceModal.tsx+++ b/frontend/src/components/modals/InventoryDeviceModal.tsx@@ -15,7 +15,22 @@* reads in one screen instead of a scrolling column of key-value pairs.*/import { useEffect, useState } from 'react'-import { Check, Copy, Layers, Pencil, Plus, X } from 'lucide-react'+import {+ Check,+ Copy,+ Factory,+ Fingerprint,+ HeartPulse,+ History,+ Layers,+ Network,+ Pencil,+ Plus,+ StickyNote,+ Tags,+ X,+ type LucideIcon,+} from 'lucide-react'import { toast } from 'sonner'import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'import { Button } from '@/components/ui/button'@@ -91,20 +106,25 @@ function categoryColor(category: string | null | undefined) {return CATEGORY_COLORS[category.toLowerCase()] ?? '#8b949e'}-/** A section card: heading bar, optional action, body. */+/** A section card: heading bar with its icon, optional action, body. */function Section({title,+ icon: Icon,action,children,}: {title: string+ icon: LucideIconaction?: React.ReactNodechildren: React.ReactNode}) {return (<section className="rounded-lg border border-[#30363d] bg-[#161b22] overflow-hidden"><header className="flex items-center justify-between gap-2 px-3 py-2 border-b border-[#30363d] bg-[#0d1117]/50">- <span className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">{title}</span>+ <span className="flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">+ <Icon size={12} className="text-muted-foreground/70" aria-hidden />+ {title}+ </span>{action}</header><div className="p-3">{children}</div>@@ -398,7 +418,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn{editing ? (<div className="grid grid-cols-1 lg:grid-cols-3 gap-4 items-start"><div className="flex flex-col gap-4 min-w-0">- <Section title="Identity">+ <Section title="Identity" icon={Fingerprint}><div className="grid grid-cols-2 gap-3"><Field label="Name" className="col-span-2"><Input value={form.label} onChange={(e) => set('label', e.target.value)} placeholder="Display name" className={INPUT} />@@ -440,7 +460,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div></Section>- <Section title="Make & model">+ <Section title="Make & model" icon={Factory}><div className="grid grid-cols-2 gap-3"><Field label="Vendor"><Input value={form.vendor} onChange={(e) => set('vendor', e.target.value)} className={INPUT} />@@ -459,7 +479,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div><div className="flex flex-col gap-4 min-w-0">- <Section title="Monitoring">+ <Section title="Monitoring" icon={HeartPulse}><div className="grid grid-cols-2 gap-3"><Field label="Check method"><Select value={form.check_method || undefined} onValueChange={(v) => set('check_method', (v as string | null) ?? '')}>@@ -479,7 +499,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div></Section>- <Section title="Notes">+ <Section title="Notes" icon={StickyNote}><Textareavalue={form.notes}onChange={(e) => set('notes', e.target.value)}@@ -505,6 +525,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn<Sectiontitle={`Services${services.length > 0 ? ` (${services.length})` : ''}`}+ icon={Network}action={<buttononClick={() => setSvcModal({ index: null })}@@ -548,8 +569,9 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div>) : (<div className="grid grid-cols-1 lg:grid-cols-3 gap-4 items-start">- <div className="flex flex-col gap-4 min-w-0">- <Section title="Identity">+ {/* What the device is: how to reach it, and what answers there. */}+ <div className="flex flex-col gap-4 min-w-0" data-testid="device-column-identity">+ <Section title="Identity" icon={Fingerprint}><div className="flex flex-col">{device.ip && <InfoRow label="IP" value={device.ip} copyable />}{device.hostname && <InfoRow label="Hostname" value={device.hostname} copyable />}@@ -572,10 +594,41 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div></Section>+ {/* Zigbee devices have no IP services — the section would always be empty. */}+ {!isZigbee && (+ <Section title={`Services found (${device.services.length})`} icon={Network}>+ {device.services.length === 0 ? (+ <Empty>No services detected</Empty>+ ) : (+ <div className="flex flex-col gap-1.5 max-h-72 overflow-y-auto">+ {device.services.map((svc, i) => (+ <div+ key={i}+ className="flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#21262d] border border-[#30363d] text-xs"+ >+ <span+ className="w-1.5 h-1.5 rounded-full shrink-0"+ style={{ backgroundColor: categoryColor(svc.category) }}+ />+ <span className="font-mono text-[#00d4ff] w-10 shrink-0">{svc.port}</span>+ <span className="text-muted-foreground w-8 shrink-0">{svc.protocol}</span>+ <span className="text-foreground truncate">{svc.service_name}</span>+ {svc.category && (+ <span className="ml-auto text-[10px] shrink-0" style={{ color: categoryColor(svc.category) }}>+ {svc.category}+ </span>+ )}+ </div>+ ))}+ </div>+ )}+ </Section>+ )}</div>- <div className="flex flex-col gap-4 min-w-0">- <Section title="Monitoring">+ {/* How it is watched, and what happened to it. */}+ <div className="flex flex-col gap-4 min-w-0" data-testid="device-column-operations">+ <Section title="Monitoring" icon={HeartPulse}><div className="flex flex-col">{device.check_method ? (<InfoRow@@ -593,7 +646,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div></Section>- <Section title="Activity">+ <Section title="Activity" icon={History}><div className="flex flex-col">{timestamps.length === 0 ? (<Empty>No activity recorded.</Empty>@@ -603,7 +656,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</div></Section>- <Section title="Notes">+ <Section title="Notes" icon={StickyNote}>{device.notes ? (<p className="text-xs text-foreground/80 whitespace-pre-wrap">{device.notes}</p>) : (@@ -612,8 +665,12 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</Section></div>- <div className="flex flex-col gap-4 min-w-0">- <Section title={`Properties${device.properties && device.properties.length > 0 ? ` (${device.properties.length})` : ''}`}>+ {/* What the user curated. */}+ <div className="flex flex-col gap-4 min-w-0" data-testid="device-column-curation">+ <Section+ title={`Properties${device.properties && device.properties.length > 0 ? ` (${device.properties.length})` : ''}`}+ icon={Tags}+ >{device.properties && device.properties.length > 0 ? (<div className="flex flex-col gap-1.5">{device.properties.map((prop, i) => (@@ -628,36 +685,6 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn)}</Section>- {/* Zigbee devices have no IP services — the section would always be empty. */}- {!isZigbee && (- <Section title={`Services found (${device.services.length})`}>- {device.services.length === 0 ? (- <Empty>No services detected</Empty>- ) : (- <div className="flex flex-col gap-1.5 max-h-72 overflow-y-auto">- {device.services.map((svc, i) => (- <div- key={i}- className="flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#21262d] border border-[#30363d] text-xs"- >- <span- className="w-1.5 h-1.5 rounded-full shrink-0"- style={{ backgroundColor: categoryColor(svc.category) }}- />- <span className="font-mono text-[#00d4ff] w-10 shrink-0">{svc.port}</span>- <span className="text-muted-foreground w-8 shrink-0">{svc.protocol}</span>- <span className="text-foreground truncate">{svc.service_name}</span>- {svc.category && (- <span className="ml-auto text-[10px] shrink-0" style={{ color: categoryColor(svc.category) }}>- {svc.category}- </span>- )}- </div>- ))}- </div>- )}- </Section>- )}</div></div>)}diff --git a/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx b/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsxindex 02c87de..e3d27ce 100644--- a/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx+++ b/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx@@ -73,6 +73,30 @@ describe('InventoryDeviceModal — header', () => {})describe('InventoryDeviceModal — view sections', () => {+ // What answers on a host belongs beside how to reach it, not in the curation+ // column next to the properties.+ it('puts the services under Identity', () => {+ render(+ <InventoryDeviceModal+ {...noop}+ device={makeDevice({ services: [{ port: 22, protocol: 'tcp', service_name: 'SSH' }] })}+ />+ )+ const identity = screen.getByTestId('device-column-identity')+ expect(identity).toHaveTextContent('Identity')+ expect(identity).toHaveTextContent('Services found (1)')+ expect(screen.getByTestId('device-column-curation')).not.toHaveTextContent('Services found')+ })++ it('heads every section with an icon', () => {+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)+ const headings = [...screen.getByRole('dialog').querySelectorAll('section > header > span:first-child')]+ expect(headings.length).toBeGreaterThan(0)+ for (const heading of headings) {+ expect(heading.querySelector('svg')).not.toBeNull()+ }+ })+it('keeps a section with an empty-state rather than dropping it', () => {render(<InventoryDeviceModal {...noop} device={makeDevice()} />)expect(screen.getByText('No properties.')).toBeInTheDocument()