Clarify the free and used RAM bar in device inventory
Rust development slice / linux (push) Failing after 12s

This commit is contained in:
2026-11-19 19:37:41 +01:00
parent 58236bc8f0
commit 577a6eea75
4 changed files with 92 additions and 20 deletions
+26 -15
View File
@@ -89,24 +89,35 @@ function Presence({ d }: { d: RecordValue }) {
</span>
);
}
function Capacity({ free, total }: { free: unknown; total: unknown }) {
function Capacity({ free, total, showBreakdown = false }: {
free: unknown;
total: unknown;
showBreakdown?: boolean;
}) {
const freePercent = typeof free === 'number' && typeof total === 'number' &&
Number.isFinite(total) && free >= 0 && free <= total && total > 0
? (free / total) * 100
: null;
const displayFree = freePercent === null ? null : Math.round(freePercent * 10) / 10;
const freeLabel = displayFree === null ? '' : `${number.format(displayFree)} % frei`;
const breakdown = displayFree === null ? '' : `${freeLabel}, ${number.format(100 - displayFree)} % belegt`;
return (
<>
<span>{capacity(free, total)}</span>
{typeof free === 'number' &&
typeof total === 'number' &&
Number.isFinite(total) &&
free >= 0 &&
free <= total &&
total > 0 && (
<span
className="capacity-track"
title={`${number.format((100 * free) / total)} % frei`}
aria-hidden="true"
>
<i style={{ width: `${(100 * (total - free)) / total}%` }} />
{freePercent !== null && (showBreakdown ? (
<>
<span className="capacity-track capacity-breakdown" role="img"
aria-label={breakdown} title={breakdown}>
<span className="capacity-free" style={{ width: `${freePercent}%` }} />
<span className="capacity-used" />
</span>
)}
<small className="capacity-caption" aria-hidden="true">{freeLabel}</small>
</>
) : (
<span className="capacity-track" title={freeLabel} aria-hidden="true">
<i style={{ width: `${100 - freePercent}%` }} />
</span>
))}
</>
);
}
@@ -693,7 +704,7 @@ export function Devices({
<Capacity free={d.disk_free_bytes} total={d.disk_total_bytes} />
</td>
<td data-label="RAM frei / gesamt" className="capacity-cell" title={measuredAt(d.ram_observed_at)}>
<Capacity free={d.ram_available_bytes} total={d.ram_total_bytes} />
<Capacity free={d.ram_available_bytes} total={d.ram_total_bytes} showBreakdown />
</td>
<td data-label="CPU">
{model.primary}
+5 -1
View File
@@ -107,6 +107,10 @@ section.fleet { padding:0; overflow:hidden; }
.fleet-table .capacity-cell { font-variant-numeric:tabular-nums; }
.capacity-track { display:block; width:min(90px,100%); border-radius:2px; background:#e1ebe6; height:4px; margin-top:6px; overflow:hidden; }
.capacity-track i { display:block; height:100%; background:#659d84; }
.capacity-breakdown { display:flex; height:6px; }
.capacity-free { flex:none; background:#2e7657; }
.capacity-used { flex:1; background:#b5c2be; }
.capacity-caption { display:block; color:var(--subtle); }
.presence { display:inline-flex; align-items:center; gap:5px; border-radius:20px; padding:2px 8px; background:#edf1ef; color:#4d5f59; font-size:.8rem; font-weight:650; }
.presence i { width:6px; height:6px; border-radius:50%; background:currentColor; }
.presence.online { color:#236343; background:#e6f4e9; }
@@ -161,7 +165,7 @@ section.fleet { padding:0; overflow:hidden; }
.fleet-table td[data-label]::before {content:attr(data-label);display:block;color:var(--subtle);font-size:.73rem;}
.fleet-table .hostname {grid-column:1/-1;padding-right:28px;} .host-link {font-size:1rem;}
.fleet-table .purpose-col {grid-column:1/-1;}
.fleet-table .target-col {position:absolute;right:14px;top:14px;width:auto;} .capacity-track {width:76px;}
.fleet-table .target-col {position:absolute;right:14px;top:14px;width:auto;} .capacity-track {width:min(76px,100%);}
.list-footer {border-top:1px solid var(--line);flex-wrap:wrap;} .facts {grid-template-columns:1fr 1fr;gap:12px;}
}
@media(max-width:450px) { .sidebar nav a {flex-direction:column;gap:2px;} .crumb span,.crumb i {display:none;} .login {margin:18px 12px;} .facts {grid-template-columns:1fr;} }