Show real target names in the Audit Log instead of type #id
The Target column only ever printed "<type> #<id>", so newly created integrations (and other records) appeared as "integration 1", "integration 2", etc. instead of the display name set in the form. Audit entries already log the name in their detail JSON on create/update/delete; parse it and show it when present. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e064b1caf7
commit
3a53a86ce0
1 file changed
+17
-3
@@ -1,6 +1,22 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { api, type AuditLogEntry } from "../api/client";
|
import { api, type AuditLogEntry } from "../api/client";
|
||||||
|
|
||||||
|
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}` : ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
export default function AuditLog() {
|
export default function AuditLog() {
|
||||||
const [entries, setEntries] = useState<AuditLogEntry[] | null>(null);
|
const [entries, setEntries] = useState<AuditLogEntry[] | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -37,9 +53,7 @@ export default function AuditLog() {
|
|||||||
<span className="badge bg-blue-lt">{e.category}</span>
|
<span className="badge bg-blue-lt">{e.category}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>{e.action}</td>
|
<td>{e.action}</td>
|
||||||
<td>
|
<td>{targetLabel(e)}</td>
|
||||||
{e.targetType ? `${e.targetType}${e.targetId ? ` #${e.targetId}` : ""}` : "—"}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{entries?.length === 0 && (
|
{entries?.length === 0 && (
|
||||||
|
|||||||
Reference in new issue
Block a user