Skip to content

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

feat(canvas): print LQI on the link, toggled per edge type

Pouzor4abbf7862f9b
diff --git a/frontend/src/components/canvas/edges/__tests__/HomelableEdge.lqi.test.tsx b/frontend/src/components/canvas/edges/__tests__/HomelableEdge.lqi.test.tsx
new file mode 100644
index 0000000..abeee2d
--- /dev/null
+++ b/frontend/src/components/canvas/edges/__tests__/HomelableEdge.lqi.test.tsx
@@ -0,0 +1,92 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { render } from '@testing-library/react'
+import { ReactFlowProvider } from '@xyflow/react'
+import type { EdgeProps, Edge } from '@xyflow/react'
+import type { EdgeData, EdgeType, EdgeTypeStyle } from '@/types'
+import { useThemeStore } from '@/stores/themeStore'
+
+/**
+ * LQI on the link. The value rides on the edge (written by the Zigbee import),
+ * but whether it is printed is a per-type view preference read live from the
+ * custom style — so toggling it redraws every link of that type at once.
+ *
+ * <EdgeLabelRenderer> portals into a node that only exists inside a full
+ * <ReactFlow> host, so stub it to a passthrough like the label test does.
+ */
+vi.mock('@xyflow/react', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('@xyflow/react')>()
+ return {
+ ...actual,
+ EdgeLabelRenderer: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+ }
+})
+
+const { HomelableEdge } = await import('../index')
+
+function showLqiFor(type: EdgeType) {
+ useThemeStore.setState({
+ customStyle: { nodes: {}, edges: { [type]: { showLqi: true } as EdgeTypeStyle } },
+ })
+}
+
+function renderEdge(data: Partial<EdgeData> = {}) {
+ const props = {
+ id: 'e1',
+ source: 'a',
+ target: 'b',
+ sourceX: 0,
+ sourceY: 0,
+ targetX: 100,
+ targetY: 100,
+ sourcePosition: 'bottom',
+ targetPosition: 'top',
+ data: { type: 'iot', ...data } as EdgeData,
+ selected: false,
+ } as unknown as EdgeProps<Edge<EdgeData>>
+
+ return render(
+ <ReactFlowProvider>
+ <svg>
+ <HomelableEdge {...props} />
+ </svg>
+ </ReactFlowProvider>,
+ )
+}
+
+describe('HomelableEdge LQI', () => {
+ beforeEach(() => {
+ useThemeStore.setState({ customStyle: { nodes: {}, edges: {} } })
+ })
+
+ it('prints the LQI when the edge type has the toggle on', () => {
+ showLqiFor('iot')
+ expect(renderEdge({ lqi: 132 }).getByText('LQI 132')).toBeTruthy()
+ })
+
+ it('prints it for mesh links too', () => {
+ showLqiFor('zigbee_mesh')
+ expect(renderEdge({ type: 'zigbee_mesh', lqi: 40 }).getByText('LQI 40')).toBeTruthy()
+ })
+
+ it('prints LQI 0 — a dead link is a reading, not a missing one', () => {
+ showLqiFor('iot')
+ expect(renderEdge({ lqi: 0 }).getByText('LQI 0')).toBeTruthy()
+ })
+
+ it('prints nothing while the toggle is off', () => {
+ const { queryByText } = renderEdge({ lqi: 132 })
+ expect(queryByText('LQI 132')).toBeNull()
+ })
+
+ it('prints nothing on an edge that carries no LQI', () => {
+ showLqiFor('iot')
+ const { container } = renderEdge({ label: 'uplink' })
+ expect(container.textContent).not.toContain('LQI')
+ })
+
+ it('leaves other edge types alone when the toggle is on for one', () => {
+ showLqiFor('iot')
+ const { queryByText } = renderEdge({ type: 'ethernet', lqi: 99 })
+ expect(queryByText('LQI 99')).toBeNull()
+ })
+})
diff --git a/frontend/src/components/canvas/edges/index.tsx b/frontend/src/components/canvas/edges/index.tsx
index cdc7bfe..f1b4335 100644
--- a/frontend/src/components/canvas/edges/index.tsx
+++ b/frontend/src/components/canvas/edges/index.tsx
@@ -306,6 +306,9 @@ export function HomelableEdge({ id, source, target, sourceHandleId, targetHandle
const activeTheme = useThemeStore((s) => s.activeTheme)
const theme = THEMES[activeTheme]
+ // Read live: LQI visibility is a view preference on the edge type, not a
+ // value copied onto each edge, so toggling it redraws every link at once.
+ const customEdgeStyles = useThemeStore((s) => s.customStyle.edges)
const sourceType = useStore((s) => s.nodeLookup.get(source)?.type)
const targetType = useStore((s) => s.nodeLookup.get(target)?.type)
const isBidirectional = sourceType === 'proxmox' && targetType === 'proxmox'
@@ -332,6 +335,8 @@ export function HomelableEdge({ id, source, target, sourceHandleId, targetHandle
: { x: labelX, y: (sourceY + targetY) / 2 }
const edgeType: EdgeType = data?.type ?? 'ethernet'
+ // `!= null` on purpose: LQI 0 is a real reading (a dead link), not "absent".
+ const showLqi = (customEdgeStyles[edgeType]?.showLqi ?? false) && data?.lqi != null
const edgeColors = theme.colors.edgeColors
const BASE_STYLES: Record<EdgeType, React.CSSProperties> = {
@@ -488,6 +493,21 @@ export function HomelableEdge({ id, source, target, sourceHandleId, targetHandle
)}
<EdgeLabelRenderer>
+ {showLqi && (
+ <div
+ className="absolute pointer-events-none font-mono text-[10px] px-1.5 py-0.5 rounded"
+ style={{
+ // Sits under the label when there is one, on the line otherwise.
+ transform: `translate(-50%, -50%) translate(${labelPosition.x}px, ${labelPosition.y + (data?.label ? 16 : 0)}px)`,
+ background: theme.colors.edgeLabelBackground,
+ color: theme.colors.edgeLabelColor,
+ border: `1px solid ${theme.colors.edgeLabelBorder}`,
+ }}
+ >
+ LQI {data!.lqi}
+ </div>
+ )}
+
{data?.label && (
<div
className="absolute pointer-events-none font-mono text-[10px] px-1.5 py-0.5 rounded whitespace-pre-line text-center"
diff --git a/frontend/src/components/modals/CustomStyleModal.tsx b/frontend/src/components/modals/CustomStyleModal.tsx
index e42279f..3997173 100644
--- a/frontend/src/components/modals/CustomStyleModal.tsx
+++ b/frontend/src/components/modals/CustomStyleModal.tsx
@@ -35,7 +35,7 @@ const NODE_TYPE_GROUPS: { label: string; types: NodeType[] }[] = [
{ label: 'Generic', types: ['generic'] },
]
-const EDITABLE_EDGE_TYPES: EdgeType[] = ['ethernet', 'wifi', 'iot', 'vlan', 'virtual', 'cluster', 'fibre', 'electrical']
+const EDITABLE_EDGE_TYPES: EdgeType[] = ['ethernet', 'wifi', 'iot', 'vlan', 'virtual', 'cluster', 'fibre', 'electrical', 'zigbee_mesh']
const NODE_ICONS: Record<string, LucideIcon> = {
isp: Globe, router: Router, firewall: Flame, switch: Network, server: Server, proxmox: Layers,
@@ -73,9 +73,14 @@ function defaultEdgeStyle(edgeType: EdgeType): EdgeTypeStyle {
animated: 'none',
arrowStart: 'none',
arrowEnd: 'none',
+ showLqi: false,
}
}
+/** Edge types the Zigbee import writes an LQI onto — the only ones worth
+ * offering the "show LQI" toggle for. */
+const LQI_EDGE_TYPES: EdgeType[] = ['iot', 'zigbee_mesh']
+
// ── Edge line preview (renders the actual dash pattern + width) ────────────────
interface EdgeLineSwatchProps {
@@ -369,6 +374,21 @@ function EdgeEditor({ edgeType, style, onChange, onApplyToExisting }: EdgeEditor
<MarkerShapePicker label="End" value={style.arrowEnd} onChange={(s) => set('arrowEnd', s)} />
</div>
</div>
+
+ {/* Only the Zigbee-imported types carry an LQI; a link without one
+ prints nothing either way, so the toggle stays where it means
+ something. Applies live — no "Apply to existing" round-trip. */}
+ {LQI_EDGE_TYPES.includes(edgeType) && (
+ <label className="flex items-center gap-2 text-xs text-[#8b949e] cursor-pointer">
+ <input
+ type="checkbox"
+ checked={style.showLqi ?? false}
+ onChange={(e) => set('showLqi', e.target.checked)}
+ className="accent-[#00d4ff] cursor-pointer"
+ />
+ Show LQI on the link
+ </label>
+ )}
</div>
<Button
diff --git a/frontend/src/components/modals/__tests__/CustomStyleModal.test.tsx b/frontend/src/components/modals/__tests__/CustomStyleModal.test.tsx
index 4f7a5f3..393e597 100644
--- a/frontend/src/components/modals/__tests__/CustomStyleModal.test.tsx
+++ b/frontend/src/components/modals/__tests__/CustomStyleModal.test.tsx
@@ -61,6 +61,28 @@ describe('CustomStyleModal', () => {
expect(screen.queryByText(/Select a node type/)).toBeNull()
})
+ it('exposes the zigbee_mesh edge type for styling', () => {
+ render(<CustomStyleModal open onClose={vi.fn()} />)
+ fireEvent.click(screen.getByRole('button', { name: 'Edges' }))
+ fireEvent.click(screen.getByRole('button', { name: /Zigbee Mesh/ }))
+ expect(screen.getByText(/Apply to existing Zigbee Mesh/)).toBeDefined()
+ })
+
+ it('offers the LQI toggle on the zigbee types only', () => {
+ render(<CustomStyleModal open onClose={vi.fn()} />)
+ fireEvent.click(screen.getByRole('button', { name: 'Edges' }))
+
+ fireEvent.click(screen.getByRole('button', { name: /Zigbee Mesh/ }))
+ const box = screen.getByRole('checkbox', { name: /Show LQI/i }) as HTMLInputElement
+ expect(box.checked).toBe(false)
+ fireEvent.click(box)
+ expect((screen.getByRole('checkbox', { name: /Show LQI/i }) as HTMLInputElement).checked).toBe(true)
+
+ // Ethernet never carries an LQI, so the toggle isn't offered there.
+ fireEvent.click(screen.getByRole('button', { name: /Ethernet/ }))
+ expect(screen.queryByRole('checkbox', { name: /Show LQI/i })).toBeNull()
+ })
+
it('selecting an edge type opens the edge editor with path style buttons', () => {
render(<CustomStyleModal open onClose={vi.fn()} />)
fireEvent.click(screen.getByRole('button', { name: 'Edges' }))
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 4af2db9..8273e4f 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -402,6 +402,13 @@ export interface EdgeTypeStyle {
arrowStart: MarkerShape
/** Default marker shape at the target end for new edges of this type. */
arrowEnd: MarkerShape
+ /**
+ * Print the measured LQI on the link, like the label. A view preference, so
+ * it is read live from the custom style rather than copied onto each edge —
+ * no "Apply to existing" needed. Only edges that carry an `lqi` show it, so
+ * it is offered for the types the Zigbee import writes (`iot`, `zigbee_mesh`).
+ */
+ showLqi?: boolean
}
export interface CustomStyleDef {