SPB Git

Repository Public

page.tsx 6.4 KB 95 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/app/admin/(panel)/page.tsx9 * Module           : app10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import Link from "next/link";44import { NewAppForm, PolicyToggle, Section, SyncButton } from "@/components/admin/Panels";45import { recentAudit } from "@/lib/audit";46import { listPasskeys } from "@/lib/auth/webauthn";47import { listApps } from "@/lib/catalog";48import { totals } from "@/lib/downloads/metrics";49import { env } from "@/lib/env";50import { requireNotarization } from "@/lib/releases/pipeline";51import { allReleases } from "@/lib/releases/store";52import { recentRuns, syncHealth } from "@/lib/releases/sync";5354const when = (s: string | null) => (s ? s.slice(0, 16).replace("T", " ") + " UTC" : "—");5556export default function Dashboard() {57  const apps = listApps({ all: true }), releases = allReleases(), runs = recentRuns(8), health = syncHealth(env.syncIntervalMin), metrics = totals(), keys = listPasskeys();58  const pending = releases.filter((r) => r.state === "validated" || r.state === "held").length;59  const sum = (kind: string) => metrics.filter((m) => m.kind === kind).reduce((n, m) => n + m.n, 0);60  return (61    <div className="grid gap-6" data-testid="admin-dashboard">62      <h1 className="h2">Dashboard</h1>63      <dl className="grid grid-cols-2 gap-px overflow-hidden rounded-3xl border border-line bg-line lg:grid-cols-5">64        {([["Applications", apps.length], ["Published", apps.filter((a) => a.publish === "published").length], ["Awaiting approval", pending], ["Published images", releases.filter((r) => r.state === "published").length], ["Passkeys", keys.length]] as const).map(([l, n]) => (65          <div key={l} className="bg-surface p-5"><dd className="mono text-3xl font-semibold">{n}</dd><dt className="mt-1 text-sm text-ink2">{l}</dt></div>66        ))}67      </dl>6869      <Section title="Applications" aside={<NewAppForm />}>70        <table className="w-full text-left text-[0.93rem]"><thead className="text-ink3"><tr><th className="py-2 font-medium">Application</th><th className="font-medium">Status</th><th className="font-medium">State</th><th className="font-medium">Updated</th></tr></thead>71          <tbody>{apps.map((r) => (72            <tr key={r.slug} className="border-t border-line"><td className="py-3"><Link className="link font-semibold" href={`/admin/apps/${r.slug}`}>{r.app.name}</Link></td>73              <td><span className="status" data-s={r.app.status}>{r.app.status}</span></td><td><span className="tag">{r.publish}</span>{r.hasDraft && <span className="tag ml-1 !text-[var(--warn)]">draft</span>}</td><td className="mono text-ink3">{when(r.updatedAt)}</td></tr>74          ))}</tbody></table>75      </Section>7677      <Section title="Release synchronization" aside={<SyncButton />}>78        <p className={`text-[0.95rem] ${health.stale ? "text-[var(--warn)]" : "text-ink2"}`} data-testid="sync-health">Last successful run: {when(health.last)}{health.stale ? " — stale" : ""}. Schedule: every {env.syncIntervalMin} min. Webhook: {env.webhookSecret ? "enabled" : "disabled (no secret)"}.</p>79        <table className="mt-4 w-full text-left text-[0.88rem]"><thead className="text-ink3"><tr><th className="py-2 font-medium">Started</th><th className="font-medium">Trigger</th><th className="font-medium">Result</th><th className="font-medium">Detail</th></tr></thead>80          <tbody>{runs.map((r) => <tr key={r.id} className="border-t border-line align-top"><td className="mono py-2">{when(r.started_at)}</td><td>{r.trigger}</td><td style={{ color: r.ok ? "var(--ok)" : "var(--bad)" }}>{r.ok === null ? "running" : r.ok ? "ok" : "error"}</td><td className="mono break-all text-ink3">{r.error ?? r.summary}</td></tr>)}</tbody></table>81        <div className="mt-5 rule pt-5"><PolicyToggle value={requireNotarization()} /></div>82      </Section>8384      <Section title="Download counters">85        <p className="text-[0.9rem] text-ink2">Button presses: <b className="mono">{sum("click")}</b> · download requests: <b className="mono">{sum("request")}</b> · downloads sent in full: <b className="mono">{sum("completed")}</b>. None of these is an installation count.</p>86        {metrics.length > 0 && <table className="mt-4 w-full text-left text-[0.88rem]"><tbody>{metrics.map((m) => <tr key={`${m.slug}${m.version}${m.kind}`} className="border-t border-line"><td className="py-2">{m.slug}</td><td className="mono">{m.version}</td><td>{m.kind}</td><td className="mono text-right">{m.n}</td></tr>)}</tbody></table>}87      </Section>8889      <Section title="Audit trail">90        <ul className="grid max-h-96 gap-1 overflow-y-auto text-[0.85rem]">{recentAudit(80).map((a) => <li key={a.id} className="grid grid-cols-[11rem_6rem_1fr] gap-3 border-t border-line py-1.5"><span className="mono text-ink3">{when(a.at)}</span><span>{a.actor}</span><span><b>{a.action}</b> <span className="mono break-all text-ink3">{a.detail}</span></span></li>)}</ul>91      </Section>92    </div>93  );94}95
Files main
Menu

Theme