Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
feat(inventory): open a device's document from its detail modal
Pouzorb910b03318a0
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex db27c6d..b31f1c7 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -1474,6 +1474,14 @@ export default function App() {<DeviceInventoryModalopen={inventoryModalOpen}onClose={() => setInventoryModalOpen(false)}+ onOpenDocumentation={+ STANDALONE+ ? undefined+ : (deviceId, label) => {+ setInventoryModalOpen(false)+ void openDocumentationFor(deviceId, label)+ }+ }highlightId={inventoryHighlightId}initialStatus={inventoryModalStatus}demoDevices={tourInventoryDemo ? DEMO_INVENTORY_DEVICES : undefined}diff --git a/frontend/src/components/modals/DeviceInventoryModal.tsx b/frontend/src/components/modals/DeviceInventoryModal.tsxindex 67ec011..d7bce24 100644--- a/frontend/src/components/modals/DeviceInventoryModal.tsx+++ b/frontend/src/components/modals/DeviceInventoryModal.tsx@@ -39,6 +39,12 @@ interface DeviceInventoryModalProps {onPick?: (device: InventoryEntry) => void/** Start with the Rackable filter on (what the rack picker wants). */initialRackableOnly?: boolean+ /**+ * Opens the Documentation section on a device, from its detail modal. The+ * list closes on the way out — Documentation is a whole view behind these+ * dialogs, not something to read under them.+ */+ onOpenDocumentation?: (deviceId: string, label: string) => void}const PORT_COLORS: Record<number, string> = {@@ -151,7 +157,7 @@ function injectAutoEdges(edges: AutoEdge[] | undefined) {}))}-export function DeviceInventoryModal({ open, onClose, highlightId, initialStatus = 'pending', demoDevices, onPick, initialRackableOnly = false }: DeviceInventoryModalProps) {+export function DeviceInventoryModal({ open, onClose, highlightId, initialStatus = 'pending', demoDevices, onPick, initialRackableOnly = false, onOpenDocumentation }: DeviceInventoryModalProps) {const [devices, setDevices] = useState<InventoryEntry[]>([])const [loading, setLoading] = useState(false)const [selected, setSelected] = useState<InventoryEntry | null>(null)@@ -933,6 +939,13 @@ export function DeviceInventoryModal({ open, onClose, highlightId, initialStatus<InventoryDeviceModaldevice={selected}onClose={() => setSelected(null)}+ onOpenDocumentation={+ onOpenDocumentation &&+ ((deviceId, label) => {+ setSelected(null)+ onOpenDocumentation(deviceId, label)+ })+ }onApprove={handleApprove}onHide={handleHide}onIgnore={handleIgnore}diff --git a/frontend/src/components/modals/InventoryDeviceModal.tsx b/frontend/src/components/modals/InventoryDeviceModal.tsxindex 35b760c..608f96d 100644--- a/frontend/src/components/modals/InventoryDeviceModal.tsx+++ b/frontend/src/components/modals/InventoryDeviceModal.tsx@@ -16,6 +16,7 @@*/import { useEffect, useRef, useState } from 'react'import {+ BookOpen,Check,Copy,Factory,@@ -71,6 +72,9 @@ interface InventoryDeviceModalProps {onIgnore: (device: InventoryEntry) => void/** Called with the saved row after an edit, so the list can refresh in place. */onSaved?: (device: InventoryEntry) => void+ /** Opens the Documentation section on this device, writing the document+ * first if it has none. Absent wherever there is no backend. */+ onOpenDocumentation?: (deviceId: string, label: string) => void}const CATEGORY_COLORS: Record<string, string> = {@@ -283,7 +287,7 @@ function toRackModel(d: InventoryEntry): DeviceRackModel | null {const nullable = (v: string) => (v.trim() === '' ? null : v.trim())const numeric = (v: string) => (v.trim() === '' ? null : Number(v))-export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgnore, onSaved }: InventoryDeviceModalProps) {+export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgnore, onSaved, onOpenDocumentation }: InventoryDeviceModalProps) {const [editing, setEditing] = useState(false)const [form, setForm] = useState<EditForm>(() => (device ? toForm(device) : toForm({} as InventoryEntry)))const [properties, setProperties] = useState<NodeProperty[]>(device?.properties ?? [])@@ -555,14 +559,27 @@ export function InventoryDeviceModal({ device, onClose, onApprove, onHide, onIgn</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>+ <div className="shrink-0 flex items-center gap-1">+ {onOpenDocumentation && (+ <Button+ size="sm"+ variant="ghost"+ className={`gap-1.5 text-[#00d4ff] hover:text-[#00d4ff] hover:bg-[#00d4ff]/10 ${modalStyles['modal-interactive']}`}+ onClick={() => onOpenDocumentation(device.id, titleLabel)}+ title="Open this device's documentation page"+ >+ <BookOpen size={13} /> Documentation+ </Button>+ )}+ <Button+ size="sm"+ variant="ghost"+ className={`gap-1.5 text-[#00d4ff] hover:text-[#00d4ff] hover:bg-[#00d4ff]/10 ${modalStyles['modal-interactive']}`}+ onClick={() => setEditing(true)}+ >+ <Pencil size={13} /> Edit+ </Button>+ </div>)}</div></DialogHeader>diff --git a/frontend/src/components/modals/__tests__/DeviceInventoryModal.test.tsx b/frontend/src/components/modals/__tests__/DeviceInventoryModal.test.tsxindex 80f1a7e..98e2643 100644--- a/frontend/src/components/modals/__tests__/DeviceInventoryModal.test.tsx+++ b/frontend/src/components/modals/__tests__/DeviceInventoryModal.test.tsx@@ -40,15 +40,20 @@ vi.mock('@/components/modals/InventoryDeviceModal', () => ({device,onApprove,onClose,+ onOpenDocumentation,}: {- device: unknown+ device: { id: string } | nullonApprove: (d: unknown) => voidonClose: () => void+ onOpenDocumentation?: (deviceId: string, label: string) => void}) =>device ? (<div data-testid="approval-modal"><button data-testid="do-approve" onClick={() => onApprove(device)}>approve</button><button data-testid="close-detail" onClick={onClose}>close</button>+ {onOpenDocumentation && (+ <button data-testid="open-docs" onClick={() => onOpenDocumentation(device.id, 'label')}>docs</button>+ )}</div>) : null,}))@@ -307,6 +312,21 @@ describe('DeviceInventoryModal', () => {expect(screen.queryByTestId('approval-modal')).not.toBeInTheDocument()})+ it('closes the detail on the way to the documentation of that device', async () => {+ const onOpenDocumentation = vi.fn()+ render(<DeviceInventoryModal {...baseProps} highlightId="dev-a" onOpenDocumentation={onOpenDocumentation} />)+ await waitFor(() => expect(screen.getByTestId('approval-modal')).toBeInTheDocument())+ fireEvent.click(screen.getByTestId('open-docs'))+ expect(onOpenDocumentation).toHaveBeenCalledWith('dev-a', 'label')+ expect(screen.queryByTestId('approval-modal')).not.toBeInTheDocument()+ })++ it('offers no documentation link when the caller has nowhere to send it', async () => {+ render(<DeviceInventoryModal {...baseProps} highlightId="dev-a" />)+ await waitFor(() => expect(screen.getByTestId('approval-modal')).toBeInTheDocument())+ expect(screen.queryByTestId('open-docs')).not.toBeInTheDocument()+ })+it('hands the device back instead of stacking a dialog in picker mode', async () => {const onPick = vi.fn()render(<DeviceInventoryModal {...baseProps} highlightId="dev-a" onPick={onPick} />)diff --git a/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx b/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsxindex e3d27ce..93351b6 100644--- a/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx+++ b/frontend/src/components/modals/__tests__/InventoryDeviceModalLayout.test.tsx@@ -70,6 +70,30 @@ describe('InventoryDeviceModal — header', () => {render(<InventoryDeviceModal {...noop} device={makeDevice({ status: 'hidden' })} />)expect(screen.getByText('Hidden')).toBeInTheDocument()})++ it('opens the device documentation with the id and the title on screen', () => {+ const onOpenDocumentation = vi.fn()+ render(+ <InventoryDeviceModal+ {...noop}+ onOpenDocumentation={onOpenDocumentation}+ device={makeDevice({ label: 'Big NAS' })}+ />+ )+ fireEvent.click(screen.getByText('Documentation'))+ expect(onOpenDocumentation).toHaveBeenCalledWith('dev-1', 'Big NAS')+ })++ it('drops the documentation link where there is no backend to hold one', () => {+ render(<InventoryDeviceModal {...noop} device={makeDevice()} />)+ expect(screen.queryByText('Documentation')).not.toBeInTheDocument()+ })++ it('hides the documentation link while editing — the header belongs to the form', () => {+ render(<InventoryDeviceModal {...noop} onOpenDocumentation={vi.fn()} device={makeDevice()} />)+ fireEvent.click(screen.getByText('Edit'))+ expect(screen.queryByText('Documentation')).not.toBeInTheDocument()+ })})describe('InventoryDeviceModal — view sections', () => {