Hub 2.6.0: paged lists, job status filters, one-product updates, installs found on servers
- Jobs: Succeeded/Cancelled filters, product, type and church search, paged on the server; audit log and alerts paged on the server with search; every other list paged. - Updates: one product at a time with its own releases; an Events update pins the church's Accounts (or updates it when the release needs it, or installs it first); fixes the requirement check comparing an object. - A status job adds installs found on a server and ties them to their registration; unlinked registered sites trigger one (daily); heartbeats tie install records too; the install page shows its registration. 13 new tests (209). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.536.0",
|
||||
"next": "^15.5.24",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3200",
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { useServerPaged } from "@/lib/paging";
|
||||
import type { InstallEvent } from "@/lib/types";
|
||||
import { Badge, Loading, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
|
||||
/** Open alerts, and the history of everything that happened to installs. */
|
||||
/** Open alerts, and the history of everything that happened to installs, a page at a time (Hub 2.6.0: paged on the server). */
|
||||
export default function AlertsPage() {
|
||||
const [openOnly, setOpenOnly] = useState(true);
|
||||
const [events, setEvents] = useState<InstallEvent[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
setEvents(null);
|
||||
api<InstallEvent[]>(`/api/admin/events${openOnly ? "?open=true" : ""}`).then(setEvents).catch(e => setError(errorText(e)));
|
||||
}, [openOnly]);
|
||||
|
||||
const shown = useMemo(() => (events || []).filter(e => matches(query, e.message, e.level, e.install?.name, e.install?.url)), [events, query]);
|
||||
const paged = usePaged(shown, `${query}|${openOnly}`);
|
||||
const [q, setQ] = useState("");
|
||||
useEffect(() => { const t = setTimeout(() => setQ(query.trim()), 300); return () => clearTimeout(t); }, [query]);
|
||||
const paged = useServerPaged<InstallEvent>("/api/admin/events", { open: openOnly ? "true" : "", q }, r => r.events as InstallEvent[]);
|
||||
const events = paged.rows;
|
||||
const error = paged.error;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -32,13 +26,13 @@ export default function AlertsPage() {
|
||||
<SearchInput className="w-full sm:ml-auto sm:w-72" value={query} onChange={setQuery} placeholder="Search alerts or install" />
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-700">{error}</p>}
|
||||
{!events ? <Loading /> : events.length === 0 ? <p className="text-sm text-slate-500">{openOnly ? "No open alerts. 🎉" : "Nothing yet."}</p> : (
|
||||
{!events ? <Loading /> : events.length === 0 && !q ? <p className="text-sm text-slate-500">{openOnly ? "No open alerts. 🎉" : "Nothing yet."}</p> : (
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500"><tr><th className="p-3">When</th><th className="p-3">Install</th><th className="p-3">What</th><th className="p-3">State</th></tr></thead>
|
||||
<tbody>
|
||||
{paged.rows.length === 0 && <tr><td colSpan={4} className="p-3 text-slate-500">No alerts match.</td></tr>}
|
||||
{paged.rows.map(e => (
|
||||
{events.length === 0 && <tr><td colSpan={4} className="p-3 text-slate-500">No alerts match.</td></tr>}
|
||||
{events.map(e => (
|
||||
<tr key={e.id} className="border-t align-top">
|
||||
<td className="p-3 whitespace-nowrap text-xs text-slate-500">{fmtDate(e.createdAt)}</td>
|
||||
<td className="p-3">{e.install ? <Link href={`/installs/${e.install.id}`} className="text-indigo-700 hover:underline">{e.install.name}</Link> : "—"}</td>
|
||||
@@ -48,7 +42,7 @@ export default function AlertsPage() {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<Pager {...paged} />
|
||||
<Pager page={paged.page} pages={paged.pages} setPage={paged.setPage} total={paged.total} pageSize={paged.pageSize} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -2,49 +2,64 @@
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { useServerPaged } from "@/lib/paging";
|
||||
import { Loading, Message, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, type Job } from "@/components/servers";
|
||||
|
||||
const FILTERS = [
|
||||
{ key: "", label: "All" },
|
||||
{ key: "upcoming", label: "Planned and running" },
|
||||
{ key: "failed", label: "Failed" },
|
||||
{ key: "succeeded", label: "Succeeded" },
|
||||
{ key: "failed,timed_out", label: "Failed" },
|
||||
{ key: "rolled_back", label: "Rolled back" },
|
||||
{ key: "missed", label: "Missed" },
|
||||
{ key: "refused", label: "Refused" },
|
||||
{ key: "cancelled", label: "Cancelled" },
|
||||
];
|
||||
|
||||
/** Every job sent to a server's agent, newest first (§11: the full report is on each job). */
|
||||
const TYPES = ["", "install", "add-product", "deploy", "adopt", "adopt-undo", "export", "uninstall", "purge", "seed-demo", "restart", "status", "check-ports", "update-agent"];
|
||||
const PRODUCTS = [{ key: "", label: "Every product" }, { key: "events", label: "Cross Events" }, { key: "accounts", label: "Accounts" }];
|
||||
|
||||
/** Every job sent to a server's agent, newest first, a page at a time (§11: the full report is on each job). */
|
||||
export default function JobsPage() {
|
||||
const [filter, setFilter] = useState("");
|
||||
const [jobs, setJobs] = useState<Job[] | null>(null);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const q = filter === "upcoming" ? "?upcoming=true" : filter ? `?status=${filter}` : "";
|
||||
setJobs(null);
|
||||
api<{ jobs: Job[] }>(`/api/admin/jobs${q}`).then(r => setJobs(r.jobs)).catch(e => setErr(errorText(e)));
|
||||
}, [filter]);
|
||||
const [type, setType] = useState("");
|
||||
const [product, setProduct] = useState("");
|
||||
const [query, setQuery] = useState("");
|
||||
const [q, setQ] = useState("");
|
||||
// Searching asks the server, so wait for a pause in typing.
|
||||
useEffect(() => { const t = setTimeout(() => setQ(query.trim()), 300); return () => clearTimeout(t); }, [query]);
|
||||
const params = { ...(filter === "upcoming" ? { upcoming: "true" } : filter ? { status: filter } : {}), type, product, q };
|
||||
const paged = useServerPaged<Job>("/api/admin/jobs", params, r => r.jobs as Job[]);
|
||||
const jobs = paged.rows;
|
||||
return (
|
||||
<div>
|
||||
<PageTitle title="Jobs" subtitle="Installs, updates, adopts, exports, uninstalls and checks run by the agents." />
|
||||
<ServersNav active="/jobs" />
|
||||
{err && <Message msg={{ type: "err", text: err }} />}
|
||||
<div className="mb-4 flex flex-wrap gap-2">{FILTERS.map(f => <button key={f.key} className={filter === f.key ? "btn-primary" : "btn-secondary"} onClick={() => setFilter(f.key)}>{f.label}</button>)}</div>
|
||||
{paged.error && <Message msg={{ type: "err", text: paged.error }} />}
|
||||
<div className="mb-3 flex flex-wrap gap-2">{FILTERS.map(f => <button key={f.key} className={filter === f.key ? "btn-primary" : "btn-secondary"} onClick={() => setFilter(f.key)}>{f.label}</button>)}</div>
|
||||
<div className="mb-4 grid gap-2 md:grid-cols-3">
|
||||
<SearchInput value={query} onChange={setQuery} placeholder="Search a church or domain" />
|
||||
<select className="input" aria-label="Product" value={product} onChange={e => setProduct(e.target.value)}>{PRODUCTS.map(p => <option key={p.key} value={p.key}>{p.label}</option>)}</select>
|
||||
<select className="input" aria-label="Job type" value={type} onChange={e => setType(e.target.value)}>{TYPES.map(t => <option key={t} value={t}>{t || "Every job type"}</option>)}</select>
|
||||
</div>
|
||||
{!jobs ? <Loading /> : (
|
||||
<div className="card overflow-x-auto">
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Job</th><th>Server</th><th>Install</th><th>When</th><th>Status</th><th>Result</th></tr></thead>
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-4 py-2">Job</th><th>Server</th><th>Install</th><th>When</th><th>Status</th><th>Result</th></tr></thead>
|
||||
<tbody>{jobs.map(j => (
|
||||
<tr key={j.id} className="border-t">
|
||||
<td className="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>{j.server?.name}</td><td>{j.deployment?.shortName || String(j.args?.church || "–")}</td><td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td>
|
||||
<td className="max-w-sm truncate text-xs text-slate-500">{j.message}</td>
|
||||
<td className="px-4 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>{j.server?.name}</td>
|
||||
<td>{j.deployment?.shortName || String(j.args?.church || "–")}{j.deployment?.product && <span className="ml-1 text-xs text-slate-500">{j.deployment.product}</span>}</td>
|
||||
<td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td>
|
||||
<td className="max-w-sm truncate pr-4 text-xs text-slate-500">{j.message}</td>
|
||||
</tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
{!jobs.length && <p className="mt-2 text-sm text-slate-500">No jobs.</p>}
|
||||
{!jobs.length && <p className="px-4 py-3 text-sm text-slate-500">No jobs.</p>}
|
||||
<Pager page={paged.page} pages={paged.pages} setPage={paged.setPage} total={paged.total} pageSize={paged.pageSize} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,8 @@ import { api, errorText } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import { PRODUCTS, PRODUCT_NAMES, type Product } from "@/lib/products";
|
||||
import type { Release, ReleaseSource } from "@/lib/types";
|
||||
import { Badge, Loading, Message, PageTitle, ReleaseNotes } from "@/components/ui";
|
||||
import { usePaged } from "@/lib/paging";
|
||||
import { Badge, Loading, Message, PageTitle, Pager, ReleaseNotes } from "@/components/ui";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
type Form = { product: Product; version: string; notes: string; urgent: boolean; releasedAt: string };
|
||||
@@ -156,6 +157,8 @@ export default function ReleasesPage() {
|
||||
const fromGit = useMemo(() => new Set((state?.releaseSources || []).map(s => s.product)), [state]);
|
||||
const manual = PRODUCTS.filter(p => !fromGit.has(p));
|
||||
const shown = (releases || []).filter(r => filter === "all" || r.product === filter);
|
||||
// Hub 2.6.0: a page at a time.
|
||||
const paged = usePaged(shown, filter, 15);
|
||||
|
||||
const body = (f: Form) => ({ product: f.product, version: f.version, notes: f.notes, urgent: f.urgent, releasedAt: f.releasedAt ? `${f.releasedAt}T12:00:00+02:00` : null });
|
||||
|
||||
@@ -207,7 +210,7 @@ export default function ReleasesPage() {
|
||||
|
||||
{!releases ? <Loading /> : shown.length === 0 ? <p className="text-sm text-slate-500">No releases yet{filter === "all" ? "" : ` for ${PRODUCT_NAMES[filter]}`}.</p> : (
|
||||
<div className="space-y-4">
|
||||
{shown.map(r => (
|
||||
{paged.rows.map(r => (
|
||||
<div key={r.id} className="card">
|
||||
{editing === r.id ? (
|
||||
<ReleaseForm initial={{ product: r.product, version: r.version, notes: r.notes, urgent: r.urgent, releasedAt: r.releasedAt.slice(0, 10) }} products={null} busy={busy} onSave={f => save(f, r.id)} onCancel={() => setEditing(null)} />
|
||||
@@ -235,6 +238,7 @@ export default function ReleasesPage() {
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div className="card p-0"><Pager {...paged} /></div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -6,7 +6,8 @@ import { useParams, useRouter } from "next/navigation";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, bytes, fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { useServerPaged } from "@/lib/paging";
|
||||
import { Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
import { PercentChart, ServersNav, StatusPill, pct, type Deployment, type Job, type ServerSummary } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
@@ -66,6 +67,8 @@ export default function ServerPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const router = useRouter();
|
||||
const [d, setD] = useState<Detail | null>(null);
|
||||
// Hub 2.6.0: every job on this server, a page at a time (it showed the last 25).
|
||||
const jobsPaged = useServerPaged<Job>("/api/admin/jobs", { serverId: String(id) }, r => r.jobs as Job[], 20);
|
||||
const [range, setRange] = useState<"24h" | "7d" | "90d">("24h");
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
const [agentVersion, setAgentVersion] = useState("");
|
||||
@@ -126,7 +129,8 @@ export default function ServerPage() {
|
||||
</div>
|
||||
<div className="card space-y-2 text-sm">
|
||||
<h2 className="font-medium">Actions</h2>
|
||||
<button className="btn-secondary w-full" onClick={() => job("status")}>Check status now</button>
|
||||
<button className="btn-secondary w-full" onClick={() => job("status")}>Check status and find installs</button>
|
||||
<p className="text-xs text-slate-500">Asks the agent what's on the server. A site added there without the Hub (crosscode add, or by hand) is added to Installs and tied to its registration. It also runs by itself once a day when a registered site has no install record here.</p>
|
||||
<div className="flex gap-2"><input className="input" placeholder="agent@1.0.1" value={agentVersion} onChange={e => setAgentVersion(e.target.value)} aria-label="Agent version" /><button className="btn-secondary" disabled={!agentVersion} onClick={() => job("update-agent", { version: agentVersion })}>Update agent</button></div>
|
||||
<button className="btn-danger w-full" onClick={remove}><Trash2 className="h-4 w-4" /> Remove server</button>
|
||||
</div>
|
||||
@@ -157,12 +161,13 @@ export default function ServerPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card overflow-x-auto">
|
||||
<h2 className="font-medium">Recent jobs</h2>
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<h2 className="px-5 pt-5 font-medium">Jobs</h2>
|
||||
<table className="mt-3 w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Job</th><th>When</th><th>Status</th><th>Result</th></tr></thead>
|
||||
<tbody>{d.jobs.map(j => <tr key={j.id} className="border-t"><td className="py-1.5"><Link className="text-indigo-700 hover:underline" href={`/jobs/${j.id}`}>{j.type}</Link> <span className="text-xs text-slate-500">{String(j.args?.church || "")}</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></tr>)}</tbody>
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-5 py-1">Job</th><th>When</th><th>Status</th><th>Result</th></tr></thead>
|
||||
<tbody>{(jobsPaged.rows ?? d.jobs).map(j => <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> <span className="text-xs text-slate-500">{String(j.args?.church || "")}</span></td><td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td><td className="max-w-md truncate pr-5 text-xs text-slate-500">{j.message}</td></tr>)}</tbody>
|
||||
</table>
|
||||
<Pager page={jobsPaged.page} pages={jobsPaged.pages} setPage={jobsPaged.setPage} total={jobsPaged.total} pageSize={jobsPaged.pageSize} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,13 +4,16 @@ import React, { useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { bytes, fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { ago, bytes, fmtDate } from "@/lib/format";
|
||||
import { useServerPaged } from "@/lib/paging";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import type { Release } from "@/lib/types";
|
||||
import { Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, toInput, fromInput, type Deployment, type Job, type ServerSummary } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
type Detail = {
|
||||
deployment: Deployment & { server: ServerSummary; jobs: Job[]; exports: { id: string; bytes: number; expiresAt: string; downloadedAt: string | null; deletedAt: string | null }[]; install: { version: string | null; url: string } | null };
|
||||
deployment: Deployment & { server: ServerSummary; jobs: Job[]; exports: { id: string; bytes: number; expiresAt: string; downloadedAt: string | null; deletedAt: string | null }[]; install: { version: string | null; url: string; lastHeartbeatAt: string | null } | null };
|
||||
fastPanel: string;
|
||||
canRemoveRecord: boolean;
|
||||
};
|
||||
@@ -30,8 +33,16 @@ export default function DeploymentPage() {
|
||||
const [un, setUn] = useState({ at: toInput(new Date(Date.now() + 7 * 24 * H)), totp: "", confirm: "" });
|
||||
const [demo, setDemo] = useState({ profile: "events", confirm: "", markConfirm: "" });
|
||||
|
||||
const load = useCallback(() => api<Detail>(`/api/admin/deployments/${id}`).then(setD).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]);
|
||||
const [releases, setReleases] = useState<Release[]>([]);
|
||||
// Hub 2.6.0: every job of this install, a page at a time (it showed the last 50).
|
||||
const jobsPaged = useServerPaged<Job>("/api/admin/jobs", { deploymentId: String(id) }, r => r.jobs as Job[], 20);
|
||||
const load = useCallback(() => {
|
||||
jobsPaged.reload();
|
||||
return api<Detail>(`/api/admin/deployments/${id}`).then(setD).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- reload is a fresh function each render
|
||||
}, [id]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
useEffect(() => { api<Release[]>("/api/admin/releases").then(setReleases).catch(() => {}); }, []);
|
||||
|
||||
const act = async (path: string, body: unknown, ok: string) => {
|
||||
setMsg(null);
|
||||
@@ -70,6 +81,12 @@ export default function DeploymentPage() {
|
||||
<PageTitle title={`${x.customer?.name} (${x.shortName})`} subtitle={<>{x.domain} · on <Link className="text-indigo-700 hover:underline" href={`/servers/${x.serverId}`}>{x.server.name}</Link> · ports web {x.webPort}, api {x.apiPort} · version {x.install?.version || x.version || "–"} <StatusPill status={x.status} /></>} />
|
||||
<ServersNav active="/servers/installs" />
|
||||
<Message msg={msg} />
|
||||
{/* Hub 2.6.0: whether the site has registered with the Hub (its banners, licence and heartbeats need it). */}
|
||||
<p className="mt-2 text-sm text-slate-600">
|
||||
{x.install
|
||||
? <>Registered site: <a className="text-indigo-700 hover:underline" href={x.install.url} target="_blank" rel="noreferrer">{x.install.url}</a>, last heartbeat {x.install.lastHeartbeatAt ? ago(x.install.lastHeartbeatAt) : "never"}.</>
|
||||
: <span className="text-amber-800">The site hasn't registered with the Hub yet. It registers by itself with its licence key when it starts, and is tied to this record at its first heartbeat; if that doesn't happen, check its HUB_URL and HUB_LICENCE_KEY.</span>}
|
||||
</p>
|
||||
{!!problems.length && <ul className="mt-2 list-disc pl-6 text-sm text-red-800">{problems.map(p => <li key={p}>{p}</li>)}</ul>}
|
||||
</div>
|
||||
|
||||
@@ -83,9 +100,15 @@ export default function DeploymentPage() {
|
||||
)}
|
||||
|
||||
{x.status === "live" && (
|
||||
<form className="card grid gap-3 md:grid-cols-2" onSubmit={e => { e.preventDefault(); act("/api/admin/updates", { deploymentIds: [x.id], version: upd.version || undefined, at: fromInput(upd.at), emergency: upd.emergency, reason: upd.reason || null, totp: upd.totp || null }, "Planned. The site admin was emailed and sees a banner."); }}>
|
||||
<form className="card grid gap-3 md:grid-cols-2" onSubmit={e => { e.preventDefault(); act("/api/admin/updates", { deploymentIds: [x.id], product: x.product, version: upd.version || undefined, at: fromInput(upd.at), emergency: upd.emergency, reason: upd.reason || null, totp: upd.totp || null }, "Planned. The site admin was emailed and sees a banner."); }}>
|
||||
<h2 className="font-medium md:col-span-2">Schedule an update</h2>
|
||||
<div><label className="label" htmlFor="u-v">Release</label><input id="u-v" className="input" placeholder="latest" value={upd.version} onChange={e => setUpd({ ...upd, version: e.target.value })} /></div>
|
||||
<div>
|
||||
<label className="label" htmlFor="u-v">{PRODUCT_NAMES[x.product as keyof typeof PRODUCT_NAMES] || x.product} release</label>
|
||||
<select id="u-v" className="input" value={upd.version} onChange={e => setUpd({ ...upd, version: e.target.value })}>
|
||||
<option value="">Latest</option>
|
||||
{releases.filter(r => r.product === x.product).map(r => <option key={r.id} value={r.version}>{r.version}{r.latest ? " (latest)" : ""}{r.requires?.length ? ` · needs ${r.requires.map(q => `${PRODUCT_NAMES[q.product]} ${q.version}`).join(", ")}` : ""}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="u-at">When</label><input id="u-at" type="datetime-local" className="input" value={upd.at} min={toInput(new Date(Date.now() + minAt))} onChange={e => setUpd({ ...upd, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {upd.emergency ? "15 minutes" : "4 hours"} away, so the church gets notice.</p></div>
|
||||
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={upd.emergency} onChange={e => setUpd({ ...upd, emergency: e.target.checked })} /> Emergency (security fix or broken release): 15 minutes' notice, a reason and your two-factor code</label>
|
||||
{upd.emergency && <>
|
||||
@@ -138,18 +161,19 @@ export default function DeploymentPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card overflow-x-auto">
|
||||
<h2 className="font-medium">Jobs</h2>
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<h2 className="px-5 pt-5 font-medium">Jobs</h2>
|
||||
<table className="mt-3 w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Job</th><th>When</th><th>Status</th><th>Result</th><th /></tr></thead>
|
||||
<tbody>{x.jobs.map(j => (
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-5 py-1">Job</th><th>When</th><th>Status</th><th>Result</th><th /></tr></thead>
|
||||
<tbody>{(jobsPaged.rows ?? x.jobs).map(j => (
|
||||
<tr key={j.id} className="border-t">
|
||||
<td className="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 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>{["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" onClick={() => act(`/api/admin/jobs/${j.id}/cancel`, {}, "Cancelled; the church was told.")}>Cancel</button>}</td>
|
||||
</tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
<Pager page={jobsPaged.page} pages={jobsPaged.pages} setPage={jobsPaged.setPage} total={jobsPaged.total} pageSize={jobsPaged.pageSize} />
|
||||
</div>
|
||||
|
||||
{!!x.exports.length && (
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Link2, Plus } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import { Loading, Message, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, pct, type Deployment, type ServerSummary } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
@@ -20,6 +22,11 @@ const emptyLink = { installId: "", serverId: "", shortName: "", webPort: "", api
|
||||
export default function InstallsPage() {
|
||||
const router = useRouter();
|
||||
const [list, setList] = useState<Deployment[] | null>(null);
|
||||
// Hub 2.6.0: which product each install is, a filter for it, a search, and a page at a time.
|
||||
const [product, setProduct] = useState("");
|
||||
const [query, setQuery] = useState("");
|
||||
const shown = useMemo(() => (list || []).filter(d => (!product || d.product === product) && matches(query, d.customer?.name, d.shortName, d.domain, d.server?.name)), [list, product, query]);
|
||||
const paged = usePaged(shown, `${product}|${query}`);
|
||||
const [srv, setSrv] = useState<ServerSummary[]>([]);
|
||||
const [customers, setCustomers] = useState<Customer[]>([]);
|
||||
const [installs, setInstalls] = useState<InstallRow[]>([]);
|
||||
@@ -138,14 +145,23 @@ export default function InstallsPage() {
|
||||
)}
|
||||
|
||||
{!list ? <Loading /> : (
|
||||
<div className="card overflow-x-auto">
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<div className="flex flex-wrap gap-2 p-4">
|
||||
<select className="input w-48" aria-label="Product" value={product} onChange={e => setProduct(e.target.value)}>
|
||||
<option value="">Every product</option>
|
||||
<option value="events">{PRODUCT_NAMES.events}</option>
|
||||
<option value="accounts">{PRODUCT_NAMES.accounts}</option>
|
||||
</select>
|
||||
<SearchInput className="w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search a church, domain or server" />
|
||||
</div>
|
||||
<table className="w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Church</th><th>Domain</th><th>Server</th><th>Version</th><th>Last heartbeat</th><th>Status</th></tr></thead>
|
||||
<tbody>{list.map(d => (
|
||||
<tr key={d.id} className="border-t"><td className="py-1.5"><Link className="text-indigo-700 hover:underline" href={`/servers/installs/${d.id}`}>{d.customer?.name} ({d.shortName})</Link>{d.isDemo && <span className="ml-1 rounded bg-sky-100 px-1.5 text-xs text-sky-800">demo</span>}</td><td>{d.domain}</td><td>{d.server?.name}</td><td>{d.install?.version || d.version || "–"}</td><td>{ago(d.install?.lastHeartbeatAt)}</td><td><StatusPill status={d.status} /></td></tr>
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-4 py-1">Church</th><th>Product</th><th>Domain</th><th>Server</th><th>Version</th><th>Last heartbeat</th><th>Status</th></tr></thead>
|
||||
<tbody>{paged.rows.map(d => (
|
||||
<tr key={d.id} className="border-t"><td className="px-4 py-1.5"><Link className="text-indigo-700 hover:underline" href={`/servers/installs/${d.id}`}>{d.customer?.name} ({d.shortName})</Link>{d.isDemo && <span className="ml-1 rounded bg-sky-100 px-1.5 text-xs text-sky-800">demo</span>}</td><td>{PRODUCT_NAMES[d.product as keyof typeof PRODUCT_NAMES] || d.product}</td><td>{d.domain}</td><td>{d.server?.name}</td><td>{d.install?.version || d.version || "–"}</td><td>{d.installId ? ago(d.install?.lastHeartbeatAt) : <span className="text-amber-800">not registered</span>}</td><td><StatusPill status={d.status} /></td></tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
{!list.length && <p className="mt-2 text-sm text-slate-500">No installs on servers yet.</p>}
|
||||
{!list.length ? <p className="px-4 py-3 text-sm text-slate-500">No installs on servers yet.</p> : !shown.length && <p className="px-4 py-3 text-sm text-slate-500">No installs match.</p>}
|
||||
<Pager {...paged} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,8 @@ import Link from "next/link";
|
||||
import { Copy, Plus } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, bytes } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { usePaged } from "@/lib/paging";
|
||||
import { Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, pct, type ServerSummary } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
@@ -13,6 +14,7 @@ type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
/** Hub → Servers: every server with its agent, resources and sites; Add server (§3, §10). */
|
||||
export default function ServersPage() {
|
||||
const [list, setList] = useState<ServerSummary[] | null>(null);
|
||||
const paged = usePaged(list || [], null, 20);
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
@@ -67,7 +69,7 @@ export default function ServersPage() {
|
||||
|
||||
{!list ? <Loading /> : list.length === 0 ? <p className="text-sm text-slate-500">No servers yet. Add one to install churches from the Hub.</p> : (
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{list.map(s => {
|
||||
{paged.rows.map(s => {
|
||||
const disk = s.disk.reduce((m, d) => Math.max(m, d.totalBytes ? (d.usedBytes / d.totalBytes) * 100 : 0), 0);
|
||||
return (
|
||||
<Link key={s.id} href={`/servers/${s.id}`} className="card block hover:border-indigo-300">
|
||||
@@ -99,6 +101,7 @@ export default function ServersPage() {
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{list && <div className="mt-4"><Pager {...paged} /></div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ import React, { useCallback, useEffect, useState } from "react";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { usePaged } from "@/lib/paging";
|
||||
import { Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
import { ServersNav } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
@@ -13,6 +14,7 @@ type Port = { port: number; role: string; note: string | null; releasedAt: strin
|
||||
/** The port list (§6) and the install defaults (§5): the same for every install. */
|
||||
export default function ServerSettingsPage() {
|
||||
const [ports, setPorts] = useState<Port[] | null>(null);
|
||||
const portsPaged = usePaged(ports || [], null, 30);
|
||||
const [range, setRange] = useState({ from: "20000", to: "29999" });
|
||||
const [defaults, setDefaults] = useState<[string, string][]>([]);
|
||||
const [ip, setIp] = useState("");
|
||||
@@ -77,12 +79,13 @@ export default function ServerSettingsPage() {
|
||||
{!ports ? <Loading /> : (
|
||||
<table className="mt-3 w-full text-sm tabular-nums">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Port</th><th>Use</th><th>Server</th><th>Note</th><th /></tr></thead>
|
||||
<tbody>{ports.map(p => (
|
||||
<tbody>{portsPaged.rows.map(p => (
|
||||
<tr key={p.port} className="border-t"><td className="py-1.5">{p.port}</td><td>{p.releasedAt ? `free from ${fmtDate(new Date(new Date(p.releasedAt).getTime() + 30 * 24 * 3600 * 1000), false)}` : p.role}</td><td>{p.server?.name || "–"}</td><td className="text-xs text-slate-500">{p.note}</td>
|
||||
<td>{(p.role === "taken" || p.releasedAt) && <button className="btn-secondary px-2 py-1 text-xs" onClick={() => free(p.port)}>Remove</button>}</td></tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
)}
|
||||
{ports && <Pager {...portsPaged} />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,68 +4,105 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { usePaged } from "@/lib/paging";
|
||||
import { PRODUCT_NAMES } from "@/lib/products";
|
||||
import type { Release } from "@/lib/types";
|
||||
import { Loading, Message, PageTitle, Pager, Tabs } from "@/components/ui";
|
||||
import { ServersNav, StatusPill, toInput, fromInput, type Deployment, type Job } from "@/components/servers";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string } | null;
|
||||
const H = 60 * 60 * 1000;
|
||||
/** Products the Hub updates on servers. */
|
||||
const UPDATABLE = ["events", "accounts"] as const;
|
||||
type Updatable = (typeof UPDATABLE)[number];
|
||||
|
||||
const versionOf = (d: Deployment) => d.install?.version || d.version || "?";
|
||||
|
||||
/**
|
||||
* Updates (§8): one release to several installs at one time with one notice. They run one at a
|
||||
* time, and the batch stops at the first failure (the rest are told it's postponed).
|
||||
* Updates (§8): one release of **one product** to several installs at one time with one notice.
|
||||
* They run one at a time, and the batch stops at the first failure (the rest are told it's
|
||||
* postponed). Hub 2.6.0: the product is chosen first, so only its installs and its own releases are
|
||||
* offered; a Cross Events update says what happens to each church's Accounts.
|
||||
*/
|
||||
export default function UpdatesPage() {
|
||||
const [deployments, setDeployments] = useState<Deployment[] | null>(null);
|
||||
const [product, setProduct] = useState<Updatable>("events");
|
||||
const [all, setAll] = useState<Deployment[] | null>(null);
|
||||
const [releases, setReleases] = useState<Release[]>([]);
|
||||
const [upcoming, setUpcoming] = useState<Job[]>([]);
|
||||
const [chosen, setChosen] = useState<string[]>([]);
|
||||
const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, reason: "", totp: "" });
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
|
||||
const load = useCallback(() => {
|
||||
api<{ deployments: Deployment[] }>("/api/admin/deployments?status=live").then(r => setDeployments(r.deployments)).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
api<{ jobs: Job[] }>("/api/admin/jobs?upcoming=true").then(r => setUpcoming(r.jobs)).catch(() => {});
|
||||
api<{ deployments: Deployment[] }>("/api/admin/deployments?status=live").then(r => setAll(r.deployments)).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
api<Release[]>("/api/admin/releases").then(setReleases).catch(() => {});
|
||||
api<{ jobs: Job[] }>("/api/admin/jobs?upcoming=true&pageSize=200").then(r => setUpcoming(r.jobs)).catch(() => {});
|
||||
}, []);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
const byVersion = useMemo(() => [...new Set((deployments || []).map(d => d.install?.version || d.version || "?"))].sort(), [deployments]);
|
||||
|
||||
const deployments = useMemo(() => (all || []).filter(d => d.product === product), [all, product]);
|
||||
const ownReleases = useMemo(() => releases.filter(r => r.product === product), [releases, product]);
|
||||
const latest = ownReleases.find(r => r.latest)?.version;
|
||||
const byVersion = useMemo(() => [...new Set(deployments.map(versionOf))].sort(), [deployments]);
|
||||
const upcomingPaged = usePaged(upcoming, upcoming.length, 20);
|
||||
|
||||
// Another product: nothing chosen carries over, and the release starts at "latest".
|
||||
const pick = (p: Updatable) => {
|
||||
setProduct(p);
|
||||
setChosen([]);
|
||||
setForm(f => ({ ...f, version: "" }));
|
||||
setMsg(null);
|
||||
};
|
||||
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setMsg(null);
|
||||
try {
|
||||
const r = await api<{ jobs: Job[]; warnings: string[] }>("/api/admin/updates", { method: "POST", body: { deploymentIds: chosen, version: form.version || undefined, at: fromInput(form.at), emergency: form.emergency, reason: form.reason || null, totp: form.totp || null } });
|
||||
setMsg({ type: "ok", text: `Planned for ${r.jobs.length} install(s); each church was emailed and sees a banner.${r.warnings.length ? ` Note: ${r.warnings.join(" ")}` : ""}` });
|
||||
const r = await api<{ jobs: Job[]; warnings: string[] }>("/api/admin/updates", { method: "POST", body: { deploymentIds: chosen, product, version: form.version || undefined, at: fromInput(form.at), emergency: form.emergency, reason: form.reason || null, totp: form.totp || null } });
|
||||
const deploys = r.jobs.filter(j => j.type === "deploy").length;
|
||||
const installs = r.jobs.length - deploys;
|
||||
setMsg({ type: "ok", text: `Planned for ${deploys} install(s)${installs ? `, with ${installs} Accounts install(s) first` : ""}; each church was emailed and sees a banner.${r.warnings.length ? ` Note: ${r.warnings.join(" ")}` : ""}` });
|
||||
setChosen([]);
|
||||
load();
|
||||
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
|
||||
};
|
||||
|
||||
const name = PRODUCT_NAMES[product];
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<PageTitle title="Updates" subtitle="Plan a release for one or more installs. Churches get an email and a banner now, and a reminder an hour before." />
|
||||
<PageTitle title="Updates" subtitle="Plan a release for one or more installs of one product. Churches get an email and a banner now, and a reminder an hour before." />
|
||||
<ServersNav active="/servers/updates" />
|
||||
<Message msg={msg} />
|
||||
</div>
|
||||
|
||||
{!deployments ? <Loading /> : (
|
||||
{!all ? <Loading /> : (
|
||||
<form className="card space-y-4" onSubmit={submit}>
|
||||
<Tabs tabs={UPDATABLE.map(p => ({ key: p, label: `${PRODUCT_NAMES[p]} (${(all || []).filter(d => d.product === p).length})` }))} active={product} onChange={pick} />
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="text-slate-500">Select:</span>
|
||||
<button type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.map(d => d.id))}>All live ({deployments.length})</button>
|
||||
{byVersion.map(v => <button key={v} type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.filter(d => (d.install?.version || d.version || "?") === v).map(d => d.id))}>On {v}</button>)}
|
||||
<button type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.map(d => d.id))}>All live {name} ({deployments.length})</button>
|
||||
{byVersion.map(v => <button key={v} type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.filter(d => versionOf(d) === v).map(d => d.id))}>On {name} {v}</button>)}
|
||||
<button type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen([])}>None</button>
|
||||
</div>
|
||||
<div className="max-h-72 space-y-1 overflow-y-auto rounded-lg border border-slate-200 p-3">
|
||||
{deployments.map(d => (
|
||||
<label key={d.id} className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" checked={chosen.includes(d.id)} onChange={() => setChosen(chosen.includes(d.id) ? chosen.filter(x => x !== d.id) : [...chosen, d.id])} />
|
||||
<span className="font-medium">{d.customer?.name}</span><span className="text-slate-500">{d.domain} · {d.install?.version || d.version || "?"} · {d.server?.name}</span>
|
||||
<span className="font-medium">{d.customer?.name}</span><span className="text-slate-500">{d.domain} · {name} {versionOf(d)} · {d.server?.name}</span>
|
||||
</label>
|
||||
))}
|
||||
{!deployments.length && <p className="text-sm text-slate-500">No live installs on servers.</p>}
|
||||
{!deployments.length && <p className="text-sm text-slate-500">No live {name} installs on servers.</p>}
|
||||
</div>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
<div><label className="label" htmlFor="b-v">Release</label><input id="b-v" className="input" placeholder="latest" value={form.version} onChange={e => setForm({ ...form, version: e.target.value })} /></div>
|
||||
<div>
|
||||
<label className="label" htmlFor="b-v">{name} release</label>
|
||||
<select id="b-v" className="input" value={form.version} onChange={e => setForm({ ...form, version: e.target.value })}>
|
||||
<option value="">Latest{latest ? ` (${latest})` : ""}</option>
|
||||
{ownReleases.map(r => <option key={r.id} value={r.version}>{r.version}{r.latest ? " (latest)" : ""}{r.requires?.length ? ` · needs ${r.requires.map(q => `${PRODUCT_NAMES[q.product]} ${q.version}`).join(", ")}` : ""}</option>)}
|
||||
</select>
|
||||
{product === "events" && <p className="mt-1 text-xs text-slate-500">Each church's Accounts stays on its version, unless this release needs a newer one: then it's updated first in the same deploy, or installed first if the church has none. The confirmation lists what happens.</p>}
|
||||
</div>
|
||||
<div><label className="label" htmlFor="b-at">When</label><input id="b-at" type="datetime-local" className="input" value={form.at} onChange={e => setForm({ ...form, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {form.emergency ? "15 minutes" : "4 hours"} away. They run one at a time from then.</p></div>
|
||||
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={form.emergency} onChange={e => setForm({ ...form, emergency: e.target.checked })} /> Emergency: 15 minutes' notice, with a reason and your two-factor code</label>
|
||||
{form.emergency && <>
|
||||
@@ -73,17 +110,18 @@ 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}>Plan the update for {chosen.length} install(s)</button>
|
||||
<button className="btn-primary" disabled={!chosen.length}>Plan the {name} update for {chosen.length} install(s)</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<div className="card overflow-x-auto">
|
||||
<h2 className="font-medium">Planned and running</h2>
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<h2 className="px-5 pt-5 font-medium">Planned and running</h2>
|
||||
<table className="mt-3 w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Job</th><th>Install</th><th>When</th><th>Status</th></tr></thead>
|
||||
<tbody>{upcoming.map(j => <tr key={j.id} className="border-t"><td className="py-1.5"><Link className="text-indigo-700 hover:underline" href={`/jobs/${j.id}`}>{j.type}</Link>{j.batchId && <span className="ml-1 text-xs text-slate-500">batch</span>}{j.emergency && <span className="ml-1 text-xs text-red-700">emergency</span>}</td><td>{j.deployment?.shortName || "–"}</td><td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td></tr>)}</tbody>
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="px-5 py-1">Job</th><th>Install</th><th>When</th><th>Status</th></tr></thead>
|
||||
<tbody>{upcomingPaged.rows.map(j => <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.batchId && <span className="ml-1 text-xs text-slate-500">batch</span>}{j.emergency && <span className="ml-1 text-xs text-red-700">emergency</span>}</td><td>{j.deployment?.shortName || "–"}{j.deployment?.product && <span className="ml-1 text-xs text-slate-500">{j.deployment.product}</span>}</td><td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td></tr>)}</tbody>
|
||||
</table>
|
||||
{!upcoming.length && <p className="mt-2 text-sm text-slate-500">Nothing planned.</p>}
|
||||
{!upcoming.length && <p className="px-5 pb-5 text-sm text-slate-500">Nothing planned.</p>}
|
||||
<Pager {...upcomingPaged} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText, setToken } from "@/lib/api";
|
||||
import { fmtDate, rand, randFine } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { useServerPaged } from "@/lib/paging";
|
||||
import type { AiInstallUse } from "@/lib/types";
|
||||
import { Loading, Message, PageTitle, Pager, SearchInput, Tabs } from "@/components/ui";
|
||||
import { BillingSettings } from "@/components/billing/BillingSettings";
|
||||
@@ -173,8 +173,12 @@ export default function SettingsPage() {
|
||||
const [publicKey, setPublicKey] = useState("");
|
||||
const [smtp, setSmtp] = useState(false);
|
||||
const [aiModels, setAiModels] = useState<AiModel[]>([]);
|
||||
const [audit, setAudit] = useState<AuditRow[]>([]);
|
||||
const [auditQuery, setAuditQuery] = useState("");
|
||||
const [auditQ, setAuditQ] = useState("");
|
||||
useEffect(() => { const t = setTimeout(() => setAuditQ(auditQuery.trim()), 300); return () => clearTimeout(t); }, [auditQuery]);
|
||||
// Hub 2.6.0: paged on the server (every entry, not the last 300).
|
||||
const auditPaged = useServerPaged<AuditRow>("/api/admin/audit", { q: auditQ }, r => r.entries as AuditRow[], 30);
|
||||
const audit = auditPaged.rows ?? [];
|
||||
const [pw, setPw] = useState({ currentPassword: "", newPassword: "" });
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
const [smtpPass, setSmtpPass] = useState({ value: "", clear: false });
|
||||
@@ -183,14 +187,11 @@ export default function SettingsPage() {
|
||||
|
||||
useEffect(() => {
|
||||
api<{ settings: Settings; publicKey: string; smtp: boolean; aiModels: AiModel[] }>("/api/admin/settings").then(r => { setSettings(r.settings); setPublicKey(r.publicKey); setSmtp(r.smtp); setAiModels(r.aiModels || []); }).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
api<AuditRow[]>("/api/admin/audit").then(setAudit).catch(() => {});
|
||||
// Open the tab named in the address (#email), so a reload or a link lands in the same place.
|
||||
const fromHash = window.location.hash.slice(1);
|
||||
if (TABS.some(t => t.key === fromHash)) setTab(fromHash as Tab);
|
||||
}, []);
|
||||
|
||||
const auditShown = useMemo(() => audit.filter(a => matches(auditQuery, a.action.replace(/_/g, " "), a.actor?.name, a.target, a.metadata ? JSON.stringify(a.metadata) : "")), [audit, auditQuery]);
|
||||
const auditPaged = usePaged(auditShown, auditQuery, 30);
|
||||
|
||||
if (!settings) return msg ? <Message msg={msg} /> : <Loading />;
|
||||
|
||||
@@ -331,9 +332,9 @@ export default function SettingsPage() {
|
||||
<>
|
||||
<SearchInput className="mb-3 w-full sm:w-72" value={auditQuery} onChange={setAuditQuery} placeholder="Search who or what" />
|
||||
<div className="card p-0">
|
||||
{audit.length === 0 ? <p className="p-5 text-sm text-slate-500">Nothing yet.</p> : auditShown.length === 0 ? <p className="p-5 text-sm text-slate-500">Nothing matches.</p> : (
|
||||
{!auditPaged.rows ? <p className="p-5 text-sm text-slate-500">Loading…</p> : audit.length === 0 ? <p className="p-5 text-sm text-slate-500">{auditQ ? "Nothing matches." : "Nothing yet."}</p> : (
|
||||
<ul className="space-y-1 p-5 text-sm">
|
||||
{auditPaged.rows.map(a => (
|
||||
{audit.map(a => (
|
||||
<li key={a.id} className="flex flex-wrap gap-2">
|
||||
<span className="w-40 shrink-0 text-xs text-slate-500">{fmtDate(a.createdAt)}</span>
|
||||
<span className="font-medium">{a.actor?.name || "—"}</span>
|
||||
@@ -343,7 +344,7 @@ export default function SettingsPage() {
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<Pager {...auditPaged} />
|
||||
<Pager page={auditPaged.page} pages={auditPaged.pages} setPage={auditPaged.setPage} total={auditPaged.total} pageSize={auditPaged.pageSize} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -31,7 +31,7 @@ export type Job = {
|
||||
id: string; serverId: string; type: string; args: Record<string, unknown>; status: string; notBefore: string; expiresAt: string;
|
||||
scheduled: boolean; emergency: boolean; reason: string | null; batchId: string | null; deliveredAt: string | null; finishedAt: string | null;
|
||||
message: string | null; createdAt: string; deploymentId: string | null;
|
||||
server?: { id: string; name: string }; deployment?: { id: string; shortName: string; domain: string } | null;
|
||||
server?: { id: string; name: string }; deployment?: { id: string; shortName: string; domain: string; product?: string } | null;
|
||||
report?: { status: string; steps: { name: string; startedAt: string; finishedAt: string | null; outcome: string; detail?: string }[]; result: Record<string, unknown>; log: string[]; message?: string } | null;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
|
||||
/** True when every word of the query appears in one of the fields (case-insensitive). */
|
||||
export function matches(query: string, ...fields: (string | number | null | undefined)[]) {
|
||||
@@ -20,3 +21,29 @@ export function usePaged<T>(items: T[], resetKey: unknown, pageSize = 25) {
|
||||
const rows = useMemo(() => items.slice((current - 1) * pageSize, current * pageSize), [items, current, pageSize]);
|
||||
return { rows, page: current, pages, setPage, total: items.length, pageSize };
|
||||
}
|
||||
|
||||
/**
|
||||
* A list paged on the server (Hub 2.6.0: jobs, alerts, the audit log). `path` without paging;
|
||||
* `params` are the filters, and a change in them goes back to the first page. `pick` takes the
|
||||
* rows out of the answer. `reload()` fetches the same page again.
|
||||
*/
|
||||
export function useServerPaged<T>(path: string, params: Record<string, string>, pick: (r: Record<string, unknown>) => T[], pageSize = 50) {
|
||||
const [page, setPage] = useState(1);
|
||||
const [data, setData] = useState<{ rows: T[]; total: number; pages: number } | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [tick, setTick] = useState(0);
|
||||
const key = JSON.stringify(params);
|
||||
useEffect(() => { setPage(1); }, [key]);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
const q = new URLSearchParams({ ...Object.fromEntries(Object.entries(params).filter(([, v]) => v !== "")), page: String(page), pageSize: String(pageSize) });
|
||||
setError(null);
|
||||
api<Record<string, unknown> & { total: number; pages: number }>(`${path}?${q}`)
|
||||
.then(r => { if (alive) setData({ rows: pick(r), total: r.total, pages: r.pages }); })
|
||||
.catch(e => { if (alive) setError(errorText(e)); });
|
||||
return () => { alive = false; };
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- `key` stands for `params`; `pick` is a fixed accessor
|
||||
}, [path, key, page, pageSize, tick]);
|
||||
const reload = () => setTick(t => t + 1);
|
||||
return { rows: data?.rows ?? null, total: data?.total ?? 0, pages: data?.pages ?? 1, page, setPage, pageSize, error, reload };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user