import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api, type AppVersions, type CurrentUser } from "../api/client"; import EmptyState from "../components/EmptyState"; import TimeAgo from "../components/TimeAgo"; import { BlockSkeleton } from "../components/Skeleton"; import { ErrorNotice } from "../components/Notice"; import { readableError } from "../utils/errors"; import { toast } from "../utils/toast"; type Row = AppVersions["rows"][number]; const LAG: Record = { same: { text: "Up to date", badge: "bg-green-lt text-green" }, patch: { text: "A patch behind", badge: "bg-blue-lt text-blue" }, minor: { text: "A minor update behind", badge: "bg-yellow-lt text-yellow" }, major: { text: "A major version behind", badge: "bg-red-lt text-red" }, ahead: { text: "Ahead of the newest release", badge: "bg-secondary-lt text-secondary" }, unknown: { text: "Not compared", badge: "bg-secondary-lt text-secondary" }, }; const ORDER: Record = { major: 0, minor: 1, patch: 2, unknown: 3, ahead: 4, same: 5 }; /** What each connected application runs, against the newest release of it — the lookup is switched on here, and is the only thing this app asks of an address of its own choosing. */ export default function Versions({ user }: { user: CurrentUser }) { const isAdmin = user.role === "admin"; const [data, setData] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [days, setDays] = useState("0"); const adopt = (d: AppVersions) => { setData(d); setDays(String(d.alertAfterDays)); setError(null); }; useEffect(() => { api.versions .get() .then(adopt) .catch((err) => setError(readableError(err))); }, []); async function save(enabled: boolean, alertAfterDays: number) { setBusy(true); try { adopt(await api.versions.save({ enabled, alertAfterDays })); toast.success(enabled ? "Saved." : "Switched off."); } catch (err) { toast.error(readableError(err)); } finally { setBusy(false); } } async function refresh() { setBusy(true); try { const r = await api.versions.refresh(); adopt(r); toast[r.result.failed > 0 ? "error" : "success"](r.result.failed > 0 ? `${r.result.failed} could not be looked up — see the list.` : `Looked up ${r.result.checked}.`); } catch (err) { toast.error(readableError(err)); } finally { setBusy(false); } } const rows = [...(data?.rows ?? [])].sort((a, b) => ORDER[a.lag] - ORDER[b.lag] || a.label.localeCompare(b.label)); const behind = rows.filter((r) => r.lag === "patch" || r.lag === "minor" || r.lag === "major").length; return ( <>

App versions

The version each connected application runs — as it was last read (see Integrations) — against the newest release of it. It looks the newest ones up on GitHub once a day; that is the only thing this app asks of an address that is not yours, so it is switched off until you switch it on. Proxmox, Synology and the rest, which have no release to compare with, are not listed.

{!data && !error && } {data && ( <>
setDays(e.target.value.replace(/[^0-9]/g, ""))} onBlur={() => Number(days) !== data.alertAfterDays && void save(data.enabled, Math.min(365, Number(days) || 0))} /> days (0 = never) {isAdmin && data.enabled && ( )}
{data.enabled ? (data.lastCheckedAt ? <>Last looked up . : "Not looked up yet — it is done a few minutes after it is switched on.") : "Switched off."} A warning is raised under Alerts only with a number of days above 0.
{rows.length === 0 ? (
) : (

{rows.length} {rows.length === 1 ? "application" : "applications"} {data.enabled ? `, ${behind === 0 ? "none behind" : `${behind} behind`}` : ""}

{rows.map((r) => ( ))}
Application Running Newest release Compared
{r.label}
{r.name}
{r.running} {r.latest ? ( <> {r.latest.url ? ( {r.latest.tag} ) : ( {r.latest.tag} )} {r.latest.publishedAt && (
out
)} ) : ( {data.enabled ? "not known yet" : "—"} )} {r.lookupError &&
{r.lookupError}
}
{LAG[r.lag].text} {r.daysOut !== null &&
{r.daysOut === 0 ? "a newer one came out today" : r.daysOut === 1 ? "a newer one has been out a day" : `a newer one has been out ${r.daysOut} days`}
}
)} )} ); }