Search and paging on lists, Settings in tabs, pinned sidebar (1.3.0)
- Installs, Customers, Alerts and the audit log get a search box and 25-per-page paging (Installs also a health filter); install History pages too. - Settings is split into Releases and alerts / Email / Login and security / Audit log tabs, remembered in the URL hash. - The side navigation is sticky at window height, so Sign out no longer scrolls off long pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { api, errorText, setToken } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { Loading, Message, PageTitle, Pager, SearchInput, Tabs } from "@/components/ui";
|
||||
|
||||
type Settings = Record<string, string>;
|
||||
type AuditRow = { id: string; action: string; target: string | null; metadata: unknown; createdAt: string; actor: { name: string } | null };
|
||||
@@ -19,11 +20,21 @@ const FIELDS: { key: string; label: string; hint: string; type?: string }[] = [
|
||||
{ key: "licence_expiry_warning_days", label: "Warn about licence expiry (days before)", hint: "Default 14.", type: "number" },
|
||||
];
|
||||
|
||||
type Tab = "alerts" | "email" | "security" | "audit";
|
||||
const TABS: { key: Tab; label: string }[] = [
|
||||
{ key: "alerts", label: "Releases and alerts" },
|
||||
{ key: "email", label: "Email" },
|
||||
{ key: "security", label: "Login and security" },
|
||||
{ key: "audit", label: "Audit log" },
|
||||
];
|
||||
|
||||
export default function SettingsPage() {
|
||||
const [tab, setTab] = useState<Tab>("alerts");
|
||||
const [settings, setSettings] = useState<Settings | null>(null);
|
||||
const [publicKey, setPublicKey] = useState("");
|
||||
const [smtp, setSmtp] = useState(false);
|
||||
const [audit, setAudit] = useState<AuditRow[]>([]);
|
||||
const [auditQuery, setAuditQuery] = useState("");
|
||||
const [pw, setPw] = useState({ currentPassword: "", newPassword: "" });
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
const [smtpPass, setSmtpPass] = useState({ value: "", clear: false });
|
||||
@@ -33,10 +44,22 @@ export default function SettingsPage() {
|
||||
useEffect(() => {
|
||||
api<{ settings: Settings; publicKey: string; smtp: boolean }>("/api/admin/settings").then(r => { setSettings(r.settings); setPublicKey(r.publicKey); setSmtp(r.smtp); }).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 />;
|
||||
|
||||
const openTab = (t: Tab) => {
|
||||
setTab(t);
|
||||
setMsg(null);
|
||||
window.history.replaceState(null, "", `#${t}`);
|
||||
};
|
||||
|
||||
const save = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
@@ -93,23 +116,25 @@ export default function SettingsPage() {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title="Settings" />
|
||||
<div className="mb-4"><Message msg={msg} /></div>
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
<form onSubmit={save} className="card space-y-4">
|
||||
<h2 className="font-semibold">Releases and alerts</h2>
|
||||
{FIELDS.map(f => (
|
||||
<div key={f.key}>
|
||||
<label className="label" htmlFor={f.key}>{f.label}</label>
|
||||
<input id={f.key} className="input" type={f.type || "text"} value={settings[f.key] ?? ""} onChange={e => setSettings({ ...settings, [f.key]: e.target.value })} />
|
||||
<p className="mt-1 text-xs text-slate-500">{f.hint}</p>
|
||||
</div>
|
||||
))}
|
||||
<button className="btn-primary">Save settings</button>
|
||||
</form>
|
||||
<Tabs tabs={TABS} active={tab} onChange={openTab} />
|
||||
{msg && <div className="mb-4"><Message msg={msg} /></div>}
|
||||
|
||||
<div className="space-y-6">
|
||||
<form onSubmit={saveSmtp} className="card space-y-3">
|
||||
<h2 className="font-semibold">Email (SMTP)</h2>
|
||||
<div role="tabpanel" id={`panel-${tab}`} aria-labelledby={`tab-${tab}`}>
|
||||
{tab === "alerts" && (
|
||||
<form onSubmit={save} className="card max-w-2xl space-y-4">
|
||||
{FIELDS.map(f => (
|
||||
<div key={f.key}>
|
||||
<label className="label" htmlFor={f.key}>{f.label}</label>
|
||||
<input id={f.key} className="input" type={f.type || "text"} value={settings[f.key] ?? ""} onChange={e => setSettings({ ...settings, [f.key]: e.target.value })} />
|
||||
<p className="mt-1 text-xs text-slate-500">{f.hint}</p>
|
||||
</div>
|
||||
))}
|
||||
<button className="btn-primary">Save settings</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{tab === "email" && (
|
||||
<form onSubmit={saveSmtp} className="card max-w-2xl space-y-3">
|
||||
<p className="text-sm text-slate-600">The mail server alert emails are sent through. The password is stored encrypted.</p>
|
||||
{!smtp && <p className="rounded-lg bg-amber-50 p-3 text-sm text-amber-900">Email isn't set up, so alerts are only logged.</p>}
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
@@ -136,38 +161,47 @@ export default function SettingsPage() {
|
||||
<p className="mt-1 text-xs text-slate-500">Tries what's in the form, saved or not. Blank sends to the alert email.</p>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<div className="card space-y-2">
|
||||
<h2 className="font-semibold">Licence signing key</h2>
|
||||
<p className="text-sm text-slate-600">Installs check licences with this public key (built into Cross Events: <code>backend/src/hub/publicKey.js</code>). The private key stays on this server only — keep a backup.</p>
|
||||
<pre className="overflow-x-auto rounded-lg bg-slate-50 p-3 text-xs">{publicKey}</pre>
|
||||
</div>
|
||||
{tab === "security" && (
|
||||
<div className="max-w-2xl space-y-6">
|
||||
<form onSubmit={changePassword} className="card space-y-3">
|
||||
<h2 className="font-semibold">Your login</h2>
|
||||
<div><label className="label" htmlFor="current_password">Current password</label><input id="current_password" type="password" className="input" autoComplete="current-password" value={pw.currentPassword} onChange={e => setPw({ ...pw, currentPassword: e.target.value })} required /></div>
|
||||
<div><label className="label" htmlFor="new_password">New password (12+ characters)</label><input id="new_password" type="password" className="input" autoComplete="new-password" minLength={12} value={pw.newPassword} onChange={e => setPw({ ...pw, newPassword: e.target.value })} required /></div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button className="btn-secondary">Change password</button>
|
||||
<button type="button" className="btn-danger" onClick={signOutEverywhere}>Sign out everywhere</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form onSubmit={changePassword} className="card space-y-3">
|
||||
<h2 className="font-semibold">Your login</h2>
|
||||
<div><label className="label">Current password</label><input type="password" className="input" autoComplete="current-password" value={pw.currentPassword} onChange={e => setPw({ ...pw, currentPassword: e.target.value })} required /></div>
|
||||
<div><label className="label">New password (12+ characters)</label><input type="password" className="input" autoComplete="new-password" minLength={12} value={pw.newPassword} onChange={e => setPw({ ...pw, newPassword: e.target.value })} required /></div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button className="btn-secondary">Change password</button>
|
||||
<button type="button" className="btn-danger" onClick={signOutEverywhere}>Sign out everywhere</button>
|
||||
<div className="card space-y-2">
|
||||
<h2 className="font-semibold">Licence signing key</h2>
|
||||
<p className="text-sm text-slate-600">Installs check licences with this public key (built into Cross Events: <code>backend/src/hub/publicKey.js</code>). The private key stays on this server only — keep a backup.</p>
|
||||
<pre className="overflow-x-auto rounded-lg bg-slate-50 p-3 text-xs">{publicKey}</pre>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card mt-6">
|
||||
<h2 className="mb-3 font-semibold">Audit log</h2>
|
||||
{audit.length === 0 ? <p className="text-sm text-slate-500">Nothing yet.</p> : (
|
||||
<ul className="space-y-1 text-sm">
|
||||
{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>
|
||||
<span>{a.action.replace(/_/g, " ")}</span>
|
||||
{a.metadata ? <span className="text-xs text-slate-400 break-all">{JSON.stringify(a.metadata)}</span> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{tab === "audit" && (
|
||||
<>
|
||||
<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> : (
|
||||
<ul className="space-y-1 p-5 text-sm">
|
||||
{auditPaged.rows.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>
|
||||
<span>{a.action.replace(/_/g, " ")}</span>
|
||||
{a.metadata ? <span className="text-xs text-slate-400 break-all">{JSON.stringify(a.metadata)}</span> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<Pager {...auditPaged} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user