Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
fix(rack): draw desktop NAS towers at a size a disk actually is
Pouzor06407046784f
diff --git a/frontend/src/rack/__tests__/RackDeviceModal.test.tsx b/frontend/src/rack/__tests__/RackDeviceModal.test.tsxindex f4f5aad..c776513 100644--- a/frontend/src/rack/__tests__/RackDeviceModal.test.tsx+++ b/frontend/src/rack/__tests__/RackDeviceModal.test.tsx@@ -263,6 +263,21 @@ describe('RackDeviceModal — adding', () => {expect(columns).toContainElement(screen.getByRole('button', { name: 'Add port' }))})+ it('offers a Width option for every plate width in the catalog', async () => {+ const { FACEPLATES } = await import('../faceplates')+ store().openDeviceEditor()+ render(<RackDeviceModal />)++ // A plate whose colSpan has no option (the sixth-width NAS did) leaves the+ // select blank and the field looks broken.+ const offered = [...screen.getByLabelText('Width').querySelectorAll('option')].map((o) =>+ Number(o.getAttribute('value')),+ )+ for (const span of new Set(FACEPLATES.map((f) => f.colSpan))) {+ expect(offered).toContain(span)+ }+ })+it('creates a brand new inventory entry from the canvas and mounts it', async () => {createPending.mockResolvedValue({ data: { id: 'pending-1' } })store().openDeviceEditor()diff --git a/frontend/src/rack/__tests__/faceplates.test.ts b/frontend/src/rack/__tests__/faceplates.test.tsindex 9f19372..951434e 100644--- a/frontend/src/rack/__tests__/faceplates.test.ts+++ b/frontend/src/rack/__tests__/faceplates.test.ts@@ -81,17 +81,21 @@ describe('faceplate catalog', () => {}})- it('keeps the desktop NAS boxes third-width and 3U, one bay column each', () => {- const expected: Record<string, number> = {- 'nas-desktop-2': 2,- 'nas-desktop-4': 4,- 'nas-desktop-5': 5,+ it('keeps the desktop NAS boxes narrow and tall, one bay column each', () => {+ // Bay count → { bays, colSpan }: two doors is a sixth-width tower, four and+ // five a third. All the same height — more disks makes a box wider, not+ // taller — and tall enough that the doors stand up (a U is 24px against a+ // 456px inner width, so the canvas squashes the vertical axis).+ const expected: Record<string, { bays: number; colSpan: number }> = {+ 'nas-desktop-2': { bays: 2, colSpan: RACK_COLUMNS / 6 },+ 'nas-desktop-4': { bays: 4, colSpan: RACK_COLUMNS / 3 },+ 'nas-desktop-5': { bays: 5, colSpan: RACK_COLUMNS / 3 },}- for (const [id, bays] of Object.entries(expected)) {+ for (const [id, { bays, colSpan }] of Object.entries(expected)) {const plate = getFaceplate(id)- // Shelf-mounted desktop gear, not rack gear: a third of the width, 3U tall.- expect(plate.colSpan).toBe(RACK_COLUMNS / 3)- expect(plate.uHeight).toBe(3)+ // Shelf-mounted desktop gear, not rack gear: a slice of the width, 5U tall.+ expect(plate.colSpan).toBe(colSpan)+ expect(plate.uHeight).toBe(5)const tray = plate.elements.find((e) => e.kind === 'bays')expect(tray).toMatchObject({ cols: bays, rows: 1 })expect(plate.ports.length).toBeGreaterThan(0)@@ -110,6 +114,28 @@ describe('faceplate catalog', () => {}})+ it('draws every desktop NAS door the same size — a disk is a disk', () => {+ // Regression: the stack stretched to fill the plate, so the 2-bay box wore+ // two doors twice as wide as the 5-bay one's. Unit coordinates are+ // fractions of the plate, so compare them scaled by the plate's own width —+ // the 2-bay box is a quarter of the rack, the others a third.+ const doors = ['nas-desktop-2', 'nas-desktop-4', 'nas-desktop-5'].map((id) => {+ const plate = getFaceplate(id)+ const tray = plate.elements.find((e) => e.kind === 'bays')!+ if (tray.kind !== 'bays') throw new Error('no bays')+ return { x: tray.x * plate.colSpan, doorW: (tray.w / tray.cols) * plate.colSpan }+ })+ for (const door of doors) {+ expect(door.doorW).toBeCloseTo(doors[0].doorW, 5)+ // …and the stack starts at the same inset, so the boxes line up on a shelf.+ expect(door.x).toBeCloseTo(doors[0].x, 5)+ }+ // The widest stack still fits the plate.+ const plate5 = getFaceplate('nas-desktop-5').elements.find((e) => e.kind === 'bays')!+ if (plate5.kind !== 'bays') throw new Error('no bays')+ expect(plate5.x + plate5.w).toBeLessThanOrEqual(1)+ })+it('falls back to the first plate on an unknown id', () => {expect(getFaceplate('does-not-exist')).toBe(FACEPLATES[0])})diff --git a/frontend/src/rack/components/FaceplatePicker.tsx b/frontend/src/rack/components/FaceplatePicker.tsxindex a038f1a..781cd79 100644--- a/frontend/src/rack/components/FaceplatePicker.tsx+++ b/frontend/src/rack/components/FaceplatePicker.tsx@@ -30,6 +30,7 @@ const WIDTH_LABEL: Record<number, string> = {[RACK_COLUMNS / 2]: 'Half width',[RACK_COLUMNS / 3]: 'Third width',[RACK_COLUMNS / 4]: 'Quarter width',+ [RACK_COLUMNS / 6]: 'Sixth width',}/** Ports carry no id in a template — seed stable ones for the preview only. */diff --git a/frontend/src/rack/components/RackDeviceModal.tsx b/frontend/src/rack/components/RackDeviceModal.tsxindex c4cb768..7ff2833 100644--- a/frontend/src/rack/components/RackDeviceModal.tsx+++ b/frontend/src/rack/components/RackDeviceModal.tsx@@ -505,6 +505,7 @@ function DeviceForm({ deviceId, onClose }: { deviceId: string | null; onClose: (<option value={RACK_COLUMNS / 2}>Half width</option><option value={RACK_COLUMNS / 3}>Third width</option><option value={RACK_COLUMNS / 4}>Quarter width</option>+ <option value={RACK_COLUMNS / 6}>Sixth width</option></select></Field></div>diff --git a/frontend/src/rack/faceplates.ts b/frontend/src/rack/faceplates.tsindex 4f1010f..44e7536 100644--- a/frontend/src/rack/faceplates.ts+++ b/frontend/src/rack/faceplates.ts@@ -72,6 +72,44 @@ function nasPorts(ports: Omit<Port, 'id'>[]): Omit<Port, 'id'>[] {return ports.map((p) => ({ ...p, y: NAS_BAND }))}+/**+ * Desktop NAS height, in U.+ *+ * A U is drawn at 24px while the rack's inner width is 456px, so the canvas+ * compresses the vertical axis about 1.8x against the real thing. A tower that+ * measures 3U tall in metal reads as a squat box here — 5U is what makes the+ * drive doors stand up the way they do on the desk.+ */+const NAS_U = 5++/** Plate width the NAS bay figures below are expressed against. */+const NAS_REF_SPAN = RACK_COLUMNS / 3+/** Left inset and per-bay width of a desktop NAS drive stack, on a NAS_REF_SPAN plate. */+const NAS_BAY_X = 0.05+const NAS_BAY_W = 0.18++/**+ * A drive door is a 3.5" disk whatever the chassis holds, so the bay stack+ * grows with the bay count instead of stretching to fill the plate — the 2-bay+ * box wears two doors the same size as the 5-bay one's, not two fat ones.+ *+ * Unit coordinates are fractions of the plate, so a narrower plate needs larger+ * fractions to draw the same door: `colSpan` scales them back to the reference.+ */+function nasBays(cols: number, colSpan: number = NAS_REF_SPAN) {+ const scale = NAS_REF_SPAN / colSpan+ return {+ kind: 'bays' as const,+ x: NAS_BAY_X * scale,+ y: 0.07,+ w: cols * NAS_BAY_W * scale,+ h: 0.68,+ cols,+ rows: 1,+ fill: BLACK_BOX,+ }+}+export const FACEPLATES: FaceplateTemplate[] = [// --- Servers ------------------------------------------------------------{@@ -316,30 +354,31 @@ export const FACEPLATES: FaceplateTemplate[] = [label: 'Desktop NAS — 2 bays',kind: 'device',group: 'Storage',- uHeight: 3,- colSpan: RACK_COLUMNS / 3,+ uHeight: NAS_U,+ // Two doors side by side is a slim tower — a sixth of the rack.+ colSpan: RACK_COLUMNS / 6,statusLed: true,- labelBox: { x: 0.13, w: 0.42, y: NAS_BAND },+ labelBox: { x: 0.26, w: 0.4, y: NAS_BAND },portSize: 'md',elements: [{ kind: 'panel', fill: '#262c35', stroke: '#0d1117' },- { kind: 'bays', x: 0.09, y: 0.07, w: 0.82, h: 0.68, cols: 2, rows: 1, fill: BLACK_BOX },+ nasBays(2, RACK_COLUMNS / 6),],- ports: nasPorts(bank({ type: 'rj45', count: 1, x: 0.62, w: 0.3, prefix: 'eth' })),+ ports: nasPorts(bank({ type: 'rj45', count: 1, x: 0.7, w: 0.26, prefix: 'eth' })),},{id: 'nas-desktop-4',label: 'Desktop NAS — 4 bays',kind: 'device',group: 'Storage',- uHeight: 3,+ uHeight: NAS_U,colSpan: RACK_COLUMNS / 3,statusLed: true,labelBox: { x: 0.13, w: 0.42, y: NAS_BAND },portSize: 'md',elements: [{ kind: 'panel', fill: '#262c35', stroke: '#0d1117' },- { kind: 'bays', x: 0.06, y: 0.07, w: 0.88, h: 0.68, cols: 4, rows: 1, fill: BLACK_BOX },+ nasBays(4),],ports: nasPorts(bank({ type: 'rj45', count: 2, x: 0.6, w: 0.34, prefix: 'eth' })),},@@ -348,14 +387,14 @@ export const FACEPLATES: FaceplateTemplate[] = [label: 'Desktop NAS — 5 bays',kind: 'device',group: 'Storage',- uHeight: 3,+ uHeight: NAS_U,colSpan: RACK_COLUMNS / 3,statusLed: true,labelBox: { x: 0.13, w: 0.42, y: NAS_BAND },portSize: 'md',elements: [{ kind: 'panel', fill: '#262c35', stroke: '#0d1117' },- { kind: 'bays', x: 0.05, y: 0.07, w: 0.9, h: 0.68, cols: 5, rows: 1, fill: BLACK_BOX },+ nasBays(5),],ports: nasPorts([...bank({ type: 'rj45', count: 2, x: 0.58, w: 0.24, prefix: 'eth' }),