feat: rename restore targets and show the application next to them

- PUT /api/v1/restore-targets/:id changes only the display name (admin, validated, audited); ids,
  identity, relations and jobs are untouched
- Relations console: Application column, inline rename, application in the target pickers
- Refresh screen: the application on each card
- registering a target suggests '<application> · <database>'

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 14:57:46 +07:00
parent 76999f06b8
commit c6dd52c700
12 changed files with 225 additions and 18 deletions

View File

@@ -119,6 +119,7 @@ export const fetchRelations = () => api<RelationOverview>("/api/v1/relations");
export const setOrbitEnvironment = (id: string, environment: Environment) => api<void>(`/api/v1/orbits/${id}/environment`, json("PUT", { environment }));
export const setTargetEnvironment = (id: string, environment: Environment) =>
api<{ ended_relations: string[] }>(`/api/v1/restore-targets/${id}/environment`, json("PUT", { environment }));
export const renameTarget = (id: string, name: string) => api<void>(`/api/v1/restore-targets/${id}`, json("PUT", { name }));
export const createRelation = (source_orbit_id: string, target_id: string) => api<RelationView>("/api/v1/relations", json("POST", { source_orbit_id, target_id }));
export const retargetRelation = (id: string, target_id: string) => api<RelationView>(`/api/v1/relations/${id}`, json("PUT", { target_id }));
export const endRelation = (id: string) => api<void>(`/api/v1/relations/${id}`, { method: "DELETE" });

View File

