Fold four pages into the pages they belong to; add a Backups menu group
Dependencies become a view of the Map (graph with the editor under it), Sessions the 'Signed in now' tab of Users, the Audit Log the 'Raw audit log' tab of the Change log, and the Diagnostic Log the 'Call log' tab of Integrations (admins). Backup coverage and Proxmox Backup move to a new Backups group. Old addresses redirect; a shared ViewTabs component does the tabs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e0c6927b2
commit
1432b148e9
19 files changed
+177
-102
No files matched your search
@@ -0,0 +1,122 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type AuditLogEntry } from "../api/client";
|
||||
import { formatDateTime, parseDbTimestamp } from "../utils/date";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import { usePagination } from "../hooks/usePagination";
|
||||
import Pagination from "../components/Pagination";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { SearchBox } from "../components/TableToolbar";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
||||
|
||||
function targetLabel(e: AuditLogEntry): string {
|
||||
if (!e.targetType) return "—";
|
||||
let detail: Record<string, unknown> | null = null;
|
||||
if (e.detail) {
|
||||
try {
|
||||
detail = JSON.parse(e.detail);
|
||||
} catch {
|
||||
detail = null;
|
||||
}
|
||||
}
|
||||
const name = detail?.name ?? detail?.targetLabel ?? detail?.ipAddress;
|
||||
const typeLabel = e.targetType.replace(/_/g, " ");
|
||||
if (typeof name === "string" && name) return `${typeLabel} "${name}"`;
|
||||
return `${typeLabel}${e.targetId ? ` #${e.targetId}` : ""}`;
|
||||
}
|
||||
|
||||
/** What was done, beyond the target — the link's label and URL, a scan's address and range, and so on. The name is already in the Target column. */
|
||||
function detailSummary(e: AuditLogEntry): string {
|
||||
if (!e.detail) return "";
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(e.detail);
|
||||
} catch {
|
||||
return e.detail;
|
||||
}
|
||||
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return String(parsed);
|
||||
return Object.entries(parsed as Record<string, unknown>)
|
||||
.filter(([key, value]) => key !== "name" && value !== null && value !== undefined && value !== "" && !(Array.isArray(value) && value.length === 0))
|
||||
.map(([key, value]) => `${key}: ${typeof value === "object" ? JSON.stringify(value) : String(value)}`)
|
||||
.join(" · ");
|
||||
}
|
||||
|
||||
/** The raw audit table — the "Raw audit log" side of the Change log page. */
|
||||
export default function AuditLogView() {
|
||||
const [entries, setEntries] = useState<AuditLogEntry[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api.auditLog
|
||||
.list()
|
||||
.then((res) => setEntries(res.entries))
|
||||
.catch((err) => setError(String(err)));
|
||||
}, []);
|
||||
|
||||
const tableSearch = useTableSearch(entries);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "createdAt", "desc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
downloadCsv(
|
||||
"audit-log.csv",
|
||||
["When", "Actor", "Category", "Action", "Target", "Details"],
|
||||
sorted.map((e) => [formatDateTime(parseDbTimestamp(e.createdAt)), e.actorLabel ?? "", e.category, e.action, targetLabel(e), detailSummary(e)]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<div className="text-secondary">The table behind the change log: every change made in the app, every sign-in and sign-out, with who did it and from where.</div>
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={exportCsv} disabled={!sorted || sorted.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<SearchBox value={tableSearch.query} onChange={tableSearch.setQuery} />
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<AuditLogEntry> label="When" sortKeyName="createdAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Actor" sortKeyName="actorLabel" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Category" sortKeyName="category" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Action" sortKeyName="action" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Target" sortKeyName="targetType" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<th>Details</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pageItems?.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td>{formatDateTime(parseDbTimestamp(e.createdAt))}</td>
|
||||
<td>{e.actorLabel ?? "—"}</td>
|
||||
<td>
|
||||
<span className="badge bg-blue-lt">{e.category}</span>
|
||||
</td>
|
||||
<td>{e.action}</td>
|
||||
<td>{targetLabel(e)}</td>
|
||||
<td className="text-secondary small text-break" style={{ maxWidth: 420 }}>
|
||||
{detailSummary(e) || "—"}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{entries === null && <LoadingRow colSpan={6} />}
|
||||
{sorted?.length === 0 && (
|
||||
<EmptyRow colSpan={6} title="Nothing recorded yet" hint="Changes people make in the app, sign-ins and the app's own housekeeping are written here as they happen." filtered={tableSearch.active ? () => tableSearch.setQuery("") : undefined} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Pagination page={page} pageCount={pageCount} totalCount={totalCount} onPageChange={setPage} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user