Skip to content

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

fix(unifi): show auto-sync runs under their own kind in Scan History

Pouzorf76cd81b6a4a
diff --git a/frontend/src/components/modals/ScanHistoryModal.tsx b/frontend/src/components/modals/ScanHistoryModal.tsx
index 584e12a..e5f743d 100644
--- a/frontend/src/components/modals/ScanHistoryModal.tsx
+++ b/frontend/src/components/modals/ScanHistoryModal.tsx
@@ -1,5 +1,5 @@
import { useState, useEffect, useCallback, useRef } from 'react'
-import { RefreshCw, X, Loader2, StopCircle, Clock, ScanLine, Network, RadioTower, Server, Inbox } from 'lucide-react'
+import { RefreshCw, X, Loader2, StopCircle, Clock, ScanLine, Network, RadioTower, Server, Wifi, Inbox } from 'lucide-react'
import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import { scanApi } from '@/api/client'
@@ -24,13 +24,14 @@ interface ScanHistoryModalProps {
demoRuns?: ScanRun[]
}
-type KindFilter = 'all' | 'ip' | 'zigbee' | 'zwave' | 'proxmox'
+type KindFilter = 'all' | 'ip' | 'zigbee' | 'zwave' | 'proxmox' | 'unifi'
/** Normalise a ScanRun.kind into one of the known display kinds. */
-function runKind(kind: string | undefined): 'ip' | 'zigbee' | 'zwave' | 'proxmox' {
+function runKind(kind: string | undefined): 'ip' | 'zigbee' | 'zwave' | 'proxmox' | 'unifi' {
return kind === 'zigbee' ? 'zigbee'
: kind === 'zwave' ? 'zwave'
: kind === 'proxmox' ? 'proxmox'
+ : kind === 'unifi' ? 'unifi'
: 'ip'
}
@@ -39,6 +40,7 @@ const KIND_META = {
zigbee: { label: 'Zigbee', color: '#00d4ff' },
zwave: { label: 'Z-Wave', color: '#ff6e00' },
proxmox: { label: 'Proxmox', color: '#e57000' },
+ unifi: { label: 'UniFi', color: '#0559c9' },
} as const
type StatusFilter = 'all' | 'running' | 'done' | 'error' | 'cancelled'
@@ -56,6 +58,7 @@ const KIND_FILTERS: { key: KindFilter; label: string }[] = [
{ key: 'zigbee', label: 'Zigbee' },
{ key: 'zwave', label: 'Z-Wave' },
{ key: 'proxmox', label: 'Proxmox' },
+ { key: 'unifi', label: 'UniFi' },
]
function statusColor(s: string): string {
@@ -111,8 +114,8 @@ export function ScanHistoryModal({ open, onClose, demoRuns }: ScanHistoryModalPr
toast.error(`Scan failed: ${run.error ?? 'unknown error'}`)
}
if (prev?.status === 'running' && run.status === 'done') {
- if (run.kind === 'zigbee' || run.kind === 'zwave' || run.kind === 'proxmox') {
- const label = run.kind === 'zwave' ? 'Z-Wave' : run.kind === 'proxmox' ? 'Proxmox' : 'Zigbee'
+ if (run.kind === 'zigbee' || run.kind === 'zwave' || run.kind === 'proxmox' || run.kind === 'unifi') {
+ const label = KIND_META[runKind(run.kind)].label
// A done run can still carry a non-fatal advisory (e.g. Proxmox
// imported hosts but the token couldn't see any VMs/LXC).
if (run.error) {
@@ -247,7 +250,7 @@ export function ScanHistoryModal({ open, onClose, demoRuns }: ScanHistoryModalPr
{filtered.map((r) => {
const kind = runKind(r.kind)
const meta = KIND_META[kind]
- const KindIcon = kind === 'zigbee' ? Network : kind === 'zwave' ? RadioTower : kind === 'proxmox' ? Server : ScanLine
+ const KindIcon = kind === 'zigbee' ? Network : kind === 'zwave' ? RadioTower : kind === 'proxmox' ? Server : kind === 'unifi' ? Wifi : ScanLine
return (
<div key={r.id} className="rounded-lg border border-border bg-[#161b22] p-3">
<div className="flex items-center gap-2">
diff --git a/frontend/src/components/modals/__tests__/ScanHistoryModal.test.tsx b/frontend/src/components/modals/__tests__/ScanHistoryModal.test.tsx
index 03b01cf..4a6e456 100644
--- a/frontend/src/components/modals/__tests__/ScanHistoryModal.test.tsx
+++ b/frontend/src/components/modals/__tests__/ScanHistoryModal.test.tsx
@@ -83,6 +83,17 @@ const PROXMOX_RUN = {
error: null,
}
+const UNIFI_RUN = {
+ id: 'run-8',
+ status: 'done',
+ kind: 'unifi',
+ ranges: ['unifi:443'],
+ devices_found: 12,
+ started_at: new Date().toISOString(),
+ finished_at: new Date().toISOString(),
+ error: null,
+}
+
function renderModal() {
return render(
<TooltipProvider>
@@ -215,4 +226,52 @@ describe('ScanHistoryModal', () => {
expect(screen.getByText('9 found')).toBeDefined()
expect(screen.queryByText('3 found')).toBeNull()
})
+
+ it('shows a unifi auto-sync run under its own kind, not IP', async () => {
+ vi.mocked(scanApi.runs).mockResolvedValue({ data: [DONE_RUN, UNIFI_RUN] } as never)
+ renderModal()
+ await waitFor(() => expect(screen.getAllByText('done').length).toBe(2))
+ // Badge on the run plus the filter chip — before the fix runKind() fell
+ // through to 'ip' and the run wore the purple IP badge.
+ expect(screen.getAllByText('UniFi').length).toBeGreaterThanOrEqual(2)
+ fireEvent.click(screen.getByRole('button', { name: 'UniFi' }))
+ expect(screen.getByText('12 found')).toBeDefined()
+ expect(screen.queryByText('3 found')).toBeNull()
+ })
+
+ it('keeps a unifi run out of the IP filter', async () => {
+ vi.mocked(scanApi.runs).mockResolvedValue({ data: [DONE_RUN, UNIFI_RUN] } as never)
+ renderModal()
+ await waitFor(() => expect(screen.getAllByText('done').length).toBe(2))
+ fireEvent.click(screen.getByRole('button', { name: 'IP' }))
+ expect(screen.getByText('3 found')).toBeDefined()
+ expect(screen.queryByText('12 found')).toBeNull()
+ })
+
+ it('toasts when a unifi auto-sync run finishes', async () => {
+ const running = { ...UNIFI_RUN, status: 'running', finished_at: null, devices_found: 0 }
+ vi.mocked(scanApi.runs).mockResolvedValue({ data: [running] } as never)
+ renderModal()
+ await waitFor(() => expect(screen.getByText('running')).toBeDefined())
+ vi.mocked(scanApi.runs).mockResolvedValue({ data: [UNIFI_RUN] } as never)
+ fireEvent.click(screen.getByTitle('Refresh'))
+ // Auto-sync has no modal of its own, so the toast is its only surface.
+ await waitFor(() =>
+ expect(toast.success).toHaveBeenCalledWith('UniFi import done — 12 devices')
+ )
+ })
+
+ it('surfaces a done unifi run advisory as a warning', async () => {
+ const running = { ...UNIFI_RUN, status: 'running', finished_at: null, devices_found: 0 }
+ vi.mocked(scanApi.runs).mockResolvedValue({ data: [running] } as never)
+ renderModal()
+ await waitFor(() => expect(screen.getByText('running')).toBeDefined())
+ vi.mocked(scanApi.runs).mockResolvedValue({
+ data: [{ ...UNIFI_RUN, error: 'Controller returned no active clients' }],
+ } as never)
+ fireEvent.click(screen.getByTitle('Refresh'))
+ await waitFor(() =>
+ expect(toast.warning).toHaveBeenCalledWith('UniFi import: Controller returned no active clients')
+ )
+ })
})