Clarify the free and used RAM bar in device inventory
Rust development slice / linux (push) Failing after 12s
Rust development slice / linux (push) Failing after 12s
This commit is contained in:
+26
-15
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user