import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api } from "../api/client"; import EmptyState from "../components/EmptyState"; import { ErrorNotice } from "../components/Notice"; import { BlockSkeleton } from "../components/Skeleton"; import { readableError } from "../utils/errors"; import { KIND_LABELS } from "../utils/inventory"; type Rack = Awaited>["racks"][number]; const UNIT_H = 24; const KIND_COLOR: Record = { server: "#4299e1", storage: "#38b2ac", network: "#48bb78", power: "#f59f00", client: "#a78bfa", other: "#8896ab" }; /** One rack, from the bottom (unit 1) up, as it stands: each piece where it says it sits, empty units between, a clash in red. */ function RackDrawing({ rack }: { rack: Rack }) { const height = rack.units * UNIT_H; const yOf = (unit: number) => height - unit * UNIT_H; // top edge of a unit return (
s.clash) ? ", with a clash" : ""}`} style={{ maxWidth: 300 }}> {Array.from({ length: rack.units }, (_, i) => i + 1).map((u) => ( {u} ))} {rack.slots.map((s) => { const h = (s.to - s.from + 1) * UNIT_H; const y = yOf(s.to); return ( {`${s.name}${s.model ? ` — ${s.model}` : ""} (${KIND_LABELS[s.kind as keyof typeof KIND_LABELS] ?? s.kind}, ${s.from === s.to ? `unit ${s.from}` : `units ${s.from}–${s.to}`}${s.powerWatts !== null ? `, ${s.powerWatts} W` : ""})${s.clash ? " — another piece is in the same unit" : ""}`} {s.name.length > 30 ? `${s.name.slice(0, 29)}…` : s.name} {h >= UNIT_H * 2 && s.model && ( {s.model.length > 34 ? `${s.model.slice(0, 33)}…` : s.model} )} ); })}
); } /** * The racks, drawn from the inventory: each piece of hardware that says which unit it sits in (U12, or U12-13) and where (the rack's name in its location). Edit a * piece's location and unit on the Inventory page and it moves here. Print it for the door of the cabinet. */ export default function InventoryRacks() { const [racks, setRacks] = useState(null); const [error, setError] = useState(null); useEffect(() => { api.inventory .racks() .then((res) => setRacks(res.racks)) .catch((err) => setError(readableError(err))); }, []); return ( <>

Racks

Hardware
Each piece of hardware that gives a unit (“U12”, or “U12-13” for a tall one) and the rack’s name as its location is drawn where it sits, from the bottom up. Two pieces in the same unit are shown in red.
{racks === null && !error && } {racks !== null && racks.length === 0 && (
On the Hardware page, give a piece a location (the rack’s name) and a rack unit such as U12, and it appears here.} />
)}
{racks?.map((rack) => (

{rack.name}

{rack.slots.length} {rack.slots.length === 1 ? "piece" : "pieces"} · {rack.usedUnits} of {rack.units} units{rack.watts > 0 ? ` · ${rack.watts} W` : ""}
{rack.slots.some((s) => s.clash) && (
Clash: {rack.slots.filter((s) => s.clash).map((s) => `${s.name} (${s.from === s.to ? `U${s.from}` : `U${s.from}-${s.to}`})`).join(", ")} claim the same unit. Correct one of them on the Hardware page.
)} {rack.unplaced.length > 0 && (
Named here but not in a unit: {rack.unplaced.map((u, i) => ( {i > 0 && ", "} {u.name} ))}
)}
    {[...rack.slots].reverse().map((s) => (
  • {s.from === s.to ? `U${s.from}` : `U${s.from}–${s.to}`} {s.name} {s.serverId !== null && ( <> {" "} · server )}
  • ))}
))}
); }