Skip to content

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

feat(inventory): make the device detail modal readable

Pouzorb4b22cc68f1e
diff --git a/frontend/src/components/modals/InventoryDeviceModal.tsx b/frontend/src/components/modals/InventoryDeviceModal.tsx
index b395dff..ba1bdac 100644
--- a/frontend/src/components/modals/InventoryDeviceModal.tsx
+++ b/frontend/src/components/modals/InventoryDeviceModal.tsx
@@ -3,11 +3,19 @@
*
* The inventory row owns what a device is; a canvas node only owns how it is
* drawn. So everything a user can curate on a node — properties, services,
- * notes, hardware specs, check method — is editable here too, through the same
- * editors the canvas uses (`PropertyList`, `ServiceModal`).
+ * notes, check method — is editable here too, through the same editors the
+ * canvas uses (`PropertyList`, `ServiceModal`).
+ *
+ * Hardware specs are properties like any other: `cpu_*` / `ram_gb` / `disk_gb`
+ * still carry what Proxmox and the YAML import record, but nothing draws them,
+ * so they are not edited here — CPU / RAM / Disk are property suggestions.
+ *
+ * Layout mirrors `NodeModal`: one wide dialog, a header carrying identity and
+ * badges, then three columns — identity / operations / curation — so a device
+ * reads in one screen instead of a scrolling column of key-value pairs.
*/
import { useEffect, useState } from 'react'
-import { Globe, Router, Server, Layers, Box, Container, HardDrive, Cpu, Wifi, Circle, Network, Pencil, Plus, X } from 'lucide-react'
+import { Check, Copy, Layers, Pencil, Plus, X } from 'lucide-react'
import { toast } from 'sonner'
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
@@ -18,10 +26,15 @@ import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSepa
import { PropertyList } from '@/components/common/PropertyList'
import { ServiceModal } from './ServiceModal'
import { scanApi } from '@/api/client'
-import { isRackDevice } from '@/utils/deviceSources'
+import { useThemeStore } from '@/stores/themeStore'
+import { resolveNodeColors } from '@/utils/nodeColors'
+import { NODE_TYPE_DEFAULT_ICONS } from '@/utils/nodeIcons'
+import { isRackDevice, orderedSources, SOURCE_META } from '@/utils/deviceSources'
import { DEVICE_TYPE_GROUPS } from '@/utils/nodeTypeGroups'
+import { formatRelative, formatTimestamp } from '@/utils/timeFormat'
import { serviceToForm, type ServiceFormData, type ServiceSubmitData } from '@/utils/serviceForm'
-import { NODE_TYPE_LABELS, type CheckMethod, type InventoryEntry, type NodeProperty, type ServiceInfo } from '@/types'
+import { NODE_TYPE_LABELS, type CheckMethod, type InventoryEntry, type NodeProperty, type NodeType, type ServiceInfo } from '@/types'
+import modalStyles from './modal-interactive.module.css'
// Home is `@/types` now — re-exported because most call sites import it here.
export type { InventoryEntry } from '@/types'
@@ -36,20 +49,6 @@ interface InventoryDeviceModalProps {
onSaved?: (device: InventoryEntry) => void
}
-const TYPE_ICONS: Record<string, React.ElementType> = {
- isp: Globe,
- router: Router,
- server: Server,
- proxmox: Layers,
- vm: Box,
- lxc: Container,
- nas: HardDrive,
- iot: Cpu,
- ap: Wifi,
- switch: Network,
- generic: Circle,
-}
-
const CATEGORY_COLORS: Record<string, string> = {
hypervisor: '#ff6e00',
nas: '#39d353',
@@ -66,22 +65,121 @@ const CATEGORY_COLORS: Record<string, string> = {
const CHECK_METHODS: CheckMethod[] = ['ping', 'http', 'https', 'tcp', 'ssh', 'prometheus', 'health', 'none']
+const CHECK_METHOD_LABELS: Record<CheckMethod, string> = {
+ none: 'None',
+ ping: 'Ping',
+ http: 'HTTP',
+ https: 'HTTPS',
+ tcp: 'TCP',
+ ssh: 'SSH',
+ prometheus: 'Prometheus',
+ health: 'Health',
+}
+
+/** Live reachability — not the pending/approved/hidden lifecycle. */
+const LIVE_META: Record<string, { color: string; label: string }> = {
+ online: { color: '#39d353', label: 'Online' },
+ offline: { color: '#f85149', label: 'Offline' },
+ pending: { color: '#e3b341', label: 'Checking' },
+ unknown: { color: '#8b949e', label: 'Unknown' },
+}
+
+const INPUT = 'bg-[#21262d] border-[#30363d] text-sm h-8'
+
function categoryColor(category: string | null | undefined) {
if (!category) return '#8b949e'
return CATEGORY_COLORS[category.toLowerCase()] ?? '#8b949e'
}
-/** Server datetimes come back naive-UTC on legacy rows; pin the zone before parsing. */
-function formatDate(value: string | null | undefined): string | null {
- if (!value) return null
- return new Date(value.endsWith('Z') ? value : value + 'Z').toLocaleString()
+/** A section card: heading bar, optional action, body. */
+function Section({
+ title,
+ action,
+ children,
+}: {
+ title: string
+ action?: React.ReactNode
+ children: 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>
+ {action}
+ </header>
+ <div className="p-3">{children}</div>
+ </section>
+ )
+}
+
+function Chip({ color, children, title }: { color: string; children: React.ReactNode; title?: string }) {
+ return (
+ <span
+ title={title}
+ className="text-[9px] font-mono px-1.5 py-0.5 rounded uppercase tracking-wider"
+ style={{ background: `${color}22`, color }}
+ >
+ {children}
+ </span>
+ )
+}
+
+/** Copies a technical value; the row keeps its own confirmation state. */
+function CopyButton({ label, value }: { label: string; value: string }) {
+ const [copied, setCopied] = useState(false)
+ const copy = () => {
+ // `clipboard` is absent outside a secure context (and in jsdom), so the
+ // promise itself is optional, not just the API.
+ const written = navigator.clipboard?.writeText(value)
+ if (!written) return
+ written
+ .then(() => {
+ setCopied(true)
+ setTimeout(() => setCopied(false), 1200)
+ })
+ .catch(() => toast.error('Could not copy'))
+ }
+ return (
+ <button
+ onClick={copy}
+ aria-label={`Copy ${label}`}
+ className="ml-auto shrink-0 text-muted-foreground/50 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-[#00d4ff] transition-opacity cursor-pointer"
+ >
+ {copied ? <Check size={11} className="text-[#39d353]" /> : <Copy size={11} />}
+ </button>
+ )
+}
+
+function InfoRow({ label, value, copyable }: { label: string; value: string; copyable?: boolean }) {
+ return (
+ <div className="group flex items-baseline gap-3 py-1 border-b border-[#30363d]/40 last:border-b-0 text-xs">
+ <span className="w-20 shrink-0 text-[11px] text-muted-foreground">{label}</span>
+ <span className="min-w-0 font-mono text-foreground break-all">{value}</span>
+ {copyable && <CopyButton label={label} value={value} />}
+ </div>
+ )
+}
+
+/** A timestamp reads relative, with the exact value on hover. */
+function TimeRow({ label, iso }: { label: string; iso: string }) {
+ return (
+ <div className="flex items-baseline gap-3 py-1 border-b border-[#30363d]/40 last:border-b-0 text-xs" title={formatTimestamp(iso)}>
+ <span className="w-20 shrink-0 text-[11px] text-muted-foreground">{label}</span>
+ <span className="font-mono text-foreground/80">{formatRelative(iso)}</span>
+ </div>
+ )
+}
+
+function Empty({ children }: { children: React.ReactNode }) {
+ return <p className="text-xs text-muted-foreground italic">{children}</p>
}
-function InfoRow({ label, value }: { label: string; value: string }) {
+function Field({ label, hint, children, className = '' }: { label: string; hint?: string; children: React.ReactNode; className?: string }) {
return (
- <div className="flex items-baseline gap-2 text-xs">
- <span className="text-muted-foreground w-20 shrink-0">{label}</span>
- <span className="font-mono text-foreground break-all">{value}</span>
+ <div className={`flex flex-col gap-1.5 min-w-0 ${className}`}>
+ <Label className="text-xs text-muted-foreground">{label}</Label>
+ {children}
+ {hint && <span className="text-[10px] text-muted-foreground/50">{hint}</span>}
</div>
)
}
@@ -143,6 +241,7 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn
const [services, setServices] = useState<ServiceInfo[]>(device?.services ?? [])
const [svcModal, setSvcModal] = useState<{ index: number | null; form?: ServiceFormData } | null>(null)
const [saving, setSaving] = useState(false)
+ const activeTheme = useThemeStore((s) => s.activeTheme)
// Reset the form whenever the modal is pointed at another device — the
// component stays mounted across card clicks in the inventory grid.
@@ -157,9 +256,14 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn
if (!device) return null
- const TypeIcon = TYPE_ICONS[device.type ?? device.suggested_type ?? 'generic'] ?? Circle
+ const resolvedType = (device.type ?? device.suggested_type ?? 'generic') as NodeType
+ const TypeIcon = NODE_TYPE_DEFAULT_ICONS[resolvedType] ?? NODE_TYPE_DEFAULT_ICONS.generic
+ // Same accent the node wears on the canvas, so a device looks like itself.
+ const roleColor = resolveNodeColors({ type: resolvedType, custom_colors: undefined }, activeTheme).border
const isZigbee = device.discovery_source === 'zigbee'
const rackOnly = isRackDevice(device)
+ const sources = orderedSources(device)
+ const live = LIVE_META[device.status_live ?? 'unknown'] ?? LIVE_META.unknown
const titleLabel = device.label ?? device.friendly_name ?? device.hostname ?? device.ip ?? device.ieee_address ?? 'Pending device'
const set = <K extends keyof EditForm>(key: K, value: EditForm[K]) => setForm((f) => ({ ...f, [key]: value }))
@@ -168,6 +272,13 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn
const handleHide = () => { onHide(device); onClose() }
const handleIgnore = () => { onIgnore(device); onClose() }
+ const handleCancel = () => {
+ setEditing(false)
+ setForm(toForm(device))
+ setProperties(device.properties ?? [])
+ setServices(device.services ?? [])
+ }
+
const handleSubmitService = (data: ServiceSubmitData) => {
const svc: ServiceInfo = {
...(data.port != null ? { port: data.port } : {}),
@@ -197,6 +308,9 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn
friendly_name: nullable(form.friendly_name),
device_subtype: nullable(form.device_subtype),
notes: nullable(form.notes),
+ // Hardware is curated as properties, like every other spec — these five
+ // are no longer editable here. They still carry Proxmox and YAML data,
+ // so they go back untouched rather than being silently cleared.
cpu_count: numeric(form.cpu_count),
cpu_model: nullable(form.cpu_model),
ram_gb: numeric(form.ram_gb),
@@ -217,323 +331,393 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn
}
}
- const discoveredAt = formatDate(device.discovered_at)
- const hardware = [
- device.cpu_count != null ? `${device.cpu_count} vCPU` : null,
- device.cpu_model,
- device.ram_gb != null ? `${device.ram_gb} GB RAM` : null,
- device.disk_gb != null ? `${device.disk_gb} GB disk` : null,
- ].filter(Boolean).join(' · ')
+ const timestamps: { label: string; iso: string }[] = []
+ if (device.discovered_at) timestamps.push({ label: 'Discovered', iso: device.discovered_at })
+ if (device.node_created_at) timestamps.push({ label: 'On canvas', iso: device.node_created_at })
+ if (device.node_last_scan) timestamps.push({ label: 'Last scan', iso: device.node_last_scan })
+ if (device.node_last_seen) timestamps.push({ label: 'Last seen', iso: device.node_last_seen })
+ if (device.node_last_modified) timestamps.push({ label: 'Modified', iso: device.node_last_modified })
return (
<Dialog open={!!device} onOpenChange={(o) => !o && onClose()}>
- <DialogContent className={`bg-[#161b22] border-[#30363d] text-foreground ${editing ? 'max-w-lg' : 'max-w-sm'} max-h-[85vh] overflow-y-auto`}>
- <DialogHeader>
- <DialogTitle className="flex items-center gap-2 text-sm font-semibold">
- <TypeIcon size={15} className="text-[#00d4ff] shrink-0" />
- {titleLabel}
- {isZigbee && (
- <span className="ml-1 text-[9px] font-mono uppercase px-1 py-0.5 rounded bg-[#00d4ff]/15 text-[#00d4ff] border border-[#00d4ff]/30">
- Zigbee
- </span>
+ <DialogContent className="!max-w-none w-[min(1180px,95vw)] max-h-[90vh] p-0 gap-0 flex flex-col overflow-hidden bg-[#0d1117] border-[#30363d] text-foreground">
+ {/* ── Header: who this device is, at a glance ── */}
+ <DialogHeader className="shrink-0 px-5 py-4 border-b border-[#30363d] bg-[#161b22]">
+ <div className="flex items-start gap-3 pr-10">
+ <div
+ className="w-11 h-11 shrink-0 rounded-lg border flex items-center justify-center"
+ style={{ background: `${roleColor}18`, borderColor: `${roleColor}55`, color: roleColor }}
+ >
+ <TypeIcon size={20} />
+ </div>
+ <div className="min-w-0 flex-1">
+ <DialogTitle className="text-base font-semibold leading-tight break-all">{titleLabel}</DialogTitle>
+ <div className="mt-1.5 flex flex-wrap items-center gap-1.5">
+ {sources.map((s) => (
+ <Chip key={s} color={SOURCE_META[s].color}>{SOURCE_META[s].label}</Chip>
+ ))}
+ {(device.type ?? device.suggested_type) && (
+ <Chip color={roleColor}>{NODE_TYPE_LABELS[resolvedType] ?? resolvedType}</Chip>
+ )}
+ <span
+ className="flex items-center gap-1 text-[9px] font-mono px-1.5 py-0.5 rounded uppercase tracking-wider"
+ style={{ background: `${live.color}22`, color: live.color }}
+ title="Live reachability"
+ >
+ <span className="w-1.5 h-1.5 rounded-full" style={{ background: live.color }} />
+ {live.label}
+ </span>
+ {(device.canvas_count ?? 0) > 0 && (
+ <span
+ className="flex items-center gap-1 text-[9px] font-mono px-1.5 py-0.5 rounded uppercase tracking-wider bg-[#00d4ff]/15 text-[#00d4ff]"
+ title={`Drawn on ${device.canvas_count} canvas${device.canvas_count !== 1 ? 'es' : ''}`}
+ >
+ <Layers size={10} />
+ {device.canvas_count}
+ </span>
+ )}
+ {device.status === 'hidden' && <Chip color="#8b949e">Hidden</Chip>}
+ {device.lqi != null && <Chip color="#8b949e">LQI {device.lqi}</Chip>}
+ </div>
+ </div>
+ {!editing && (
+ <Button
+ size="sm"
+ variant="ghost"
+ className={`shrink-0 gap-1.5 text-[#00d4ff] hover:text-[#00d4ff] hover:bg-[#00d4ff]/10 ${modalStyles['modal-interactive']}`}
+ onClick={() => setEditing(true)}
+ >
+ <Pencil size={13} /> Edit
+ </Button>
)}
- </DialogTitle>
+ </div>
</DialogHeader>
- {editing ? (
- <div className="flex flex-col gap-3 mt-1">
- <div className="grid grid-cols-2 gap-2">
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Name</Label>
- <Input value={form.label} onChange={(e) => set('label', e.target.value)} placeholder="Display name" className="bg-[#21262d] border-[#30363d] text-xs h-7" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Type</Label>
- <Select value={form.type || undefined} onValueChange={(v) => set('type', (v as string | null) ?? '')}>
- <SelectTrigger className="bg-[#21262d] border-[#30363d] text-xs h-7">
- <SelectValue placeholder="Pick a type" />
- </SelectTrigger>
- <SelectContent>
- {DEVICE_TYPE_GROUPS.map((group, i) => (
- <SelectGroup key={group.label}>
- {i > 0 && <SelectSeparator />}
- <SelectLabel className="text-[10px]">{group.label}</SelectLabel>
- {group.types.map((t) => (
- <SelectItem key={t} value={t} className="text-xs">
- {NODE_TYPE_LABELS[t] ?? t}
- </SelectItem>
- ))}
- </SelectGroup>
- ))}
- </SelectContent>
- </Select>
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Hostname</Label>
- <Input value={form.hostname} onChange={(e) => set('hostname', e.target.value)} className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">IP</Label>
- <Input value={form.ip} onChange={(e) => set('ip', e.target.value)} placeholder="10.0.0.5, 10.0.1.5" className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">MAC</Label>
- <Input value={form.mac} onChange={(e) => set('mac', e.target.value)} className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">OS</Label>
- <Input value={form.os} onChange={(e) => set('os', e.target.value)} className="bg-[#21262d] border-[#30363d] text-xs h-7" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Vendor</Label>
- <Input value={form.vendor} onChange={(e) => set('vendor', e.target.value)} className="bg-[#21262d] border-[#30363d] text-xs h-7" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Model</Label>
- <Input value={form.model} onChange={(e) => set('model', e.target.value)} className="bg-[#21262d] border-[#30363d] text-xs h-7" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Check method</Label>
- <Select value={form.check_method || undefined} onValueChange={(v) => set('check_method', (v as string | null) ?? '')}>
- <SelectTrigger className="bg-[#21262d] border-[#30363d] text-xs h-7">
- <SelectValue placeholder="None" />
- </SelectTrigger>
- <SelectContent>
- {CHECK_METHODS.map((m) => (
- <SelectItem key={m} value={m} className="text-xs">{m}</SelectItem>
- ))}
- </SelectContent>
- </Select>
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Check target</Label>
- <Input value={form.check_target} onChange={(e) => set('check_target', e.target.value)} placeholder="host:port or URL" className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">vCPU</Label>
- <Input value={form.cpu_count} onChange={(e) => set('cpu_count', e.target.value.replace(/\D/g, ''))} className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">CPU model</Label>
- <Input value={form.cpu_model} onChange={(e) => set('cpu_model', e.target.value)} className="bg-[#21262d] border-[#30363d] text-xs h-7" />
- </div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">RAM (GB)</Label>
- <Input value={form.ram_gb} onChange={(e) => set('ram_gb', e.target.value.replace(/[^\d.]/g, ''))} className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
+ {/* ── Body: three columns — identity / operations / curation ── */}
+ <div className="flex-1 min-h-0 overflow-y-auto p-5">
+ {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">
+ <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} />
+ </Field>
+ <Field label="Type" className="col-span-2">
+ <Select value={form.type || undefined} onValueChange={(v) => set('type', (v as string | null) ?? '')}>
+ <SelectTrigger className={`${INPUT} w-full cursor-pointer ${modalStyles['modal-interactive']}`} aria-label="Device type selector">
+ <SelectValue placeholder="Pick a type" />
+ </SelectTrigger>
+ <SelectContent className="bg-[#21262d] border-[#30363d]">
+ {DEVICE_TYPE_GROUPS.map((group, i) => (
+ <SelectGroup key={group.label}>
+ {i > 0 && <SelectSeparator className="bg-[#30363d]" />}
+ <SelectLabel className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/50 px-2 py-1">
+ {group.label}
+ </SelectLabel>
+ {group.types.map((t) => (
+ <SelectItem key={t} value={t} className="text-sm pl-4">
+ {NODE_TYPE_LABELS[t] ?? t}
+ </SelectItem>
+ ))}
+ </SelectGroup>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
+ <Field label="Hostname">
+ <Input value={form.hostname} onChange={(e) => set('hostname', e.target.value)} placeholder="server.lan" className={`${INPUT} font-mono`} />
+ </Field>
+ <Field label="IP" hint="comma-separated">
+ <Input value={form.ip} onChange={(e) => set('ip', e.target.value)} placeholder="10.0.0.5, 10.0.1.5" className={`${INPUT} font-mono`} />
+ </Field>
+ <Field label="MAC">
+ <Input value={form.mac} onChange={(e) => set('mac', e.target.value)} placeholder="aa:bb:cc:dd:ee:ff" className={`${INPUT} font-mono`} />
+ </Field>
+ <Field label="OS">
+ <Input value={form.os} onChange={(e) => set('os', e.target.value)} placeholder="Debian 12" className={INPUT} />
+ </Field>
+ </div>
+ </Section>
+
+ <Section title="Make & model">
+ <div className="grid grid-cols-2 gap-3">
+ <Field label="Vendor">
+ <Input value={form.vendor} onChange={(e) => set('vendor', e.target.value)} className={INPUT} />
+ </Field>
+ <Field label="Model">
+ <Input value={form.model} onChange={(e) => set('model', e.target.value)} className={INPUT} />
+ </Field>
+ <Field label="Friendly name">
+ <Input value={form.friendly_name} onChange={(e) => set('friendly_name', e.target.value)} className={INPUT} />
+ </Field>
+ <Field label="Role">
+ <Input value={form.device_subtype} onChange={(e) => set('device_subtype', e.target.value)} placeholder="e.g. router" className={INPUT} />
+ </Field>
+ </div>
+ </Section>
</div>
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Disk (GB)</Label>
- <Input value={form.disk_gb} onChange={(e) => set('disk_gb', e.target.value.replace(/[^\d.]/g, ''))} className="bg-[#21262d] border-[#30363d] text-xs h-7 font-mono" />
+
+ <div className="flex flex-col gap-4 min-w-0">
+ <Section title="Monitoring">
+ <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) ?? '')}>
+ <SelectTrigger className={`${INPUT} w-full cursor-pointer ${modalStyles['modal-interactive']}`} aria-label="Check method selector">
+ <SelectValue placeholder="None" />
+ </SelectTrigger>
+ <SelectContent className="bg-[#21262d] border-[#30363d]">
+ {CHECK_METHODS.map((m) => (
+ <SelectItem key={m} value={m} className="text-sm">{CHECK_METHOD_LABELS[m]}</SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
+ <Field label="Check target">
+ <Input value={form.check_target} onChange={(e) => set('check_target', e.target.value)} placeholder="host:port or URL" className={`${INPUT} font-mono`} />
+ </Field>
+ </div>
+ </Section>
+
+ <Section title="Notes">
+ <Textarea
+ value={form.notes}
+ onChange={(e) => set('notes', e.target.value)}
+ rows={6}
+ placeholder="Anything worth remembering about this device."
+ className="bg-[#21262d] border-[#30363d] text-sm"
+ />
+ </Section>
</div>
- </div>
- <label className="flex items-center gap-2 cursor-pointer">
- <input
- type="checkbox"
- checked={form.show_hardware}
- onChange={(e) => set('show_hardware', e.target.checked)}
- className="accent-[#00d4ff] w-3 h-3"
- />
- <span className="text-[10px] text-muted-foreground">Show hardware specs on the node</span>
- </label>
-
- <div className="flex flex-col gap-1">
- <Label className="text-[10px] text-muted-foreground">Notes</Label>
- <Textarea value={form.notes} onChange={(e) => set('notes', e.target.value)} rows={3} className="bg-[#21262d] border-[#30363d] text-xs" />
+ <div className="flex flex-col gap-4 min-w-0">
+ {/* Same editors as the canvas — one implementation, one behaviour. */}
+ <section className="rounded-lg border border-[#30363d] bg-[#161b22] overflow-hidden">
+ <PropertyList
+ properties={properties}
+ onChange={setProperties}
+ visibleLabel="Show on node"
+ // Hardware is a property like any other; these are the keys
+ // the Proxmox import and the YAML import already mint.
+ suggestions={['CPU Model', 'CPU Cores', 'RAM', 'Disk']}
+ />
+ </section>
+
+ <Section
+ title={`Services${services.length > 0 ? ` (${services.length})` : ''}`}
+ action={
+ <button
+ onClick={() => setSvcModal({ index: null })}
+ className="flex items-center gap-1 text-[10px] text-[#00d4ff] hover:text-[#00d4ff]/80 transition-colors cursor-pointer"
+ >
+ <Plus size={10} /> Add
+ </button>
+ }
+ >
+ {services.length === 0 ? (
+ <Empty>No services — click Add to register one.</Empty>
+ ) : (
+ <div className="flex flex-col gap-1.5">
+ {services.map((svc, i) => (
+ <div key={`${svc.port ?? 'host'}-${svc.protocol}-${i}`} className="group flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-[#21262d] border border-[#30363d] text-xs">
+ <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>
+ <div className="ml-auto flex items-center gap-1.5 shrink-0">
+ <button
+ onClick={() => setSvcModal({ index: i, form: serviceToForm(svc) })}
+ title="Edit service"
+ className="text-[#8b949e] hover:text-[#00d4ff] cursor-pointer"
+ >
+ <Pencil size={11} />
+ </button>
+ <button
+ onClick={() => setServices((prev) => prev.filter((_, j) => j !== i))}
+ title="Remove service"
+ className="text-[#8b949e] hover:text-[#f85149] cursor-pointer"
+ >
+ <X size={11} />
+ </button>
+ </div>
+ </div>
+ ))}
+ </div>
+ )}
+ </Section>
+ </div>
</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">
+ <div className="flex flex-col">
+ {device.ip && <InfoRow label="IP" value={device.ip} copyable />}
+ {device.hostname && <InfoRow label="Hostname" value={device.hostname} copyable />}
+ {device.mac && <InfoRow label="MAC" value={device.mac} copyable />}
+ {device.ieee_address && <InfoRow label="IEEE" value={device.ieee_address} copyable />}
+ {device.os && <InfoRow label="OS" value={device.os} />}
+ {(device.type ?? device.suggested_type) && (
+ <InfoRow label="Type" value={(device.type ?? device.suggested_type) as string} />
+ )}
+ {device.friendly_name && device.friendly_name !== device.hostname && (
+ <InfoRow label="Name" value={device.friendly_name} />
+ )}
+ {device.vendor && <InfoRow label="Vendor" value={device.vendor} />}
+ {device.model && <InfoRow label="Model" value={device.model} />}
+ {device.device_subtype && <InfoRow label="Role" value={device.device_subtype} />}
+ {device.lqi != null && <InfoRow label="LQI" value={String(device.lqi)} />}
+ {!device.ip && !device.hostname && !device.mac && !device.ieee_address && (
+ <Empty>Nothing identifying recorded yet.</Empty>
+ )}
+ </div>
+ </Section>
- {/* Same editors as the canvas — one implementation, one behaviour. */}
- <div className="-mx-6">
- <PropertyList properties={properties} onChange={setProperties} visibleLabel="Show on node" />
- </div>
+ </div>
- <div className="border-t border-border pt-3">
- <div className="flex items-center justify-between mb-2">
- <span className="text-xs text-muted-foreground">Services{services.length > 0 ? ` (${services.length})` : ''}</span>
- <button onClick={() => setSvcModal({ index: null })} className="flex items-center gap-1 text-[10px] text-[#00d4ff] hover:text-[#00d4ff]/80 transition-colors cursor-pointer">
- <Plus size={10} /> Add
- </button>
+ <div className="flex flex-col gap-4 min-w-0">
+ <Section title="Monitoring">
+ <div className="flex flex-col">
+ {device.check_method ? (
+ <InfoRow
+ label="Check"
+ value={device.check_target ? `${device.check_method} → ${device.check_target}` : device.check_method}
+ />
+ ) : (
+ <Empty>Not monitored — pick a check method from Edit.</Empty>
+ )}
+ {device.response_time_ms != null && <InfoRow label="Response" value={`${device.response_time_ms} ms`} />}
+ {device.discovery_source && <InfoRow label="Source" value={device.discovery_source.toUpperCase()} />}
+ {device.canvas_count != null && device.canvas_count > 0 && (
+ <InfoRow label="Canvases" value={String(device.canvas_count)} />
+ )}
+ </div>
+ </Section>
+
+ <Section title="Activity">
+ <div className="flex flex-col">
+ {timestamps.length === 0 ? (
+ <Empty>No activity recorded.</Empty>
+ ) : (
+ timestamps.map((t) => <TimeRow key={t.label} label={t.label} iso={t.iso} />)
+ )}
+ </div>
+ </Section>
+
+ <Section title="Notes">
+ {device.notes ? (
+ <p className="text-xs text-foreground/80 whitespace-pre-wrap">{device.notes}</p>
+ ) : (
+ <Empty>No notes.</Empty>
+ )}
+ </Section>
</div>
- {services.length === 0 ? (
- <p className="text-[10px] text-muted-foreground/50">No services — click Add to register one.</p>
- ) : (
- <div className="flex flex-col gap-1.5">
- {services.map((svc, i) => (
- <div key={`${svc.port ?? 'host'}-${svc.protocol}-${i}`} className="group flex items-center gap-2 px-2 py-1.5 rounded bg-[#21262d] border border-[#30363d] text-xs">
- <span className="font-mono text-[#00d4ff] w-10 shrink-0">{svc.port ?? '—'}</span>
- <span className="text-muted-foreground w-7 shrink-0">{svc.protocol}</span>
- <span className="text-foreground truncate">{svc.service_name}</span>
- <div className="ml-auto flex items-center gap-1 shrink-0">
- <button
- onClick={() => setSvcModal({ index: i, form: serviceToForm(svc) })}
- title="Edit service"
- className="text-[#8b949e] hover:text-[#00d4ff]"
- >
- <Pencil size={10} />
- </button>
- <button
- onClick={() => setServices((prev) => prev.filter((_, j) => j !== i))}
- title="Remove service"
- className="text-[#8b949e] hover:text-[#f85149]"
- >
- <X size={10} />
- </button>
- </div>
+
+ <div className="flex flex-col gap-4 min-w-0">
+ <Section title={`Properties${device.properties && device.properties.length > 0 ? ` (${device.properties.length})` : ''}`}>
+ {device.properties && device.properties.length > 0 ? (
+ <div className="flex flex-col gap-1.5">
+ {device.properties.map((prop, i) => (
+ <div key={`${prop.key}-${i}`} className="flex items-baseline gap-2 px-2.5 py-1.5 rounded-md bg-[#21262d] border border-[#30363d] text-xs">
+ <span className="text-muted-foreground shrink-0">{prop.key}</span>
+ <span className="ml-auto font-mono text-foreground break-all text-right">{prop.value}</span>
+ </div>
+ ))}
</div>
- ))}
- </div>
- )}
+ ) : (
+ <Empty>No properties.</Empty>
+ )}
+ </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>
+ )}
+ </div>
- <div className="flex gap-2 pt-1">
+ {/* ── Footer: lifecycle in view, form controls in edit ── */}
+ <div className="shrink-0 flex items-center justify-between gap-3 px-5 py-3 border-t border-[#30363d] bg-[#161b22]">
+ <p className="text-[11px] text-muted-foreground/70 min-w-0 truncate">
+ {editing
+ ? 'These facts belong to the device — every canvas drawing it follows.'
+ : rackOnly
+ ? 'Rack gear — mounted from a rack canvas, never placed on a logical one.'
+ : 'One device, one row. Editing here updates every canvas drawing it.'}
+ </p>
+ {editing ? (
+ <div className="flex items-center gap-2 shrink-0">
+ <Button size="sm" variant="ghost" onClick={handleCancel} className="text-muted-foreground hover:text-foreground">
+ Cancel
+ </Button>
<Button
size="sm"
- className="flex-1 bg-[#00d4ff] text-[#0d1117] hover:bg-[#00d4ff]/90"
+ className="bg-[#00d4ff] text-[#0d1117] hover:bg-[#00d4ff]/90 min-w-20"
onClick={handleSave}
disabled={saving}
>
{saving ? 'Saving…' : 'Save'}
</Button>
- <Button size="sm" variant="ghost" className="flex-1" onClick={() => { setEditing(false); setForm(toForm(device)); setProperties(device.properties ?? []); setServices(device.services ?? []) }}>
- Cancel
- </Button>
- </div>
- </div>
- ) : (
- <div className="flex flex-col gap-4 mt-1">
- {/* Device info */}
- <div className="flex flex-col gap-1.5 p-3 rounded-md bg-[#21262d] border border-[#30363d]">
- {device.ip && <InfoRow label="IP" value={device.ip} />}
- {device.hostname && <InfoRow label="Hostname" value={device.hostname} />}
- {device.mac && <InfoRow label="MAC" value={device.mac} />}
- {device.os && <InfoRow label="OS" value={device.os} />}
- {device.ieee_address && <InfoRow label="IEEE" value={device.ieee_address} />}
- {device.friendly_name && device.friendly_name !== device.hostname && (
- <InfoRow label="Name" value={device.friendly_name} />
- )}
- {device.vendor && <InfoRow label="Vendor" value={device.vendor} />}
- {device.model && <InfoRow label="Model" value={device.model} />}
- {device.device_subtype && <InfoRow label="Role" value={device.device_subtype} />}
- {device.lqi != null && <InfoRow label="LQI" value={String(device.lqi)} />}
- {(device.type ?? device.suggested_type) && (
- <InfoRow label="Type" value={(device.type ?? device.suggested_type) as string} />
- )}
- {hardware && <InfoRow label="Hardware" value={hardware} />}
- {device.check_method && (
- <InfoRow label="Check" value={device.check_target ? `${device.check_method} → ${device.check_target}` : device.check_method} />
- )}
- {device.status_live && device.status_live !== 'unknown' && (
- <InfoRow label="Live" value={device.status_live} />
- )}
- {device.discovery_source && (
- <InfoRow label="Source" value={device.discovery_source.toUpperCase()} />
- )}
- {device.canvas_count != null && device.canvas_count > 0 && (
- <InfoRow label="Canvases" value={String(device.canvas_count)} />
- )}
- {discoveredAt && <InfoRow label="Discovered" value={discoveredAt} />}
- {formatDate(device.node_last_scan) && <InfoRow label="Last scan" value={formatDate(device.node_last_scan) as string} />}
- {formatDate(device.node_last_seen) && <InfoRow label="Last seen" value={formatDate(device.node_last_seen) as string} />}
- {formatDate(device.node_last_modified) && <InfoRow label="Modified" value={formatDate(device.node_last_modified) as string} />}
- </div>
-
- {/* Properties */}
- {device.properties && device.properties.length > 0 && (
- <div>
- <p className="text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5">
- Properties ({device.properties.length})
- </p>
- <div className="flex flex-col gap-1">
- {device.properties.map((prop, i) => (
- <div key={`${prop.key}-${i}`} className="flex items-baseline gap-2 px-2.5 py-1.5 rounded bg-[#21262d] border border-[#30363d] text-xs">
- <span className="text-muted-foreground shrink-0">{prop.key}</span>
- <span className="font-mono text-foreground break-all">{prop.value}</span>
- </div>
- ))}
- </div>
</div>
- )}
-
- {/* Notes */}
- {device.notes && (
- <div>
- <p className="text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5">Notes</p>
- <p className="text-xs text-foreground/80 whitespace-pre-wrap">{device.notes}</p>
- </div>
- )}
-
- {/* Services (skipped for Zigbee devices — they don't have IP services) */}
- {!isZigbee && <div>
- <p className="text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5">
- Services found ({device.services.length})
- </p>
- {device.services.length === 0 ? (
- <p className="text-xs text-muted-foreground italic">No services detected</p>
- ) : (
- <div className="flex flex-col gap-1 max-h-40 overflow-y-auto">
- {device.services.map((svc, i) => (
- <div
- key={i}
- className="flex items-center gap-2 px-2.5 py-1.5 rounded 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-7 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>
- )}
- </div>}
-
- {/* Actions */}
- <div className="flex gap-2 pt-1">
- {/* Rack gear is mounted from a rack canvas, never approved onto a
- logical one — so it gets no Approve button at all. */}
- {!rackOnly && (
+ ) : (
+ <div className="flex items-center gap-2 shrink-0">
<Button
size="sm"
- className="flex-1 bg-[#39d353]/15 text-[#39d353] hover:bg-[#39d353]/25 border border-[#39d353]/30"
- onClick={handleApprove}
+ variant="ghost"
+ className="text-muted-foreground hover:text-foreground hover:bg-[#30363d]"
+ onClick={handleHide}
>
- Approve
+ Hide
</Button>
- )}
- <Button
- size="sm"
- variant="ghost"
- className="flex-1 text-[#00d4ff] hover:text-[#00d4ff] hover:bg-[#00d4ff]/10"
- onClick={() => setEditing(true)}
- >
- Edit
- </Button>
- <Button
- size="sm"
- variant="ghost"
- className="flex-1 text-muted-foreground hover:text-foreground hover:bg-[#30363d]"
- onClick={handleHide}
- >
- Hide
- </Button>
- <Button
- size="sm"
- variant="ghost"
- className="flex-1 text-[#f85149] hover:text-[#f85149] hover:bg-[#f85149]/10"
- onClick={handleIgnore}
- >
- Delete
- </Button>
- </div>
+ <Button
+ size="sm"
+ variant="ghost"
+ className="text-[#f85149] hover:text-[#f85149] hover:bg-[#f85149]/10"
+ onClick={handleIgnore}
+ >
+ Delete
+ </Button>
+ {/* Rack gear is mounted from a rack canvas, never approved onto a
+ logical one — so it gets no Approve button at all. */}
+ {!rackOnly && (
+ <Button
+ size="sm"
+ className="bg-[#39d353]/15 text-[#39d353] hover:bg-[#39d353]/25 border border-[#39d353]/30"
+ onClick={handleApprove}
+ >
+ Approve
+ </Button>
+ )}
+ </div>
+ )}
</div>
- )}
{svcModal && (
<ServiceModal
diff --git a/frontend/src/components/modals/__tests__/InventoryDeviceModalEdit.test.tsx b/frontend/src/components/modals/__tests__/InventoryDeviceModalEdit.test.tsx
index 3c0e7f0..ba4a6a6 100644
--- a/frontend/src/components/modals/__tests__/InventoryDeviceModalEdit.test.tsx
+++ b/frontend/src/components/modals/__tests__/InventoryDeviceModalEdit.test.tsx
@@ -55,7 +55,6 @@ describe('InventoryDeviceModal — view mode extras', () => {
/>
)
expect(screen.getByText('garage rack')).toBeInTheDocument()
- expect(screen.getByText('4 vCPU · 16 GB RAM')).toBeInTheDocument()
expect(screen.getByText('http → http://192.168.1.100')).toBeInTheDocument()
expect(screen.getByText('Owner')).toBeInTheDocument()
expect(screen.getByText('me')).toBeInTheDocument()
@@ -120,15 +119,16 @@ describe('InventoryDeviceModal — edit mode', () => {
expect(mockUpdatePending.mock.calls[0][1].ip).toBeNull()
})
+ // Hardware moved to the properties; the columns are no longer edited here but
+ // must still be sent as numbers, not as the form's strings.
it('sends the numeric hardware fields as numbers', async () => {
render(<InventoryDeviceModal {...noop} device={makeDevice({ cpu_count: 2, ram_gb: 8 })} />)
fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
- fireEvent.change(screen.getByDisplayValue('8'), { target: { value: '32' } })
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
await waitFor(() => expect(mockUpdatePending).toHaveBeenCalled())
const body = mockUpdatePending.mock.calls[0][1]
- expect(body.ram_gb).toBe(32)
+ expect(body.ram_gb).toBe(8)
expect(body.cpu_count).toBe(2)
})
diff --git a/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx b/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx
new file mode 100644
index 0000000..02c87de
--- /dev/null
+++ b/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx
@@ -0,0 +1,193 @@
+/**
+ * The detail modal reads as a device sheet: a header that identifies the row at
+ * a glance, sections that stay put when they have nothing to show, and copyable
+ * technical values.
+ */
+import { describe, it, expect, beforeEach, vi } from 'vitest'
+import { render, screen, fireEvent, waitFor } from '@testing-library/react'
+import { InventoryDeviceModal } from '../InventoryDeviceModal'
+import type { InventoryEntry } from '@/types'
+
+const mockUpdatePending = vi.fn()
+
+vi.mock('@/api/client', () => ({
+ scanApi: { updatePending: (...a: unknown[]) => mockUpdatePending(...a) },
+}))
+
+vi.mock('sonner', async () => (await import('@/test/mocks')).mockSonner())
+
+function makeDevice(overrides: Partial<InventoryEntry> = {}): InventoryEntry {
+ return {
+ id: 'dev-1',
+ ip: '192.168.1.100',
+ mac: 'aa:bb:cc:dd:ee:ff',
+ hostname: 'pve.local',
+ os: 'Linux',
+ services: [],
+ suggested_type: 'server',
+ status: 'pending',
+ discovered_at: '2024-01-15T10:30:00Z',
+ ...overrides,
+ }
+}
+
+const noop = { onClose: vi.fn(), onApprove: vi.fn(), onHide: vi.fn(), onIgnore: vi.fn() }
+
+beforeEach(() => {
+ vi.clearAllMocks()
+ mockUpdatePending.mockResolvedValue({ data: makeDevice() })
+})
+
+describe('InventoryDeviceModal — header', () => {
+ it('badges every source that observed the device', () => {
+ render(
+ <InventoryDeviceModal
+ {...noop}
+ // No `ip`, so the only "IP" on screen is the source badge itself.
+ device={makeDevice({ ip: null, discovery_source: 'arp', discovery_sources: ['arp', 'proxmox'] })}
+ />
+ )
+ expect(screen.getByText('IP')).toBeInTheDocument()
+ expect(screen.getByText('PROXMOX')).toBeInTheDocument()
+ })
+
+ it('shows live reachability, which is not the pending/approved lifecycle', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice({ status: 'pending', status_live: 'online' })} />)
+ expect(screen.getByText('Online')).toBeInTheDocument()
+ })
+
+ it('reads unknown when the device has never been checked', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+ expect(screen.getByText('Unknown')).toBeInTheDocument()
+ })
+
+ it('counts the canvases drawing the device', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice({ canvas_count: 3 })} />)
+ expect(screen.getByTitle('Drawn on 3 canvases')).toBeInTheDocument()
+ })
+
+ it('marks a hidden row', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice({ status: 'hidden' })} />)
+ expect(screen.getByText('Hidden')).toBeInTheDocument()
+ })
+})
+
+describe('InventoryDeviceModal — view sections', () => {
+ it('keeps a section with an empty-state rather than dropping it', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+ expect(screen.getByText('No properties.')).toBeInTheDocument()
+ expect(screen.getByText('No notes.')).toBeInTheDocument()
+ expect(screen.getByText('Not monitored — pick a check method from Edit.')).toBeInTheDocument()
+ })
+
+ // Hardware is curated as properties, like every other spec — the modal has no
+ // hardware section on either side.
+ it('shows no hardware section — specs live in the properties', () => {
+ render(
+ <InventoryDeviceModal
+ {...noop}
+ device={makeDevice({ cpu_count: 4, ram_gb: 8, cpu_model: 'N5105', disk_gb: 500 })}
+ />
+ )
+ expect(screen.queryByText('Hardware')).toBeNull()
+ expect(screen.queryByText('4 vCPU · N5105 · 8 GB RAM · 500 GB disk')).toBeNull()
+ })
+
+ it('offers no hardware inputs in the form', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice({ ram_gb: 8, show_hardware: true })} />)
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ expect(screen.queryByText('Hardware')).toBeNull()
+ expect(screen.queryByText('RAM (GB)')).toBeNull()
+ expect(screen.queryByText('Show hardware specs on the node')).toBeNull()
+ })
+
+ it('suggests the spec keys so a hardware value is one click from a property', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ expect(screen.getByTitle('Add a RAM property')).toBeInTheDocument()
+ expect(screen.getByTitle('Add a CPU Model property')).toBeInTheDocument()
+ })
+
+ // Proxmox and the YAML import still write these columns; an edit here must not
+ // wipe what they recorded.
+ it('sends the stored hardware values back untouched', async () => {
+ render(
+ <InventoryDeviceModal
+ {...noop}
+ device={makeDevice({ cpu_count: 4, cpu_model: 'N5105', ram_gb: 8, disk_gb: 500, show_hardware: true })}
+ />
+ )
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+
+ await waitFor(() => expect(mockUpdatePending).toHaveBeenCalled())
+ const body = mockUpdatePending.mock.calls[0][1]
+ expect(body).toMatchObject({
+ cpu_count: 4,
+ cpu_model: 'N5105',
+ ram_gb: 8,
+ disk_gb: 500,
+ show_hardware: true,
+ })
+ })
+
+ it('shows the response time of the last check', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice({ check_method: 'ping', response_time_ms: 12 })} />)
+ expect(screen.getByText('12 ms')).toBeInTheDocument()
+ })
+
+ it('copies a technical value to the clipboard', async () => {
+ const writeText = vi.fn().mockResolvedValue(undefined)
+ Object.assign(navigator, { clipboard: { writeText } })
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+
+ fireEvent.click(screen.getByLabelText('Copy IP'))
+ await waitFor(() => expect(writeText).toHaveBeenCalledWith('192.168.1.100'))
+ })
+
+ it('offers no copy button on a value that is not an address', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+ expect(screen.queryByLabelText('Copy OS')).toBeNull()
+ })
+})
+
+describe('InventoryDeviceModal — edit sections', () => {
+ it('edits the make-and-model fields the view shows', async () => {
+ render(
+ <InventoryDeviceModal
+ {...noop}
+ device={makeDevice({ vendor: 'Dell', friendly_name: 'kitchen', device_subtype: 'router' })}
+ />
+ )
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ fireEvent.change(screen.getByDisplayValue('kitchen'), { target: { value: 'garage' } })
+ fireEvent.change(screen.getByDisplayValue('router'), { target: { value: 'switch' } })
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+
+ await waitFor(() => expect(mockUpdatePending).toHaveBeenCalled())
+ const body = mockUpdatePending.mock.calls[0][1]
+ expect(body.friendly_name).toBe('garage')
+ expect(body.device_subtype).toBe('switch')
+ expect(body.vendor).toBe('Dell')
+ })
+
+ it('drops the edits on Cancel rather than keeping them staged', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ fireEvent.change(screen.getByDisplayValue('pve.local'), { target: { value: 'renamed.local' } })
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
+
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ expect(screen.getByDisplayValue('pve.local')).toBeInTheDocument()
+ expect(screen.queryByDisplayValue('renamed.local')).toBeNull()
+ })
+
+ it('hides the lifecycle actions while editing', () => {
+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ expect(screen.queryByRole('button', { name: 'Hide' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'Delete' })).toBeNull()
+ // …and offers no second Edit while the form is open.
+ expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull()
+ })
+})