Lifecycle planning, and consistent empty and loading states
- Inventory: end of support and replacement cost per asset; a Lifecycle page showing what ages out year by year and what replacing it will cost; support ending within 90 days in the weekly digest - Lists: a shared empty state saying what is missing, why, and the one thing to do; "nothing matches" with a clear button; skeleton rows instead of empty-looking lists while loading Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
92726568b7
commit
846af02851
50 files changed
+4434
-233
No files matched your search
@@ -15,6 +15,7 @@ import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { KIND_HINTS, KIND_LABELS, money, warrantyDays, warrantyState, yearlyCost, yearlyKwh } from "../utils/inventory";
|
||||
import { toast } from "../utils/toast";
|
||||
import { EmptyRow } from "../components/EmptyState";
|
||||
|
||||
const KINDS = Object.keys(KIND_LABELS) as AssetKind[];
|
||||
|
||||
@@ -28,6 +29,8 @@ interface Draft {
|
||||
purchaseDate: string;
|
||||
purchasePrice: string;
|
||||
warrantyUntil: string;
|
||||
endOfSupport: string;
|
||||
replacementCost: string;
|
||||
location: string;
|
||||
rackUnit: string;
|
||||
powerWatts: string;
|
||||
@@ -35,7 +38,7 @@ interface Draft {
|
||||
notes: string;
|
||||
}
|
||||
|
||||
const EMPTY: Draft = { id: null, name: "", kind: "server", manufacturer: "", model: "", serial: "", purchaseDate: "", purchasePrice: "", warrantyUntil: "", location: "", rackUnit: "", powerWatts: "", serverId: "", notes: "" };
|
||||
const EMPTY: Draft = { id: null, name: "", kind: "server", manufacturer: "", model: "", serial: "", purchaseDate: "", purchasePrice: "", warrantyUntil: "", endOfSupport: "", replacementCost: "", location: "", rackUnit: "", powerWatts: "", serverId: "", notes: "" };
|
||||
|
||||
function toDraft(a: Asset): Draft {
|
||||
return {
|
||||
@@ -48,6 +51,8 @@ function toDraft(a: Asset): Draft {
|
||||
purchaseDate: a.purchaseDate ?? "",
|
||||
purchasePrice: a.purchasePrice === null ? "" : String(a.purchasePrice),
|
||||
warrantyUntil: a.warrantyUntil ?? "",
|
||||
endOfSupport: a.endOfSupport ?? "",
|
||||
replacementCost: a.replacementCost === null ? "" : String(a.replacementCost),
|
||||
location: a.location ?? "",
|
||||
rackUnit: a.rackUnit ?? "",
|
||||
powerWatts: a.powerWatts === null ? "" : String(a.powerWatts),
|
||||
@@ -67,6 +72,8 @@ function toInput(d: Draft): AssetInput {
|
||||
purchaseDate: d.purchaseDate || null,
|
||||
purchasePrice: num(d.purchasePrice),
|
||||
warrantyUntil: d.warrantyUntil || null,
|
||||
endOfSupport: d.endOfSupport || null,
|
||||
replacementCost: num(d.replacementCost),
|
||||
location: d.location,
|
||||
rackUnit: d.rackUnit,
|
||||
powerWatts: num(d.powerWatts),
|
||||
@@ -75,6 +82,14 @@ function toInput(d: Draft): AssetInput {
|
||||
};
|
||||
}
|
||||
|
||||
/** Under the warranty: when support ends, in words that say how soon. */
|
||||
function SupportLine({ until }: { until: string }) {
|
||||
const days = warrantyDays(until);
|
||||
if (days === null) return null;
|
||||
const cls = days < 0 ? "text-red" : days <= 180 ? "text-yellow" : "text-secondary";
|
||||
return <div className={`small ${cls}`}>{days < 0 ? `support ended ${until}` : days === 0 ? "support ends today" : `support ends ${until}`}</div>;
|
||||
}
|
||||
|
||||
function WarrantyBadge({ until }: { until: string | null }) {
|
||||
const state = warrantyState(until);
|
||||
const days = warrantyDays(until);
|
||||
@@ -191,8 +206,8 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
if (!sorted) return;
|
||||
downloadCsv(
|
||||
"inventory.csv",
|
||||
["Name", "Kind", "Manufacturer", "Model", "Serial", "Location", "Rack unit", "Purchased", "Price", "Warranty until", "Power (W)", "Server", "Notes"],
|
||||
sorted.map((a) => [a.name, KIND_LABELS[a.kind], a.manufacturer ?? "", a.model ?? "", a.serial ?? "", a.location ?? "", a.rackUnit ?? "", a.purchaseDate ?? "", a.purchasePrice ?? "", a.warrantyUntil ?? "", a.powerWatts ?? "", a.server?.name ?? "", a.notes ?? ""]),
|
||||
["Name", "Kind", "Manufacturer", "Model", "Serial", "Location", "Rack unit", "Purchased", "Price", "Warranty until", "End of support", "Replacement cost", "Power (W)", "Server", "Notes"],
|
||||
sorted.map((a) => [a.name, KIND_LABELS[a.kind], a.manufacturer ?? "", a.model ?? "", a.serial ?? "", a.location ?? "", a.rackUnit ?? "", a.purchaseDate ?? "", a.purchasePrice ?? "", a.warrantyUntil ?? "", a.endOfSupport ?? "", a.replacementCost ?? "", a.powerWatts ?? "", a.server?.name ?? "", a.notes ?? ""]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -228,6 +243,9 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h2 className="page-title mb-0">Inventory</h2>
|
||||
<div className="ms-auto d-flex gap-2">
|
||||
<Link to="/inventory/lifecycle" className="btn">
|
||||
Lifecycle
|
||||
</Link>
|
||||
<Link to="/inventory/labels" className="btn">
|
||||
Print labels
|
||||
</Link>
|
||||
@@ -382,6 +400,20 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
</label>
|
||||
<input id="inv-warranty" type="date" className="form-control" value={draft.warrantyUntil} onChange={(e) => set("warrantyUntil", e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label" htmlFor="inv-eos">
|
||||
End of support
|
||||
</label>
|
||||
<input id="inv-eos" type="date" className="form-control" value={draft.endOfSupport} onChange={(e) => set("endOfSupport", e.target.value)} />
|
||||
<div className="form-hint text-secondary small mt-1">When the maker stops patching it, or you plan to retire it.</div>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label" htmlFor="inv-repl">
|
||||
Replacement cost {config.currency && <span className="text-secondary">({config.currency})</span>}
|
||||
</label>
|
||||
<input id="inv-repl" type="number" min={0} step="any" className="form-control" value={draft.replacementCost} onChange={(e) => set("replacementCost", e.target.value)} />
|
||||
<div className="form-hint text-secondary small mt-1">What replacing it should cost. Left empty, the purchase price stands in.</div>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label" htmlFor="inv-power">
|
||||
Typical power draw
|
||||
@@ -507,6 +539,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
</td>
|
||||
<td className="stack-label" data-label="Warranty">
|
||||
<WarrantyBadge until={a.warrantyUntil} />
|
||||
{a.endOfSupport && <SupportLine until={a.endOfSupport} />}
|
||||
</td>
|
||||
<td className="stack-label" data-label="Power">{a.powerWatts === null ? <span className="text-secondary">—</span> : `${a.powerWatts} W`}</td>
|
||||
{canEdit && (
|
||||
@@ -524,11 +557,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
</tr>
|
||||
))}
|
||||
{assets !== null && sorted?.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={canEdit ? 7 : 6} className="text-secondary text-center">
|
||||
{tableSearch.active || kind ? "Nothing matches that." : `Nothing in the inventory yet.${canEdit ? " Add the first piece of hardware." : ""}`}
|
||||
</td>
|
||||
</tr>
|
||||
<EmptyRow colSpan={canEdit ? 7 : 6} {...(tableSearch.active || kind ? { filtered: () => { tableSearch.setQuery(""); setParams((p) => { const n = new URLSearchParams(p); n.delete("kind"); return n; }, { replace: true }); } } : { title: "Nothing in the inventory yet", hint: "Keep track of the hardware behind it all: what it is, when it was bought, how long it is covered, where it sits and what it draws.", action: canEdit ? { label: "Add the first piece of hardware", onClick: () => setDraft({ ...EMPTY }) } : undefined })} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in new issue
Block a user