Remove one retired device pairing and its owned history from the device detail
This commit is contained in:
+55
-10
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
ApiError,
|
||||
objectId,
|
||||
page,
|
||||
pretty,
|
||||
@@ -129,7 +130,7 @@ function DeviceDetail({
|
||||
auth: Session;
|
||||
back: () => void;
|
||||
openOperation: (id: string, jobId: string) => void;
|
||||
changed: () => void;
|
||||
changed: (notice?: string) => void;
|
||||
}) {
|
||||
const path = devicePath(customer, asset);
|
||||
const detail = useResource(
|
||||
@@ -143,6 +144,8 @@ function DeviceDetail({
|
||||
);
|
||||
const [busy, setBusy] = useState(false),
|
||||
[error, setError] = useState<string | null>(null);
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const [managing, setManaging] = useState(false);
|
||||
const d = detail.data;
|
||||
const scoped = membership.data;
|
||||
const volumes = Array.isArray(d?.volumes) ? d.volumes.map((v) => record(v)) : [];
|
||||
@@ -162,7 +165,7 @@ function DeviceDetail({
|
||||
<button className="quiet" onClick={back}>
|
||||
<NavIcon name="zurueck" /> Zur Geräteliste
|
||||
</button>
|
||||
<ErrorBox error={detail.error ?? membership.error ?? error} />
|
||||
<ErrorBox error={detail.error ?? membership.error} />
|
||||
{!d && !detail.error && <p>Inventar wird geladen …</p>}
|
||||
{d && (
|
||||
<>
|
||||
@@ -238,9 +241,11 @@ function DeviceDetail({
|
||||
<CatalogCheckNotice device={d} />
|
||||
<pre aria-label="Vollständiges Geräteinventar">{pretty(d)}</pre>
|
||||
</details>
|
||||
{scoped && allowed(scoped, 'devices:revoke') && (
|
||||
<details>
|
||||
{scoped && allowed(scoped, 'devices:revoke') &&
|
||||
d.tenant_id === customer && d.asset_id === asset && d.agent_id === agent && (
|
||||
<details open={managing} onToggle={e => setManaging(e.currentTarget.open)}>
|
||||
<summary>Gerät verwalten</summary>
|
||||
<ErrorBox error={error} />
|
||||
{['archived', 'current'].includes(String(d.lifecycle)) && (
|
||||
<button
|
||||
disabled={busy}
|
||||
@@ -265,16 +270,52 @@ function DeviceDetail({
|
||||
: 'In die Historie verschieben'}
|
||||
</button>
|
||||
)}
|
||||
{d.lifecycle === 'current' && (
|
||||
{d.lifecycle !== 'revoked' && (
|
||||
<AdminControl
|
||||
auth={scoped}
|
||||
path={path + '/revocation'}
|
||||
path={path + '/revocation?agent_id=' + encodeURIComponent(agent)}
|
||||
permission="devices:revoke"
|
||||
title="Geräteidentität widerrufen"
|
||||
warning="Der Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Die Wiederaufnahme erfordert eine neue Registrierung."
|
||||
done={changed}
|
||||
warning="Der Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Danach können Sie diese Kopplung endgültig löschen. Eine Wiederaufnahme erfordert eine neue Registrierung."
|
||||
done={detail.reload}
|
||||
/>
|
||||
)}
|
||||
{d.lifecycle === 'revoked' && (confirmDelete ? (
|
||||
<div>
|
||||
<p className="warning">
|
||||
Die Kopplung von <strong>{label(d.hostname)}</strong> bei <strong>{label(d.customer_name)}</strong>
|
||||
{' '}wird mit ihrem Inventar und ihren Geräteergebnissen dauerhaft gelöscht.
|
||||
Andere Installationen bleiben erhalten.
|
||||
</p>
|
||||
<p>Kopplungs-ID <code>{agent}</code></p>
|
||||
<button className="danger" disabled={busy} onClick={async () => {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await request(path + '?agent_id=' + encodeURIComponent(agent), {
|
||||
method: 'DELETE', csrf: scoped.csrf_token, tenantId: customer
|
||||
});
|
||||
changed(`Kopplung von „${label(d.hostname)}“ bei „${label(d.customer_name)}“ gelöscht.`);
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === 'DEVICE_HAS_OPEN_WORK') {
|
||||
setError('Für diese Kopplung gibt es offene Aufträge oder Genehmigungen. Prüfen Sie diese vor dem Löschen.');
|
||||
} else if (e instanceof ApiError && e.code === 'DEVICE_REVOCATION_REQUIRED') {
|
||||
setError('Widerrufen Sie diese Geräteidentität vor dem Löschen.');
|
||||
} else {
|
||||
setError(errorText(e));
|
||||
}
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}>Endgültig löschen</button>
|
||||
<button className="quiet" disabled={busy} onClick={() => {
|
||||
setConfirmDelete(false);
|
||||
setError(null);
|
||||
}}>Abbrechen</button>
|
||||
</div>
|
||||
) : (
|
||||
<button className="danger" onClick={() => setConfirmDelete(true)}>Kopplung löschen</button>
|
||||
))}
|
||||
</details>
|
||||
)}
|
||||
</section>
|
||||
@@ -313,6 +354,7 @@ export function Devices({
|
||||
[query, setQuery] = useState(''),
|
||||
[status, setStatus] = useState(''),
|
||||
[history, setHistory] = useState(false);
|
||||
const [deletionNotice, setDeletionNotice] = useState('');
|
||||
const [trail, setTrail] = useState<{ filter: string; routes: string[] }>({ filter, routes: [] });
|
||||
const routes = trail.filter === filter ? trail.routes : [];
|
||||
function setRoutes(next: string[] | ((old: string[]) => string[])) {
|
||||
@@ -361,12 +403,13 @@ export function Devices({
|
||||
if (target)
|
||||
return (
|
||||
<DeviceDetail
|
||||
key={target.agent}
|
||||
key={detailPath}
|
||||
{...target}
|
||||
auth={auth}
|
||||
back={back}
|
||||
openOperation={(id, jobId) => onOperation(target.customer, id, jobId)}
|
||||
changed={() => {
|
||||
changed={(notice) => {
|
||||
setDeletionNotice(notice ?? '');
|
||||
back();
|
||||
setRoutes([]);
|
||||
onSelection({ customer: '', ids: [] });
|
||||
@@ -386,6 +429,7 @@ export function Devices({
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{deletionNotice && <p role="status">{deletionNotice}</p>}
|
||||
<section className="fleet" aria-label="Gerätebestand">
|
||||
<div className="fleet-tabs">
|
||||
<button
|
||||
@@ -487,6 +531,7 @@ export function Devices({
|
||||
customer = objectId(d, 'tenant'),
|
||||
model = cpu(d);
|
||||
const show = () => {
|
||||
setDeletionNotice('');
|
||||
window.location.hash = ['geraete', customer, asset, agent]
|
||||
.map(encodeURIComponent)
|
||||
.join('/');
|
||||
|
||||
Reference in New Issue
Block a user