Hub 2.7.1: one click is one update

Buttons are off from the click until the Hub answers (the Updates page and
every action on an install's page); the server refuses a second update for
an install with one planned or running (ALREADY_PLANNED). Test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 22:15:58 +02:00
co-authored by Claude Opus 5.5
parent 90fdde054a
commit dab6fbcff6
9 changed files with 81 additions and 21 deletions
@@ -44,7 +44,27 @@ export default function DeploymentPage() {
useEffect(() => { load(); }, [load]);
useEffect(() => { api<Release[]>("/api/admin/releases").then(setReleases).catch(() => {}); }, []);
const act = async (path: string, body: Record<string, unknown>, ok: string) => {
// 2.7.1: every button here is off from a click until the Hub answers, so one click is one job.
const [busy, setBusy] = useState(false);
const withBusy = async (fn: () => Promise<void>) => {
if (busy) return;
setBusy(true);
try {
await fn();
} finally {
setBusy(false);
}
};
const act = async (path: string, body: Record<string, unknown>, ok: string): Promise<void> => {
if (busy && !body.confirmLive) return;
setBusy(true);
try {
await doAct(path, body, ok);
} finally {
setBusy(false);
}
};
const doAct = async (path: string, body: Record<string, unknown>, ok: string): Promise<void> => {
setMsg(null);
try {
const r = await api<{ warnings?: string[] }>(path, { method: "POST", body });
@@ -52,11 +72,12 @@ export default function DeploymentPage() {
load();
} catch (e) {
// Hub 2.7.0: an event is on there now: ask once more, then go ahead.
if (e instanceof ApiError && e.code === "LIVE_EVENT" && !body.confirmLive && window.confirm(e.message)) return act(path, { ...body, confirmLive: true }, ok);
if (e instanceof ApiError && e.code === "LIVE_EVENT" && !body.confirmLive && window.confirm(e.message)) return doAct(path, { ...body, confirmLive: true }, ok);
setMsg({ type: "err", text: errorText(e) });
}
};
const proxyDone = async () => {
const proxyDone = () => withBusy(proxyDoneNow);
const proxyDoneNow = async () => {
setMsg(null);
try {
const r = await api<{ live: boolean; problems: string[] }>(`/api/admin/deployments/${id}/proxy-done`, { method: "POST" });
@@ -66,7 +87,8 @@ export default function DeploymentPage() {
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
};
const removeRecord = async () => {
const removeRecord = () => withBusy(removeRecordNow);
const removeRecordNow = async () => {
if (!d || !window.confirm(`Remove the record of ${d.deployment.shortName}? Its install failed, so nothing of it is on the server.`)) return;
setMsg(null);
try {
@@ -98,7 +120,7 @@ export default function DeploymentPage() {
<div className="card">
<h2 className="font-medium">Set up the site in FastPanel</h2>
<pre className="mt-3 overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-50 p-3 text-xs">{d.fastPanel}</pre>
<button className="btn-primary mt-3" disabled={x.status !== "waiting_for_proxy"} onClick={proxyDone}>Proxy done</button>
<button className="btn-primary mt-3" disabled={x.status !== "waiting_for_proxy" || busy} onClick={proxyDone}>Proxy done</button>
{x.status === "installing" && <p className="mt-2 text-xs text-slate-500">Waiting for the install to finish (see its job below).</p>}
</div>
)}
@@ -126,7 +148,7 @@ export default function DeploymentPage() {
<div><label className="label" htmlFor="u-r">Reason (shown to the church)</label><input id="u-r" className="input" required value={upd.reason} onChange={e => setUpd({ ...upd, reason: e.target.value })} /></div>
<div><label className="label" htmlFor="u-t">Two-factor code</label><input id="u-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={upd.totp} onChange={e => setUpd({ ...upd, totp: e.target.value })} /></div>
</>}
<div className="md:col-span-2"><button className="btn-primary">{upd.emergency && upd.asap ? "Update now" : "Schedule"}</button></div>
<div className="md:col-span-2"><button className="btn-primary" disabled={busy} aria-busy={busy}>{busy ? "Working…" : upd.emergency && upd.asap ? "Update now" : "Schedule"}</button></div>
</form>
)}
@@ -138,7 +160,7 @@ export default function DeploymentPage() {
<div><label className="label" htmlFor="a-a">The church&apos;s address</label><input id="a-a" className="input" required={!x.domain.startsWith("events.")} placeholder={x.domain.startsWith("events.") ? x.domain.slice("events.".length) : "hope.co.za"} value={adopt.address} onChange={e => setAdopt({ ...adopt, address: e.target.value })} /></div>
<div><label className="label" htmlFor="a-v">Release</label><input id="a-v" className="input" placeholder="latest" value={adopt.version} onChange={e => setAdopt({ ...adopt, version: e.target.value })} /></div>
<div><label className="label" htmlFor="a-at">When</label><input id="a-at" type="datetime-local" className="input" value={adopt.at} onChange={e => setAdopt({ ...adopt, at: e.target.value })} /></div>
<div className="md:col-span-3"><button className="btn-primary">Plan the move</button></div>
<div className="md:col-span-3"><button className="btn-primary" disabled={busy}>Plan the move</button></div>
</form>
)}
@@ -149,7 +171,7 @@ export default function DeploymentPage() {
<form className="grid gap-3 md:grid-cols-[1fr_auto] md:items-end" onSubmit={e => { e.preventDefault(); act(`/api/admin/deployments/${x.id}/demo`, { isDemo: true, confirm: demo.markConfirm }, "Marked as a demo site."); }}>
<p className="text-sm text-slate-500 md:col-span-2">A demo site&apos;s data can be replaced with demo data from here. Only mark sites used for showing Cross Events, never a church&apos;s real site.</p>
<div><label className="label" htmlFor="d-m">Type {x.shortName}</label><input id="d-m" className="input" value={demo.markConfirm} onChange={e => setDemo({ ...demo, markConfirm: e.target.value })} /></div>
<button className="btn-secondary" disabled={demo.markConfirm !== x.shortName}>Mark as a demo site</button>
<button className="btn-secondary" disabled={demo.markConfirm !== x.shortName || busy}>Mark as a demo site</button>
</form>
) : (
<>
@@ -164,7 +186,7 @@ export default function DeploymentPage() {
</select>
</div>
<div><label className="label" htmlFor="d-c">Type {x.shortName}</label><input id="d-c" className="input" value={demo.confirm} onChange={e => setDemo({ ...demo, confirm: e.target.value })} /></div>
<button className="btn-danger" disabled={demo.confirm !== x.shortName}>Load demo data</button>
<button className="btn-danger" disabled={demo.confirm !== x.shortName || busy}>Load demo data</button>
</form>
<button type="button" className="text-sm text-slate-500 underline" onClick={() => act(`/api/admin/deployments/${x.id}/demo`, { isDemo: false }, "No longer a demo site.")}>It isn&apos;t a demo site any more</button>
</>
@@ -180,7 +202,7 @@ export default function DeploymentPage() {
<tr key={j.id} className="border-t">
<td className="px-5 py-1.5"><Link className="text-indigo-700 hover:underline" href={`/jobs/${j.id}`}>{j.type}</Link>{j.emergency && <span className="ml-1 text-xs text-red-700">emergency</span>}</td>
<td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td><td className="max-w-md truncate text-xs text-slate-500">{j.message}</td>
<td className="pr-5">{["queued", "scheduled"].includes(j.status) && <button className="btn-secondary px-2 py-1 text-xs" onClick={() => act(`/api/admin/jobs/${j.id}/cancel`, {}, "Cancelled; the church was told.")}>Cancel</button>}</td>
<td className="pr-5">{["queued", "scheduled"].includes(j.status) && <button className="btn-secondary px-2 py-1 text-xs" disabled={busy} onClick={() => act(`/api/admin/jobs/${j.id}/cancel`, {}, "Cancelled; the church was told.")}>Cancel</button>}</td>
</tr>
))}</tbody>
</table>
@@ -198,7 +220,7 @@ export default function DeploymentPage() {
<div className="card border-red-200">
<h2 className="font-medium text-red-800">Remove the record</h2>
<p className="mt-1 text-sm text-slate-500">This install failed and the server already removed what it made, so there&apos;s nothing to export or uninstall. Removing the record frees the short name.</p>
<button className="btn-danger mt-3" onClick={removeRecord}>Remove the record</button>
<button className="btn-danger mt-3" disabled={busy} onClick={removeRecord}>Remove the record</button>
</div>
)}
@@ -209,7 +231,7 @@ export default function DeploymentPage() {
<div><label className="label" htmlFor="x-at">When</label><input id="x-at" type="datetime-local" className="input" value={un.at} onChange={e => setUn({ ...un, at: e.target.value })} /></div>
<div><label className="label" htmlFor="x-c">Type {x.shortName}</label><input id="x-c" className="input" required value={un.confirm} onChange={e => setUn({ ...un, confirm: e.target.value })} /></div>
<div><label className="label" htmlFor="x-t">Two-factor code</label><input id="x-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={un.totp} onChange={e => setUn({ ...un, totp: e.target.value })} /></div>
<div className="md:col-span-3"><button className="btn-danger" disabled={un.confirm !== x.shortName}>Plan the uninstall</button></div>
<div className="md:col-span-3"><button className="btn-danger" disabled={un.confirm !== x.shortName || busy}>Plan the uninstall</button></div>
</form>
)}
</div>
@@ -32,6 +32,8 @@ export default function UpdatesPage() {
const [chosen, setChosen] = useState<string[]>([]);
const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" });
const [msg, setMsg] = useState<Msg>(null);
// 2.7.1: the button is off from the click until the Hub answers, so one click is one update.
const [busy, setBusy] = useState(false);
const load = useCallback(() => {
api<{ deployments: Deployment[] }>("/api/admin/deployments?status=live").then(r => setAll(r.deployments)).catch(e => setMsg({ type: "err", text: errorText(e) }));
@@ -54,8 +56,18 @@ export default function UpdatesPage() {
setMsg(null);
};
const submit = async (e: React.FormEvent | null, confirmLive = false) => {
const submit = async (e: React.FormEvent | null, confirmLive = false): Promise<void> => {
e?.preventDefault();
if (busy && !confirmLive) return;
setBusy(true);
try {
await send(confirmLive);
} finally {
setBusy(false);
}
};
const send = async (confirmLive: boolean): Promise<void> => {
setMsg(null);
const asap = form.emergency && form.asap;
try {
@@ -67,7 +79,7 @@ export default function UpdatesPage() {
load();
} catch (err) {
// Hub 2.7.0: an event is on at one of them: ask once more, then go ahead.
if (err instanceof ApiError && err.code === "LIVE_EVENT" && !confirmLive && window.confirm(err.message)) return submit(null, true);
if (err instanceof ApiError && err.code === "LIVE_EVENT" && !confirmLive && window.confirm(err.message)) return send(true);
setMsg({ type: "err", text: errorText(err) });
}
};
@@ -122,7 +134,7 @@ export default function UpdatesPage() {
<div><label className="label" htmlFor="b-t">Two-factor code</label><input id="b-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={form.totp} onChange={e => setForm({ ...form, totp: e.target.value })} /></div>
</>}
</div>
<button className="btn-primary" disabled={!chosen.length}>{form.emergency && form.asap ? `Update ${chosen.length} ${name} install(s) now` : `Plan the ${name} update for ${chosen.length} install(s)`}</button>
<button className="btn-primary" disabled={!chosen.length || busy} aria-busy={busy}>{busy ? "Working…" : form.emergency && form.asap ? `Update ${chosen.length} ${name} install(s) now` : `Plan the ${name} update for ${chosen.length} install(s)`}</button>
</form>
)}