feat: rebuild the orbital vault as an operational map
This commit is contained in:
370
web/src/App.tsx
370
web/src/App.tsx
@@ -1,209 +1,215 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
abortReconstitute,
|
||||
fetchHealth,
|
||||
fetchOrbits,
|
||||
fetchSnapshots,
|
||||
pollReconstitute,
|
||||
runOrbit,
|
||||
startReconstitute,
|
||||
abortReconstitute, fetchHealth, fetchOrbits, fetchSnapshots, pollReconstitute,
|
||||
runOrbit, startReconstitute, type Orbit,
|
||||
} from "./api";
|
||||
import { vaultStatusFromOrbits } from "./lib/format";
|
||||
import { DecayView } from "./components/decay/DecayView";
|
||||
import { OrbitInspector, OrbitRegister, TelemetryStrip } from "./components/hud/DiegeticHUD";
|
||||
import { HUDPanel } from "./components/hud/HUDPanel";
|
||||
import { HUDRail, type HUDMode } from "./components/hud/HUDRail";
|
||||
import { OrbitsView } from "./components/orbits/OrbitsView";
|
||||
import { WormholeView } from "./components/outposts/WormholeView";
|
||||
import { ReconstituteWizard } from "./components/reconstitute/ReconstituteWizard";
|
||||
import { VaultScene } from "./components/scene/VaultScene";
|
||||
import { SnapshotSheet } from "./components/vault/SnapshotSheet";
|
||||
import {
|
||||
CockpitFrame,
|
||||
SnapshotsMiniList,
|
||||
TelemetryStrip,
|
||||
} from "./components/hud/DiegeticHUD";
|
||||
import { HUDPanel, SceneAction } from "./components/hud/HUDPanel";
|
||||
import { HUDRail, type HUDMode } from "./components/hud/HUDRail";
|
||||
import { EmptyState } from "./components/ui/EmptyState";
|
||||
import { QueryGate } from "./components/ui/QueryGate";
|
||||
import { SnapshotSheet } from "./components/vault/SnapshotSheet";
|
||||
import { useReducedMotion } from "./hooks/useReducedMotion";
|
||||
import { orbitStatus } from "./lib/format";
|
||||
import { groupSnapshots } from "./lib/galaxyLayout";
|
||||
|
||||
const panelTitles: Record<HUDMode, string> = {
|
||||
scene: "Vault",
|
||||
orbits: "Orbit management",
|
||||
wormhole: "Wormhole uplink",
|
||||
decay: "Snapshot retention",
|
||||
reconstitute: "Restore snapshot",
|
||||
snapshot: "Snapshot detail",
|
||||
};
|
||||
|
||||
function priority(orbit: Orbit) {
|
||||
if (orbit.last_status === "failed") return 0;
|
||||
return orbitStatus(orbit.last_status).busy ? 1 : 2;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [mode, setMode] = useState<HUDMode>("scene");
|
||||
const [selectedSnap, setSelectedSnap] = useState<string | null>(null);
|
||||
const [orbitId, setOrbitId] = useState<string>();
|
||||
const [snapshotId, setSnapshotId] = useState<string | null>(null);
|
||||
const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null);
|
||||
const [galaxyFlowing, setGalaxyFlowing] = useState(true);
|
||||
const [capturePulse, setCapturePulse] = useState(0);
|
||||
const [play, setPlay] = useState(true);
|
||||
const [restoreBusy, setRestoreBusy] = useState(false);
|
||||
const [restoreTarget, setRestoreTarget] = useState<{ id: string | null }>();
|
||||
const reducedMotion = useReducedMotion();
|
||||
const qc = useQueryClient();
|
||||
|
||||
const health = useQuery({
|
||||
queryKey: ["health"],
|
||||
queryFn: fetchHealth,
|
||||
refetchInterval: 30_000,
|
||||
retry: 1,
|
||||
});
|
||||
const snaps = useQuery({
|
||||
queryKey: ["snapshots"],
|
||||
queryFn: fetchSnapshots,
|
||||
refetchInterval: 8_000,
|
||||
});
|
||||
const orbits = useQuery({
|
||||
queryKey: ["orbits"],
|
||||
queryFn: fetchOrbits,
|
||||
refetchInterval: 8_000,
|
||||
});
|
||||
|
||||
const vaultStatus = vaultStatusFromOrbits(orbits.data ?? []);
|
||||
const hubOnline = health.isSuccess;
|
||||
const totalBytes = useMemo(
|
||||
() => (snaps.data ?? []).reduce((a, s) => a + s.size_bytes, 0),
|
||||
[snaps.data],
|
||||
);
|
||||
|
||||
const capturing =
|
||||
orbits.data?.some((o) => o.last_status === "running") ?? false;
|
||||
|
||||
const health = useQuery({ queryKey: ["health"], queryFn: fetchHealth, refetchInterval: 15_000, retry: 1 });
|
||||
const snaps = useQuery({ queryKey: ["snapshots"], queryFn: fetchSnapshots, refetchInterval: 8_000, retry: 1 });
|
||||
const orbits = useQuery({ queryKey: ["orbits"], queryFn: fetchOrbits, refetchInterval: 8_000, retry: 1 });
|
||||
const capture = useMutation({
|
||||
mutationFn: async () => {
|
||||
const target = orbits.data?.[0];
|
||||
if (!target) throw new Error("no-orbit");
|
||||
await runOrbit(target.id);
|
||||
mutationFn: (target: Orbit) => runOrbit(target.id),
|
||||
onSettled: () => {
|
||||
void qc.invalidateQueries({ queryKey: ["orbits"] });
|
||||
void qc.invalidateQueries({ queryKey: ["snapshots"] });
|
||||
},
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["snapshots", "orbits"] }),
|
||||
});
|
||||
|
||||
const selectedSnapshot = snaps.data?.find((s) => s.id === selectedSnap);
|
||||
const online = health.isSuccess;
|
||||
const activeId = capture.isPending ? capture.variables.id : undefined;
|
||||
const sceneOrbits = useMemo(() => (orbits.data ?? []).map((orbit) =>
|
||||
orbit.id === activeId ? { ...orbit, last_status: orbit.dry_run ? "rehearsing" : "running" } : orbit,
|
||||
), [orbits.data, activeId]);
|
||||
const register = useMemo(() => [...sceneOrbits].sort((a, b) => priority(a) - priority(b)), [sceneOrbits]);
|
||||
const grouped = useMemo(() => groupSnapshots(orbits.data ?? [], snaps.data ?? []), [orbits.data, snaps.data]);
|
||||
const totalBytes = useMemo(() => (snaps.data ?? []).reduce((sum, snap) => sum + snap.size_bytes, 0), [snaps.data]);
|
||||
const selected = sceneOrbits.find(({ id }) => id === orbitId);
|
||||
const history = (selected && grouped.get(selected.id)) ?? [];
|
||||
const snapshot = snaps.data?.find(({ id }) => id === snapshotId);
|
||||
const completedOrbitId = capture.isSuccess ? capture.variables.id : undefined;
|
||||
const arrival = useMemo(() => !reducedMotion && completedOrbitId && capture.data
|
||||
? { orbitId: completedOrbitId, snapshotId: capture.data }
|
||||
: undefined, [reducedMotion, completedOrbitId, capture.data]);
|
||||
const failedCount = sceneOrbits.filter(({ last_status }) => last_status === "failed").length;
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && mode !== "scene") setMode("scene");
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [mode]);
|
||||
const orbitMessage = orbits.isPending ? "Receiving orbit telemetry…" : orbits.isError
|
||||
? orbits.data ? "Live telemetry unavailable. Showing last known orbits." : "Orbit telemetry unavailable."
|
||||
: register.length ? undefined : "No backup jobs yet. Set up an orbit to begin.";
|
||||
const snapshotMessage = snaps.isPending ? "Loading snapshot history…" : snaps.isError
|
||||
? snaps.data ? "Showing last known snapshots." : "Snapshot history unavailable."
|
||||
: history.length ? undefined : "This orbit has no snapshots yet.";
|
||||
const captureLabel = capture.isPending ? capture.variables.dry_run ? "Rehearsing" : "Capturing"
|
||||
: capture.isError ? "Capture failed for"
|
||||
: capture.variables?.dry_run ? "Rehearsal complete for"
|
||||
: capture.data ? "Snapshot secured from" : "Capture finished for";
|
||||
const captureNotice = capture.variables && (
|
||||
<p className={`capture-notice${capture.isError ? " tone-red" : ""}`} role="status">
|
||||
{captureLabel} {capture.variables.name}{capture.isPending ? "…" : "."}
|
||||
</p>
|
||||
);
|
||||
const noticeInInspector = !!selected && selected.id === capture.variables?.id;
|
||||
|
||||
const snapshotPanel = selectedSnapshot && mode === "scene";
|
||||
function selectOrbit(id: string) {
|
||||
setOrbitId(id);
|
||||
setPlay(false);
|
||||
}
|
||||
|
||||
function openSnapshot(id: string) {
|
||||
document.getElementById(`snapshot-${id}`)?.focus({ preventScroll: true });
|
||||
setSnapshotId(id);
|
||||
setMode("snapshot");
|
||||
}
|
||||
|
||||
function runCapture(target: Orbit) {
|
||||
selectOrbit(target.id);
|
||||
capture.mutate(target);
|
||||
}
|
||||
|
||||
function openConsole(next: HUDMode, target: string | null = null) {
|
||||
if (next === "reconstitute" && !restoreBusy &&
|
||||
(!restoreTarget || (target !== null && target !== restoreTarget.id))) {
|
||||
setRestoreTarget({ id: target });
|
||||
}
|
||||
setMode(next);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-[100dvh] w-full overflow-hidden bg-space-950 text-star-100 relative">
|
||||
<VaultScene
|
||||
orbits={orbits.data ?? []}
|
||||
snapshots={snaps.data ?? []}
|
||||
flowing={galaxyFlowing}
|
||||
onToggleFlow={() => setGalaxyFlowing((f) => !f)}
|
||||
capturing={capturing || capture.isPending}
|
||||
capturePulse={capturePulse}
|
||||
selectedSnapshotId={selectedSnap}
|
||||
onSelect={(id) => setSelectedSnap(id)}
|
||||
onSelectOrbit={() => {
|
||||
setGalaxyFlowing(false);
|
||||
setMode("orbits");
|
||||
}}
|
||||
/>
|
||||
|
||||
<CockpitFrame>
|
||||
<TelemetryStrip
|
||||
status={vaultStatus}
|
||||
online={hubOnline}
|
||||
snapCount={snaps.data?.length ?? 0}
|
||||
totalBytes={totalBytes}
|
||||
/>
|
||||
<SnapshotsMiniList
|
||||
snapshots={snaps.data ?? []}
|
||||
selected={selectedSnap}
|
||||
onSelect={(id) => setSelectedSnap(id)}
|
||||
/>
|
||||
</CockpitFrame>
|
||||
|
||||
<div className="absolute bottom-24 left-1/2 -translate-x-1/2 z-30 flex gap-3 pointer-events-none">
|
||||
<SceneAction
|
||||
label={capture.isPending ? "ORBIT ACTIVE…" : "CAPTURE NOW"}
|
||||
disabled={capture.isPending}
|
||||
onClick={() => {
|
||||
if (!(orbits.data?.length ?? 0)) setMode("orbits");
|
||||
else {
|
||||
setCapturePulse((n) => n + 1);
|
||||
capture.mutate();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<HUDRail active={mode} onSelect={setMode} capturing={capturing} />
|
||||
|
||||
<HUDPanel
|
||||
open={!!snapshotPanel}
|
||||
title="Snapshot tile"
|
||||
subtitle="Point-in-time mass on the ring"
|
||||
side="left"
|
||||
onClose={() => setSelectedSnap(null)}
|
||||
>
|
||||
{selectedSnapshot && (
|
||||
<SnapshotSheet
|
||||
snap={selectedSnapshot}
|
||||
onReconstitute={() => setMode("reconstitute")}
|
||||
/>
|
||||
)}
|
||||
</HUDPanel>
|
||||
|
||||
<HUDPanel
|
||||
open={mode === "orbits"}
|
||||
title="Orbit console"
|
||||
subtitle="Schedule circles — not a spreadsheet"
|
||||
onClose={() => setMode("scene")}
|
||||
>
|
||||
<QueryGate query={orbits} empty={<OrbitsView orbits={[]} />}>
|
||||
{(data) => <OrbitsView orbits={data} />}
|
||||
</QueryGate>
|
||||
</HUDPanel>
|
||||
|
||||
<HUDPanel
|
||||
open={mode === "wormhole"}
|
||||
title="Wormhole uplink"
|
||||
subtitle="Pair an outpost once"
|
||||
onClose={() => setMode("scene")}
|
||||
>
|
||||
<WormholeView pairing={pairing} onPaired={setPairing} />
|
||||
</HUDPanel>
|
||||
|
||||
<HUDPanel
|
||||
open={mode === "decay"}
|
||||
title="Decay field"
|
||||
subtitle="What fades, on purpose"
|
||||
onClose={() => setMode("scene")}
|
||||
>
|
||||
<DecayView
|
||||
appliedPresets={(orbits.data ?? []).map(
|
||||
(o) => o.decay_preset ?? "week-of-dailies",
|
||||
)}
|
||||
/>
|
||||
</HUDPanel>
|
||||
|
||||
<HUDPanel
|
||||
open={mode === "reconstitute"}
|
||||
title="Reconstitute"
|
||||
subtitle="12s grace — abort restores nothing"
|
||||
side="bottom"
|
||||
onClose={() => setMode("scene")}
|
||||
>
|
||||
{(snaps.data?.length ?? 0) === 0 ? (
|
||||
<EmptyState
|
||||
title="No tiles to restore"
|
||||
body="Capture an orbit first, then return here."
|
||||
/>
|
||||
) : (
|
||||
<ReconstituteWizard
|
||||
snapshots={snaps.data ?? []}
|
||||
selected={selectedSnap}
|
||||
onStart={startReconstitute}
|
||||
onPoll={pollReconstitute}
|
||||
onAbort={abortReconstitute}
|
||||
/>
|
||||
)}
|
||||
</HUDPanel>
|
||||
|
||||
{capture.isError && (
|
||||
<p className="absolute top-24 inset-x-0 text-center text-[10px] font-mono text-orbit-amber z-30">
|
||||
NO ORBIT — OPEN ⟳ CONSOLE
|
||||
<div className="vault-app">
|
||||
<header className="vault-topbar">
|
||||
<div className="vault-brand">
|
||||
<svg viewBox="0 0 38 38" width="34" height="34" aria-hidden="true">
|
||||
<circle cx="19" cy="19" r="10.5" fill="none" stroke="currentColor" opacity=".5" />
|
||||
<ellipse cx="19" cy="19" rx="17" ry="5.8" transform="rotate(-32 19 19)" fill="none" stroke="currentColor" />
|
||||
<circle cx="19" cy="19" r="3" fill="currentColor" />
|
||||
</svg>
|
||||
<div><strong>Tessera</strong><span>Backup control</span></div>
|
||||
</div>
|
||||
<HUDRail active={mode === "snapshot" ? "scene" : mode} onSelect={openConsole} />
|
||||
<p className="hub-link" role="status">
|
||||
<span className={`register-signal signal-${online ? "green" : "grey"}`} />
|
||||
{online ? "Hub online" : health.isPending ? "Connecting" : "Hub offline"}
|
||||
</p>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<main className="vault-main">
|
||||
<div className="vault-overview">
|
||||
<div>
|
||||
<p className="instrument-label overview-label"><span aria-hidden="true">◈</span> Vault / 01</p>
|
||||
<h1>Orbital vault</h1>
|
||||
<p className="overview-copy">Backup jobs and recovery points</p>
|
||||
</div>
|
||||
<TelemetryStrip orbitCount={orbits.data?.length} failedCount={failedCount} snapCount={snaps.data?.length} totalBytes={totalBytes} />
|
||||
</div>
|
||||
|
||||
<div className="vault-workspace">
|
||||
<VaultScene
|
||||
orbits={sceneOrbits} selectedOrbitId={selected?.id} recentSnapshots={history.slice(0, 3)}
|
||||
flowing={play && !reducedMotion} reducedMotion={reducedMotion} arrival={arrival}
|
||||
onToggleFlow={() => setPlay((value) => !value)}
|
||||
onSelectOrbit={(id) => {
|
||||
selectOrbit(id);
|
||||
document.getElementById(`register-${id}`)?.focus({ preventScroll: true });
|
||||
}}
|
||||
onSelectSnapshot={openSnapshot}
|
||||
/>
|
||||
<OrbitRegister
|
||||
orbits={register} selected={selected?.id} message={orbitMessage}
|
||||
onSelect={selectOrbit} onManage={() => setMode("orbits")}
|
||||
/>
|
||||
<OrbitInspector
|
||||
orbit={selected} snapshots={history} snapshotMessage={snapshotMessage}
|
||||
onSelectSnapshot={openSnapshot}
|
||||
capture={selected && (
|
||||
<>
|
||||
<button
|
||||
type="button" className="console-control capture-button"
|
||||
onClick={() => runCapture(selected)}
|
||||
disabled={!online || capture.isPending || orbitStatus(selected.last_status).busy}
|
||||
>
|
||||
<span aria-hidden="true">↘</span>
|
||||
<span>{selected.dry_run ? "Rehearse" : "Capture"} {selected.name}</span>
|
||||
</button>
|
||||
{noticeInInspector && mode !== "orbits" && captureNotice}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<footer className="vault-footer">
|
||||
{(!noticeInInspector && mode !== "orbits" && captureNotice) || <p>Vault telemetry</p>}
|
||||
<p role="status">{restoreBusy ? "Restore active · open Restore to monitor" : "Local backup station"}</p>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
<HUDPanel
|
||||
open={mode !== "scene"}
|
||||
title={panelTitles[mode]}
|
||||
subtitle={mode === "reconstitute" ? "Review the destination before starting the restore." : undefined}
|
||||
onClose={() => setMode("scene")}
|
||||
>
|
||||
{mode === "orbits" && (
|
||||
<QueryGate query={orbits}>
|
||||
{() => <OrbitsView orbits={sceneOrbits} onRun={runCapture} captureDisabled={!online || capture.isPending} notice={captureNotice} />}
|
||||
</QueryGate>
|
||||
)}
|
||||
{mode === "wormhole" && <WormholeView pairing={pairing} onPaired={setPairing} />}
|
||||
{mode === "decay" && <DecayView appliedPresets={sceneOrbits.map((orbit) => orbit.decay_preset ?? "week-of-dailies")} />}
|
||||
{mode === "snapshot" && (snapshot ? (
|
||||
<SnapshotSheet snap={snapshot} onReconstitute={() => openConsole("reconstitute", snapshot.id)} />
|
||||
) : <EmptyState title="Snapshot unavailable" body="It may have expired under the retention policy." />)}
|
||||
<div hidden={mode !== "reconstitute"}>
|
||||
{restoreTarget && (snaps.data?.length || restoreBusy ? (
|
||||
<ReconstituteWizard
|
||||
key={restoreTarget.id ?? "manual"}
|
||||
snapshots={snaps.data ?? []} selected={restoreTarget.id}
|
||||
onStart={startReconstitute} onPoll={pollReconstitute} onAbort={abortReconstitute} onBusyChange={setRestoreBusy}
|
||||
/>
|
||||
) : (
|
||||
<QueryGate query={snaps} empty={<EmptyState title="No snapshots to restore" body="Capture an orbit to create a recovery point." />}>
|
||||
{() => null}
|
||||
</QueryGate>
|
||||
))}
|
||||
</div>
|
||||
</HUDPanel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user