import { useState, type ReactNode } from 'react'; import type { RecordValue } from './api'; const unreported = 'Nicht gemeldet'; const pageSize = 25; function object(value: unknown): RecordValue { return value && typeof value === 'object' && !Array.isArray(value) ? value as RecordValue : {}; } function text(value: unknown): string | undefined { return typeof value === 'string' && value.trim() ? value.trim() : undefined; } function values(value: unknown) { return Array.isArray(value) ? value.flatMap(value => text(value) ?? []) : []; } function observation(device: RecordValue, name: string) { const observations = object(device.inventory).observations; return Array.isArray(observations) ? observations.map(object).find(item => item.quality === 'valid' && (item.scope === 'linux.' + name || item.scope === 'windows.' + name) ) : undefined; } export function systemDetails(device: RecordValue, formatTime: (value: unknown) => string) { const os = observation(device, 'os'); const system = object(os?.data); const hardware = object(observation(device, 'hardware')?.data); const installed = formatTime(system.installed_at); const source = system.install_date_source === 'root_filesystem' ? 'Root-Dateisystem' : system.install_date_source === 'installer_directory' ? 'Installer-Verzeichnis' : null; let booted = formatTime(system.booted_at); if (booted === unreported && os?.scope === 'linux.os' && typeof system.uptime_seconds === 'number') { const captured = Date.parse(text(os.observed_at) ?? ''); const estimated = captured - system.uptime_seconds * 1000; if (system.uptime_seconds >= 0 && Number.isFinite(estimated) && estimated >= 0) { booted = formatTime(new Date(estimated).toISOString()); } } return [ ['OS installiert am', source && installed !== unreported ? installed + ' · geschätzt (' + source + ')' : installed], ['Letzter Neustart', booted], ['Hersteller', text(hardware.manufacturer) ?? text(object(hardware.readable_dmi).sys_vendor) ?? unreported], ['BIOS-Seriennummer', text(hardware.bios_serial_number) ?? unreported], ['Garantie bis', formatTime(hardware.warranty_expires_at)] ]; } function entries(report: RecordValue | undefined): unknown[] | null { const rows = Array.isArray(report?.data) ? report.data : object(report?.data).entries; return Array.isArray(rows) ? rows : null; } function note(report: RecordValue | undefined) { const readErrors = object(report?.data).read_errors; return report?.truncated === true || (typeof readErrors === 'number' && readErrors > 0); } function InventoryTable({ headings, children }: { headings: string[]; children: ReactNode }) { return
| {label} | )}
|---|
Die Meldung enthält einen Teil der gefundenen Einträge.
} {rows === undefined ?{unreported}
: rows.length === 0 ?Keine Softwareeinträge gemeldet.
: <> {matching.length ?Keine Treffer.
} {lastPage > 0 &&Die Meldung enthält einen Teil der Netzwerkkarten oder Adressen.
} {interfaces === undefined ?{unreported}
: interfaces.length === 0 ?Keine Netzwerkkarten gemeldet.
:Die Meldung enthält einen Teil der Sitzungen.
} {users.length ?{entries(sessions) && !note(sessions) ? 'Keine Benutzer angemeldet.' : unreported}
}