- Release.product and requires; unique (product, version); latest version per product (latest_version stays Cross Events' latest) - Release sources per product (Releases page): repository, tag prefix, notes file. Defaults: every product from crosscode-platform plus Cross Events' v1.2.3 tags from hope-events. A product's releases are only removed when all its sources were read and found tags - "— requires accounts 1.2.0" in a notes heading: Request update answers 409 REQUIREMENT_NOT_MET until the church's install of that product is new enough; install page and Releases page show it; v2 replies carry requires - @crosscode/contracts 1.1.0 vendored (optional requires on releases) - Alerts, dashboard and install lists compare against each product's latest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
5.7 KiB
TypeScript
113 lines
5.7 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useMemo, 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 type { InstallSummary } from "@/lib/types";
|
|
import { PRODUCTS, PRODUCT_NAMES, type Product } from "@/lib/products";
|
|
import { Badge, Loading, PageTitle, Pager, SearchInput, Stat } from "@/components/ui";
|
|
|
|
type Dashboard = {
|
|
latestVersion: string | null;
|
|
latestVersions: Partial<Record<Product, string>>;
|
|
counts: { installs: number; healthy: number; warning: number; critical: number; behind: number; customers: number; openAlerts: number; licences: Record<string, number> };
|
|
installs: InstallSummary[];
|
|
};
|
|
|
|
type Health = "all" | InstallSummary["status"] | "behind";
|
|
const HEALTH: { key: Health; label: string }[] = [
|
|
{ key: "all", label: "All health" },
|
|
{ key: "critical", label: "Critical" },
|
|
{ key: "warning", label: "Warnings" },
|
|
{ key: "ok", label: "Healthy" },
|
|
{ key: "behind", label: "Behind latest" },
|
|
];
|
|
|
|
/** Every install at a glance: health, version, licence, last heartbeat. */
|
|
export default function OverviewPage() {
|
|
const [data, setData] = useState<Dashboard | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [query, setQuery] = useState("");
|
|
const [health, setHealth] = useState<Health>("all");
|
|
|
|
useEffect(() => {
|
|
const load = () => api<Dashboard>("/api/admin/dashboard").then(d => { setData(d); setError(null); }).catch(e => setError(errorText(e)));
|
|
load();
|
|
const t = setInterval(load, 60_000);
|
|
return () => clearInterval(t);
|
|
}, []);
|
|
|
|
const shown = useMemo(() => (data?.installs || []).filter(i =>
|
|
(health === "all" || (health === "behind" ? i.behind : i.status === health))
|
|
&& matches(query, i.customer?.name, i.name, i.url, i.version),
|
|
), [data, query, health]);
|
|
const paged = usePaged(shown, `${query}|${health}`);
|
|
|
|
if (error) return <p className="text-sm text-red-700">{error}</p>;
|
|
if (!data) return <Loading />;
|
|
const c = data.counts;
|
|
|
|
return (
|
|
<>
|
|
<PageTitle
|
|
title="Installs"
|
|
subtitle={PRODUCTS.some(p => data.latestVersions[p])
|
|
? `Latest releases: ${PRODUCTS.filter(p => data.latestVersions[p]).map(p => `${PRODUCT_NAMES[p]} ${data.latestVersions[p]}`).join(" · ")}`
|
|
: "Releases appear on the Releases page once they're tagged; then you can see who is behind."}
|
|
/>
|
|
<div className="mb-6 grid grid-cols-2 gap-3 md:grid-cols-5">
|
|
<Stat label="Installs" value={c.installs} />
|
|
<Stat label="Healthy" value={c.healthy} tone="green" />
|
|
<Stat label="Warnings" value={c.warning} tone={c.warning ? "amber" : undefined} />
|
|
<Stat label="Critical" value={c.critical} tone={c.critical ? "red" : undefined} />
|
|
<Stat label="Behind latest" value={c.behind} tone={c.behind ? "amber" : undefined} />
|
|
</div>
|
|
|
|
{data.installs.length === 0 ? (
|
|
<div className="card text-sm text-slate-600">
|
|
No installs yet. Add a <Link href="/customers" className="text-indigo-600 hover:underline">customer</Link>, generate a licence, and enter its key in the church's Cross Events setup.
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className="mb-3 flex flex-wrap gap-2">
|
|
<SearchInput className="w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search church, address or version" />
|
|
<select className="input w-auto" aria-label="Health" value={health} onChange={e => setHealth(e.target.value as Health)}>
|
|
{HEALTH.map(h => <option key={h.key} value={h.key}>{h.label}</option>)}
|
|
</select>
|
|
</div>
|
|
<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">Install</th><th className="p-3">Health</th><th className="p-3">Version</th><th className="p-3">Licence</th><th className="p-3">Last heartbeat</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
{paged.rows.length === 0 && <tr><td colSpan={5} className="p-3 text-slate-500">No installs match.</td></tr>}
|
|
{paged.rows.map(i => (
|
|
<tr key={i.id} className="border-t align-top hover:bg-slate-50">
|
|
<td className="p-3">
|
|
<Link href={`/installs/${i.id}`} className="font-medium text-indigo-700 hover:underline">{i.customer?.name || i.name}</Link>
|
|
<div className="text-xs text-slate-500">{PRODUCT_NAMES[i.product]} · {i.url}</div>
|
|
</td>
|
|
<td className="p-3">
|
|
<Badge value={i.status} />
|
|
{i.problems.filter(p => p.level !== "info").map(p => <div key={p.type} className="mt-1 text-xs text-slate-600">{p.message}</div>)}
|
|
</td>
|
|
<td className="p-3 whitespace-nowrap">{i.version || "—"}{i.behind && <span className="ml-1 text-xs text-amber-700">(latest {i.latestVersion})</span>}</td>
|
|
<td className="p-3 whitespace-nowrap">
|
|
{i.licence ? <><Badge value={i.licence.status} />{i.licence.expiresAt && <div className="mt-1 text-xs text-slate-500">to {fmtDate(i.licence.expiresAt, false)}</div>}</> : <span className="text-xs text-slate-400">none</span>}
|
|
</td>
|
|
<td className="p-3 whitespace-nowrap" title={fmtDate(i.lastHeartbeatAt)}>{ago(i.lastHeartbeatAt)}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
<Pager {...paged} />
|
|
</div>
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
}
|