feat: rebuild the orbital vault as an operational map
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { motion } from "motion/react";
|
||||
import type { Snapshot } from "../../api";
|
||||
import { formatBytes, formatWhen } from "../../lib/format";
|
||||
import { Button } from "../ui/Button";
|
||||
@@ -14,6 +13,7 @@ export function ReconstituteWizard({
|
||||
onStart,
|
||||
onPoll,
|
||||
onAbort,
|
||||
onBusyChange,
|
||||
}: {
|
||||
snapshots: Snapshot[];
|
||||
selected: string | null;
|
||||
@@ -23,35 +23,55 @@ export function ReconstituteWizard({
|
||||
}>;
|
||||
onPoll: (id: string) => Promise<{ state: string; seconds_remaining: number }>;
|
||||
onAbort: (id: string) => Promise<void>;
|
||||
onBusyChange: (busy: boolean) => void;
|
||||
}) {
|
||||
const [snapId, setSnapId] = useState(selected ?? snapshots[0]?.id ?? "");
|
||||
const [target, setTarget] = useState("./restore/out");
|
||||
const [sessionId, setSessionId] = useState<string | null>(null);
|
||||
const [remaining, setRemaining] = useState(GRACE);
|
||||
const [state, setState] = useState("idle");
|
||||
const [action, setAction] = useState<"starting" | "aborting">();
|
||||
const [error, setError] = useState<string>();
|
||||
const [reconnecting, setReconnecting] = useState(false);
|
||||
|
||||
const snap = snapshots.find((s) => s.id === snapId);
|
||||
const inCountdown = state === "countdown" || state === "confirming";
|
||||
const busy = !!action || inCountdown || state === "restoring";
|
||||
|
||||
useEffect(() => { onBusyChange(busy); }, [busy, onBusyChange]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!sessionId) return;
|
||||
const t = setInterval(async () => {
|
||||
let cancelled = false;
|
||||
let timer: number;
|
||||
const poll = async () => {
|
||||
try {
|
||||
const s = await onPoll(sessionId);
|
||||
if (cancelled) return;
|
||||
setReconnecting(false);
|
||||
setState(s.state);
|
||||
setRemaining(s.seconds_remaining ?? 0);
|
||||
if (["completed", "aborted", "failed", "unavailable"].includes(s.state)) {
|
||||
setAction(undefined);
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
/* hub may clear session */
|
||||
if (cancelled) return;
|
||||
setReconnecting(true);
|
||||
}
|
||||
}, 400);
|
||||
return () => clearInterval(t);
|
||||
timer = window.setTimeout(poll, 400);
|
||||
};
|
||||
timer = window.setTimeout(poll, 400);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [sessionId, onPoll]);
|
||||
|
||||
const inCountdown = state === "countdown";
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-star-300">
|
||||
Pick a snapshot, choose where it lands, then wait through the grace window.
|
||||
Choose a snapshot and a destination on the hub.
|
||||
</p>
|
||||
|
||||
{snap && (
|
||||
@@ -67,11 +87,11 @@ export function ReconstituteWizard({
|
||||
className="mt-1 w-full rounded-xl bg-space-950 border border-space-700 px-3 py-2.5"
|
||||
value={snapId}
|
||||
onChange={(e) => setSnapId(e.target.value)}
|
||||
disabled={inCountdown || state === "restoring"}
|
||||
disabled={busy}
|
||||
>
|
||||
{snapshots.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.orbit_name} — {new Date(s.taken_at).toLocaleDateString()}
|
||||
{s.orbit_name} · {formatWhen(s.taken_at)} · {formatBytes(s.size_bytes)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -83,15 +103,13 @@ export function ReconstituteWizard({
|
||||
className="mt-1 w-full rounded-xl bg-space-950 border border-space-700 px-3 py-2.5 font-mono text-xs"
|
||||
value={target}
|
||||
onChange={(e) => setTarget(e.target.value)}
|
||||
disabled={inCountdown || state === "restoring"}
|
||||
disabled={busy}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{inCountdown && (
|
||||
<motion.div
|
||||
<div
|
||||
className="relative rounded-2xl border border-orbit-amber/40 bg-orbit-amber/10 p-6 text-center"
|
||||
animate={{ opacity: [1, 0.85, 1] }}
|
||||
transition={{ duration: 1.2, repeat: Infinity }}
|
||||
>
|
||||
<div className="relative mx-auto w-20 h-20">
|
||||
<svg viewBox="0 0 36 36" className="w-full h-full -rotate-90">
|
||||
@@ -114,33 +132,57 @@ export function ReconstituteWizard({
|
||||
<p className="mt-3 text-orbit-amber text-sm font-medium">
|
||||
Reconstituting in {remaining}s — abort restores nothing.
|
||||
</p>
|
||||
</motion.div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="danger"
|
||||
className="flex-1"
|
||||
disabled={!sessionId || state === "completed"}
|
||||
onClick={() => sessionId && onAbort(sessionId)}
|
||||
disabled={!sessionId || !inCountdown || !!action}
|
||||
onClick={async () => {
|
||||
if (!sessionId) return;
|
||||
setAction("aborting");
|
||||
setError(undefined);
|
||||
try {
|
||||
await onAbort(sessionId);
|
||||
} catch {
|
||||
setAction(undefined);
|
||||
setError("Could not cancel the restore. Check the current session status.");
|
||||
}
|
||||
}}
|
||||
>
|
||||
Abort
|
||||
</Button>
|
||||
<Button
|
||||
variant="warn"
|
||||
className="flex-1"
|
||||
disabled={!snapId || inCountdown || state === "restoring"}
|
||||
disabled={!snap || !target.trim() || busy}
|
||||
onClick={async () => {
|
||||
const res = await onStart(snapId, target);
|
||||
setSessionId(res.session_id);
|
||||
setState(res.session.state);
|
||||
setRemaining(res.session.seconds_remaining);
|
||||
setAction("starting");
|
||||
setError(undefined);
|
||||
try {
|
||||
const res = await onStart(snapId, target);
|
||||
setSessionId(res.session_id);
|
||||
setState(res.session.state);
|
||||
setRemaining(res.session.seconds_remaining);
|
||||
} catch {
|
||||
setError("Could not confirm that the hub started the restore.");
|
||||
} finally {
|
||||
setAction(undefined);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Begin reconstitute
|
||||
Begin restore
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{error && <p role="alert" className="text-orbit-red text-sm">{error}</p>}
|
||||
{reconnecting && <p role="status" className="text-orbit-amber text-sm">Reconnecting to the restore session…</p>}
|
||||
{state === "restoring" && <p role="status" className="text-orbit-amber text-sm">Restoring snapshot…</p>}
|
||||
{state === "unavailable" && (
|
||||
<p role="alert" className="text-orbit-red text-sm">The hub no longer has this restore session. Check the destination before retrying.</p>
|
||||
)}
|
||||
{state === "completed" && (
|
||||
<p className="text-orbit-green text-sm text-center">Reconstitute complete.</p>
|
||||
)}
|
||||
@@ -151,7 +193,7 @@ export function ReconstituteWizard({
|
||||
<p className="text-orbit-red text-sm text-center">Reconstitute failed — check telemetry.</p>
|
||||
)}
|
||||
|
||||
<Hint>Destructive-capable. Evidence above is what we'll write to disk after the timer.</Hint>
|
||||
<Hint>The hub writes after the countdown. An existing file at the destination may be overwritten.</Hint>
|
||||
|
||||
{sessionId && (
|
||||
<TelemetryPanel label="Session">
|
||||
|
||||
Reference in New Issue
Block a user