Show disk, pool and unassigned Linux capacity in device fleet views
This commit is contained in:
+30
-1
@@ -119,12 +119,41 @@ function Capacity({ free, total }: {
|
||||
);
|
||||
}
|
||||
|
||||
function LinuxDisk({ disk, groups }: { disk: RecordValue; groups: string[] }) {
|
||||
const { used_bytes: used, available_bytes: free, total_bytes: total } = disk;
|
||||
const size = typeof total === 'number' && Number.isFinite(total) && total > 0 ? total : null;
|
||||
const valid = size !== null && typeof used === 'number' && used >= 0 && typeof free === 'number' && free >= 0 && used + free <= size;
|
||||
const usedPct = valid ? used / size * 100 : 0, freePct = valid ? free / size * 100 : 0;
|
||||
const summary = valid ? `${number.format(usedPct)} % belegt, ${number.format(freePct)} % frei, ${number.format(Math.max(0,100-usedPct-freePct))} % nicht zugeordnet` : 'Belegung nicht ermittelbar';
|
||||
const group = disk.kind === 'group';
|
||||
return <div className="drive-capacity">
|
||||
<strong>{group ? 'Verbund: ' : ''}{label(disk.name)}</strong>
|
||||
{typeof disk.model === 'string' && <small>{disk.model}</small>}
|
||||
{group && Array.isArray(disk.members) && disk.members.length > 0 && <small>{disk.members.filter(v => typeof v === 'string').join(', ')}</small>}
|
||||
{!group && groups.length > 0 && <small>Im Verbund: {groups.join(', ')}</small>}
|
||||
<div>{size === null ? 'Größe nicht gemeldet' : `${valid ? gib(used) : '–'} / ${gib(size)} GiB`}</div>
|
||||
{size !== null && <span className="capacity-track disk-track" role="img" aria-label={summary} title={summary}>
|
||||
<span className="capacity-used" style={{width:`${usedPct}%`}} />
|
||||
<span className="capacity-free" style={{width:`${freePct}%`}} />
|
||||
</span>}
|
||||
<small>{valid ? `${number.format(usedPct)} % belegt` : summary}</small>
|
||||
</div>;
|
||||
}
|
||||
|
||||
function DiskCapacity({ device }: { device: RecordValue }) {
|
||||
if ('disks' in device) {
|
||||
const disks = Array.isArray(device.disks) ? device.disks.filter(d => d && typeof d === 'object' && ['disk','group'].includes(d.kind) && typeof d.name === 'string') : [];
|
||||
return <>{disks.length ? disks.map((disk,i) => <LinuxDisk key={`${disk.kind}/${disk.name}/${i}`} disk={disk}
|
||||
groups={disk.kind === 'disk' ? disks.filter(g => g.kind === 'group' && Array.isArray(g.members) && g.members.includes(disk.name)).map(g => g.name) : []}/>) :
|
||||
<small>Keine Festplatten gemeldet</small>}
|
||||
{device.disks_truncated === true && <small>Liste gekürzt</small>}</>;
|
||||
}
|
||||
// Only Windows fleet rows use drive letters. Linux mount inventories remain
|
||||
// available in the detail view, without expanding every fleet row.
|
||||
const drives = Array.isArray(device.volumes)
|
||||
? device.volumes.map(v => record(v)).filter(v => typeof v.name === 'string' && /^[A-Z]:$/.test(v.name)) : [];
|
||||
if (!drives.length) return <Capacity free={device.disk_free_bytes} total={device.disk_total_bytes} />;
|
||||
if (!drives.length) return <>{device.source_id === 'linux.base' && <small>Root-Dateisystem /</small>}
|
||||
<Capacity free={device.disk_free_bytes} total={device.disk_total_bytes} /></>;
|
||||
return <>{drives.map(drive => (
|
||||
<div className="drive-capacity" key={String(drive.name)}>
|
||||
<strong>{String(drive.name)}</strong>{' '}<Capacity free={drive.free_bytes} total={drive.total_bytes} />
|
||||
|
||||
Reference in New Issue
Block a user