Group the device overview by hypervisor, Hetzner, physical and unassigned devices
Rust development slice / linux (push) Failing after 7s

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 22:57:02 +01:00
co-authored by Claude Fable 5.2
parent dbfa76184d
commit e29257b808
8 changed files with 352 additions and 104 deletions
+158 -93
View File
@@ -21,6 +21,7 @@ import { OPNsenseDetails } from './opnsense';
import { ProxmoxDetails } from './proxmox';
import { DeviceCustomerTransfer } from './device-customer-transfer';
import { HypervisorAssignment, HypervisorLabel } from './device-hypervisor';
import { groupDevices, type FleetGroup, type RowRole } from './device-groups';
import { ErrorBox, errorText, useResource } from './resource';
import { NavIcon, orderDetailRoute } from './navigation';
import { orderTitle, Status } from './order-presentation';
@@ -32,6 +33,49 @@ import { SystemNonstartReview } from './system-nonstart-review';
const unknown = 'Nicht gemeldet';
const noPurpose = 'Nicht hinterlegt';
const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
function groupName(group: FleetGroup) {
return group.kind === 'hypervisor' ? 'Hypervisor ' + (group.title || 'unbekannt')
: group.kind === 'hetzner' ? 'Hetzner Cloud'
: group.kind === 'physical' ? 'Physische Geräte' : 'Nicht zugeordnet';
}
/** How a listed virtual machine got its place under a registered hypervisor. */
function linkSource(d: RecordValue) {
if (!d.hypervisor || typeof d.hypervisor !== 'object') return '';
const info = record(d.hypervisor);
return info.kind !== 'device' ? '' : info.source === 'proxmox' ? 'automatisch erkannt' : 'manuell zugeordnet';
}
function GroupHeader({ group, showCustomer }: { group: FleetGroup; showCustomer: boolean }) {
const guests = group.rows.filter((r) => r.role !== 'host').length;
const machines = plural(guests, 'virtuelle Maschine', 'virtuelle Maschinen');
const [icon, eyebrow, title, facts] =
group.kind === 'hypervisor'
? (['server', 'Hypervisor',
group.hostPath ? <a href={'#' + group.hostPath}>{group.title || 'Unbekannter Host'}</a> : group.title || 'Unbekannter Host',
[guests ? machines : 'Keine zugeordneten virtuellen Maschinen',
!group.hostListed && 'Host in dieser Ansicht nicht enthalten',
showCustomer && group.customer]] as const)
: group.kind === 'hetzner'
? (['cloud', 'Externer Anbieter', 'Hetzner Cloud', [machines, 'Platzhalter, kein Gerät im Bestand']] as const)
: group.kind === 'physical'
? (['geraete', 'Eigene Hardware', 'Physische Geräte', [plural(guests, 'Gerät', 'Geräte')]] as const)
: (['offen', 'Ohne Zuordnung', 'Nicht zugeordnet',
[plural(guests, 'Gerät', 'Geräte'), 'kein Hypervisor oder Gerätetyp erkannt']] as const);
return (
<div className="fleet-group-head">
<span className="group-icon"><NavIcon name={icon} /></span>
<div>
<span className="group-eyebrow">{eyebrow}</span>
<strong>{title}</strong>
</div>
<p>{facts.filter(Boolean).map((fact, i) => <span key={i}>{fact}</span>)}</p>
</div>
);
}
const number = new Intl.NumberFormat('de-DE', { maximumFractionDigits: 1 });
const date = new Intl.DateTimeFormat('de-DE', { dateStyle: 'medium', timeStyle: 'short' });
function label(value: unknown) {
@@ -580,6 +624,105 @@ export function Devices({
}}
/>
);
const columns = ['Hostname', 'Type', 'Zweck', 'OS', 'Status', 'Speicher belegt / gesamt', 'RAM belegt / gesamt', 'CPU', 'Kunde'];
const row = (d: RecordValue, role: RowRole | 'flat') => {
const asset = objectId(d, 'asset'),
agent = objectId(d, 'agent'),
customer = objectId(d, 'tenant'),
model = cpu(d),
purpose = typeof d.purpose === 'string' ? d.purpose : '';
const show = () => {
setDeletionNotice('');
window.location.hash = ['geraete', customer, asset, agent]
.map(encodeURIComponent)
.join('/');
};
const another = selection.ids.length > 0 && selection.customer !== customer;
return (
<tr key={agent} onClick={show} className={role === 'flat' ? undefined : role}>
{!history && (
<td className="target-col" onClick={(e) => e.stopPropagation()}>
<input
type="checkbox"
aria-label={'Ziel ' + asset}
title={
another ? 'Aufträge werden je Kunde geplant' : 'Für Auftrag auswählen'
}
disabled={another}
checked={selection.customer === customer && selection.ids.includes(asset)}
onChange={(e) => select(d, e.target.checked)}
/>
</td>
)}
<td className="hostname">
<button
className="host-link"
onClick={(e) => {
e.stopPropagation();
show();
}}
>
{label(d.hostname)}
</button>
{role === 'flat' && <HypervisorLabel device={d} />}
{role === 'guest' && linkSource(d) && <small className="link-source">{linkSource(d)}</small>}
</td>
<td data-label="Type">{label(d.device_type)}</td>
<td data-label="Zweck" className="purpose-col">
<span className={'purpose-text' + (purpose ? '' : ' muted')} title={purpose || undefined}>
{purpose || noPurpose}
</span>
</td>
<td data-label="OS">{label(d.os)}</td>
<td data-label="Status" className="device-presence">
<Presence d={d} />
{d.status === 'offline' && d.lifecycle === 'current' && (
<small>Zuletzt {time(d.last_contact_at)}</small>
)}
</td>
<td data-label="Speicher belegt / gesamt" className="capacity-cell">
<DiskCapacity device={d} />
</td>
<td data-label="RAM belegt / gesamt" className="capacity-cell" title={measuredAt(d.ram_observed_at)}>
<Capacity free={d.ram_available_bytes} total={d.ram_total_bytes} />
</td>
<td data-label="CPU">
{model.primary}
{model.secondary && <small>{model.secondary}</small>}
<small title={measuredAt(d.cpu_usage_observed_at)}>
Auslastung {cpuUsage(d.cpu_usage_percent)}
</small>
</td>
<td data-label="Kunde">{label(d.customer_name)}</td>
</tr>
);
};
/** Every block shares these column widths, so the blocks line up under one heading. */
const table = (rows: { device: RecordValue; role: RowRole | 'flat' }[], heading: 'visible' | 'hidden' | 'only') => (
<div className={'table fleet-table' + (heading === 'only' ? ' fleet-head' : '')} aria-hidden={heading === 'only' || undefined}>
<table>
<colgroup>
{!history && <col className="target-col" />}
{columns.map((h) => <col key={h} className={h === 'Zweck' ? 'purpose-col' : h === 'Hostname' ? 'host-col' : undefined} />)}
</colgroup>
<thead className={heading === 'hidden' ? 'sr-only' : undefined}>
<tr>
{!history && (
<th className="target-col">
<span className="sr-only">Ziel auswählen</span>
</th>
)}
{columns.map((h) => (
<th scope="col" key={h} className={h === 'Zweck' ? 'purpose-col' : undefined}>
{h}
</th>
))}
</tr>
</thead>
{heading !== 'only' && <tbody>{rows.map((r) => row(r.device, r.role))}</tbody>}
</table>
</div>
);
return (
<>
<div className="page-title">
@@ -669,99 +812,21 @@ export function Devices({
{!list.data && !list.error && <p className="list-message">Geräte werden geladen …</p>}
{list.data && (
<>
<div className="table fleet-table">
<table>
<thead>
<tr>
{!history && (
<th className="target-col">
<span className="sr-only">Ziel auswählen</span>
</th>
)}
{['Hostname', 'Type', 'Zweck', 'OS', 'Status', 'Speicher belegt / gesamt', 'RAM belegt / gesamt', 'CPU', 'Kunde'].map(
(h) => (
<th scope="col" key={h} className={h === 'Zweck' ? 'purpose-col' : undefined}>
{h}
</th>
)
)}
</tr>
</thead>
<tbody>
{list.data.items.map((d) => {
const asset = objectId(d, 'asset'),
agent = objectId(d, 'agent'),
customer = objectId(d, 'tenant'),
model = cpu(d),
purpose = typeof d.purpose === 'string' ? d.purpose : '';
const show = () => {
setDeletionNotice('');
window.location.hash = ['geraete', customer, asset, agent]
.map(encodeURIComponent)
.join('/');
};
const another = selection.ids.length > 0 && selection.customer !== customer;
return (
<tr key={agent} onClick={show}>
{!history && (
<td className="target-col" onClick={(e) => e.stopPropagation()}>
<input
type="checkbox"
aria-label={'Ziel ' + asset}
title={
another ? 'Aufträge werden je Kunde geplant' : 'Für Auftrag auswählen'
}
disabled={another}
checked={selection.customer === customer && selection.ids.includes(asset)}
onChange={(e) => select(d, e.target.checked)}
/>
</td>
)}
<td className="hostname">
<button
className="host-link"
onClick={(e) => {
e.stopPropagation();
show();
}}
>
{label(d.hostname)}
</button>
<HypervisorLabel device={d} />
</td>
<td data-label="Type">{label(d.device_type)}</td>
<td data-label="Zweck" className="purpose-col">
<span className={'purpose-text' + (purpose ? '' : ' muted')} title={purpose || undefined}>
{purpose || noPurpose}
</span>
</td>
<td data-label="OS">{label(d.os)}</td>
<td data-label="Status" className="device-presence">
<Presence d={d} />
{d.status === 'offline' && d.lifecycle === 'current' && (
<small>Zuletzt {time(d.last_contact_at)}</small>
)}
</td>
<td data-label="Speicher belegt / gesamt" className="capacity-cell">
<DiskCapacity device={d} />
</td>
<td data-label="RAM belegt / gesamt" className="capacity-cell" title={measuredAt(d.ram_observed_at)}>
<Capacity free={d.ram_available_bytes} total={d.ram_total_bytes} />
</td>
<td data-label="CPU">
{model.primary}
{model.secondary && <small>{model.secondary}</small>}
<small title={measuredAt(d.cpu_usage_observed_at)}>
Auslastung {cpuUsage(d.cpu_usage_percent)}
</small>
</td>
<td data-label="Kunde">{label(d.customer_name)}</td>
</tr>
);
})}
</tbody>
</table>
</div>
{history ? (
table(list.data.items.map((device) => ({ device, role: 'flat' as const })), 'visible')
) : (
!!list.data.items.length && (
<div className="fleet-groups">
{table([], 'only')}
{groupDevices(list.data.items).map((group) => (
<div className={'fleet-group ' + group.kind} role="group" aria-label={groupName(group)} key={group.key}>
<GroupHeader group={group} showCustomer={!filter} />
{table(group.rows, 'hidden')}
</div>
))}
</div>
)
)}
{!list.data.items.length && (
<div className="empty-list">
<NavIcon name="geraete" />