@@ -22,8 +22,8 @@ const phases: Record<string, string> = {
cancelled: "Cancelled",
};
export function DatabaseRestore({ snapshot, application, engine }: {
snapshot: string; application: string; engine: RestoreTarget["engine"];
export function DatabaseRestore({ snapshot, application, applicationName, engine }: {
snapshot: string; application: string; applicationName?: string; engine: RestoreTarget["engine"];
}) {
const fieldId = useId();
const query = useQueryClient();
@@ -112,7 +112,7 @@ export function DatabaseRestore({ snapshot, application, engine }: {
</form>
)}
{registering
? <RestoreTargetForm application={application} engine={engine} onClose={() => setRegistering(false)} />
? <RestoreTargetForm application={application} applicationName={applicationName} engine={engine} onClose={() => setRegistering(false)} />
: !targets.data?.length && <Button type="button" onClick={() => setRegistering(true)}>Register restore target</Button>}
</div>

View File

@@ -117,7 +117,7 @@ export function ReconstituteWizard({
</div>
{managed && databaseMode ? (
<DatabaseRestore key={snapId} snapshot={snapId} application={managed.application_id} engine={managed.engine} />
<DatabaseRestore key={snapId} snapshot={snapId} application={managed.application_id} applicationName={snap?.orbit_name} engine={managed.engine} />
) : <>
<div className="restore-fields">
<label className="block text-sm">

View File

@@ -8,12 +8,16 @@ import { Hint } from "../ui/EmptyState";
const field = "field";
const uuidPattern = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
export function RestoreTargetForm({ application, engine, onClose }: {
export function RestoreTargetForm({ application, applicationName, engine, onClose }: {
application: string;
/** Used to suggest a name that tells this target apart from the same environment of other applications. */
applicationName?: string;
engine: RestoreTarget["engine"];
onClose: () => void;
}) {
const [initialId] = useState(() => globalThis.crypto?.randomUUID?.() ?? "");
const [name, setName] = useState("");
const [named, setNamed] = useState(false);
const qc = useQueryClient();
const register = useMutation({
mutationFn: registerRestoreTarget,
@@ -42,7 +46,8 @@ export function RestoreTargetForm({ application, engine, onClose }: {
<h4 className="font-medium text-star-100">Register a {engine === "postgres" ? "PostgreSQL" : "MySQL"} restore target</h4>
<label className="block text-sm text-star-300">
Target name
<input name="name" required maxLength={128} className={field} />
<input name="name" required maxLength={128} className={field} value={name}
onChange={(event) => { setName(event.target.value); setNamed(true); }} />
</label>
<label className="block text-sm text-star-300">
Target UUID
@@ -55,7 +60,13 @@ export function RestoreTargetForm({ application, engine, onClose }: {
</label>
<label className="block text-sm text-star-300">
Database name
<input name="database" required maxLength={255} className={field} />
<input name="database" required maxLength={255} className={field}
onBlur={(event) => {
// Suggest "<application> · <database>" until the person types their own name. The environment is
// set afterwards in Relations, where the name can still be changed.
const database = event.target.value.trim();
if (!named && database && applicationName) setName(`${applicationName} · ${database}`.slice(0, 128));
}} />
</label>
<Hint>Configure this target UUID under the application’s targets on the assigned agent. Keep the connection settings and credentials on that agent.</Hint>
{register.isError && <p role="alert" className="text-sm text-orbit-red">Could not register the target. Verify its identity, UUID, and Outpost.</p>}

View File

@@ -121,6 +121,7 @@ function RelationCard({ relation, runs, onChanged }: { relation: RefreshRelation
return (
<section className="rounded-xl border border-space-700 p-5" aria-label={`${relation.source_name} to ${relation.target_name}`}>
<p className="text-xs uppercase tracking-wide text-star-300">Application: {relation.source_name}</p>
<div className="flex flex-wrap items-center justify-between gap-3">
<h3 className="text-lg font-semibold text-star-100">
{relation.target_name}

View File

@@ -2,7 +2,7 @@ import { useState, type FormEvent } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
createRelation, endRelation, fetchAccessUsers, fetchRelationAccess, fetchRelations, grantRelationAccess, refusalReason,
retargetRelation, revokeRelationAccess, setOrbitEnvironment, setTargetEnvironment,
renameTarget, retargetRelation, revokeRelationAccess, setOrbitEnvironment, setTargetEnvironment,
type AccessUser, type Environment, type OrbitSetup, type RelationOverview, type RelationView, type TargetSetup,
} from "../../api";
import { Button } from "../ui/Button";
@@ -50,6 +50,7 @@ export function RelationsView() {
const orbitEnv = useMutation({ mutationFn: (v: { id: string; environment: Environment }) => setOrbitEnvironment(v.id, v.environment), onSuccess: refresh });
const targetEnv = useMutation({ mutationFn: (v: { id: string; environment: Environment }) => setTargetEnvironment(v.id, v.environment), onSuccess: refresh });
const create = useMutation({ mutationFn: (v: { source: string; target: string }) => createRelation(v.source, v.target), onSuccess: refresh });
const rename = useMutation({ mutationFn: (v: { id: string; name: string }) => renameTarget(v.id, v.name), onSuccess: refresh });
const end = useMutation({ mutationFn: endRelation, onSuccess: refresh });
const [source, setSource] = useState("");
@@ -58,6 +59,10 @@ export function RelationsView() {
return <p role="alert" className="p-6 text-star-300">Could not load relations. This hub may not support them.</p>;
}
// Several applications can have a target called "dev": the application is what tells them apart.
const appName = (t: TargetSetup) => data.orbits.find((o) => o.application_id === t.application_id)?.name ?? "Unknown application";
// a name that already mentions the application (e.g. "presensi · dev") is not prefixed twice
const targetLabel = (t: TargetSetup) => (t.name.toLowerCase().includes(appName(t).toLowerCase()) ? t.name : `${appName(t)} · ${t.name}`);
const sources = data.orbits.filter((o) => o.ready);
const chosen = data.orbits.find((o) => o.id === source);
const targetsFor = (orbit?: OrbitSetup) =>
@@ -109,11 +114,12 @@ export function RelationsView() {
<h4 className="text-sm font-medium text-star-200">Restore targets</h4>
{data.targets.length === 0 ? <p className="mt-2 text-sm text-star-300">No restore targets are registered yet. Register one from the Orbits console.</p> : (
<table className="mt-2 w-full text-left text-sm">
<thead className="text-star-300"><tr><th className="py-2 pr-3">Target</th><th className="pr-3">Database</th><th className="pr-3">Environment</th><th>Outpost</th></tr></thead>
<thead className="text-star-300"><tr><th className="py-2 pr-3">Application</th><th className="pr-3">Target</th><th className="pr-3">Database</th><th className="pr-3">Environment</th><th>Outpost</th></tr></thead>
<tbody>
{data.targets.map((t: TargetSetup) => (
<tr key={t.id} className="border-t border-space-700 text-star-100">
<td className="py-2 pr-3">{t.name}</td>
<td className="py-2 pr-3">{appName(t)}</td>
<td className="pr-3"><TargetName target={t} pending={rename.isPending} onSave={(name) => rename.mutate({ id: t.id, name })} /></td>
<td className="pr-3 text-star-300">{t.engine} · {t.identity.database}</td>
<td className="pr-3" style={{ minWidth: 160 }}>
<Select aria-label={`Environment of ${t.name}`} value={t.environment ?? ""} onChange={(e) => targetEnv.mutate({ id: t.id, environment: e.target.value as Environment })}>
@@ -132,7 +138,7 @@ export function RelationsView() {
{targetEnv.data && targetEnv.data.ended_relations.length > 0 && (
<p role="status" className="mt-3 text-sm text-orbit-red">Relabelling that target ended {targetEnv.data.ended_relations.length} relation(s) into it.</p>
)}
{(orbitEnv.isError || targetEnv.isError) && <p role="alert" className="mt-3 text-sm text-orbit-red">That change was refused.</p>}
{(orbitEnv.isError || targetEnv.isError || rename.isError) && <p role="alert" className="mt-3 text-sm text-orbit-red">That change was refused.</p>}
</section>
<section aria-labelledby="rel-new">
@@ -152,7 +158,7 @@ export function RelationsView() {
Target database
<Select name="target" required key={source}>
<option value="" disabled>{chosen ? "Choose…" : "Pick a source first"}</option>
{targetsFor(chosen).map((t) => <option key={t.id} value={t.id}>{t.name} ({t.environment})</option>)}
{targetsFor(chosen).map((t) => <option key={t.id} value={t.id}>{targetLabel(t)} ({t.environment})</option>)}
</Select>
</label>
<div className="sm:col-span-2 flex items-center gap-4">
@@ -172,7 +178,7 @@ export function RelationsView() {
{active.length === 0 ? <p className="mt-2 text-sm text-star-300">No active relations.</p> : (
<div className="mt-3 space-y-4">
{active.map((relation) => (
<RelationCard key={relation.id} relation={relation} targets={targetsFor({ id: relation.source_orbit_id, name: relation.source_name, application_id: data.targets.find((t) => t.id === relation.target_id)?.application_id ?? null, engine: relation.engine, environment: relation.source_environment, ready: true, reason: null })}
<RelationCard key={relation.id} relation={relation} labelOf={targetLabel} targets={targetsFor({ id: relation.source_orbit_id, name: relation.source_name, application_id: data.targets.find((t) => t.id === relation.target_id)?.application_id ?? null, engine: relation.engine, environment: relation.source_environment, ready: true, reason: null })}
onEnd={() => end.mutate(relation.id)} ending={end.isPending} onChanged={refresh} />
))}
</div>
@@ -190,8 +196,8 @@ export function RelationsView() {
);
}
function RelationCard({ relation, targets, onEnd, ending, onChanged }: {
relation: RelationView; targets: TargetSetup[]; onEnd: () => void; ending: boolean; onChanged: () => void;
function RelationCard({ relation, targets, labelOf, onEnd, ending, onChanged }: {
relation: RelationView; targets: TargetSetup[]; labelOf: (target: TargetSetup) => string; onEnd: () => void; ending: boolean; onChanged: () => void;
}) {
const qc = useQueryClient();
const retarget = useMutation({ mutationFn: (target: string) => retargetRelation(relation.id, target), onSuccess: onChanged });
@@ -216,7 +222,7 @@ function RelationCard({ relation, targets, onEnd, ending, onChanged }: {
Point at another target
<Select name="target" key={relation.id}>
<option value="" disabled>Choose…</option>
{others.map((t) => <option key={t.id} value={t.id}>{t.name}</option>)}
{others.map((t) => <option key={t.id} value={t.id}>{labelOf(t)}</option>)}
</Select>
</label>
<Button type="submit" disabled={retarget.isPending}>Retarget</Button>
@@ -288,3 +294,31 @@ function RelationAccess({ relationId, onChange }: { relationId: string; onChange
</div>
);
}
/** A target's name with an inline rename. The id and the database it points at never change. */
function TargetName({ target, pending, onSave }: { target: TargetSetup; pending: boolean; onSave: (name: string) => void }) {
const [editing, setEditing] = useState(false);
if (!editing) {
return (
<span className="inline-flex items-center gap-2">
{target.name}
<button type="button" className="console-control" aria-label={`Rename ${target.name}`} onClick={() => setEditing(true)}>Rename</button>
</span>
);
}
return (
<form
className="flex items-center gap-2"
onSubmit={(event) => {
event.preventDefault();
const name = String(new FormData(event.currentTarget).get("name") ?? "").trim();
if (name && name !== target.name) onSave(name);
setEditing(false);
}}
>
<input name="name" aria-label={`New name for ${target.name}`} defaultValue={target.name} required maxLength={128} autoFocus className="field" />
<Button type="submit" disabled={pending}>Save</Button>
<Button type="button" onClick={() => setEditing(false)}>Cancel</Button>
</form>
);
}