Render audit events as readable labels instead of raw codes

This commit is contained in:
ZacharyZhang-NY committed 2026-05-28 22:43:33 -04:00
1 parent da14be3443
commit 1cda873cb5
4 files changed
+17 -7

No files matched your search

@@ -10,7 +10,7 @@ import type {
ChatThreadRecord,
FileObjectRecord,
} from "../../../../shared/domain";
import { formatTime } from "../types";
import { auditEventLabel, formatTime } from "../types";
import { ChatMessageRow } from "./ChatMessageRow";
import { senderName, type MessageContext } from "./chat-helpers";
@@ -241,7 +241,7 @@ function AuditReplay({ events }: { events: AuditEventRecord[] }) {
>
<span className="mono" style={{ fontSize: 11, color: "var(--text-3)", flexShrink: 0 }}>{formatTime(event.createdAt)}</span>
<span style={{ fontSize: 12, color: "var(--text-1)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
{event.entityType}.{event.action}
{auditEventLabel(event.entityType, event.action)}
</span>
</div>
))}
@@ -1,6 +1,6 @@
import { Avatar, Pill } from "../../shared/ui";
import type { AuditEventRecord, EmployeeRecord } from "../../../../shared/domain";
import { formatRelative } from "../types";
import { formatRelative, humanizeToken } from "../types";
export function ProfilePanel({ employee }: { employee: EmployeeRecord }) {
return (
@@ -43,7 +43,7 @@ export function NotificationsPanel({ events, employee }: { events: AuditEventRec
style={{ padding: "12px 18px", borderBottom: index === visible.length - 1 ? "none" : "1px solid var(--border-soft)" }}
>
<Pill>{event.entityType.replaceAll("_", " ")}</Pill>
<span style={{ flex: 1, fontWeight: 480, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{event.action}</span>
<span style={{ flex: 1, fontWeight: 480, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{humanizeToken(event.action)}</span>
<span style={{ color: "var(--text-3)", fontSize: 12 }}>{formatRelative(event.createdAt)}</span>
</div>
))}
@@ -68,7 +68,7 @@ export function SecurityPanel({ events }: { events: AuditEventRecord[] }) {
style={{ padding: "12px 18px", borderBottom: index === security.length - 1 ? "none" : "1px solid var(--border-soft)" }}
>
<Pill tone="amber">{event.entityType.replaceAll("_", " ")}</Pill>
<span style={{ flex: 1, fontWeight: 480, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{event.action}</span>
<span style={{ flex: 1, fontWeight: 480, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{humanizeToken(event.action)}</span>
<span style={{ color: "var(--text-3)", fontSize: 12 }}>{formatRelative(event.createdAt)}</span>
</div>
))}
@@ -46,6 +46,16 @@ export function formatTime(iso: string): string {
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12: false });
}
export function humanizeToken(value: string): string {
const spaced = value.replace(/_/g, " ").trim();
if (!spaced) return spaced;
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
}
export function auditEventLabel(entityType: string, action: string): string {
return `${humanizeToken(entityType)} ${action.replace(/_/g, " ")}`.trim();
}
export function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
+2 -2
View File
@@ -90,8 +90,8 @@ test("onboards, hires, and creates work in the Electron shell", async () => {
await expect(page.getByText("/escalate").first()).toBeVisible();
await page.getByRole("button", { name: "Open thread" }).first().click();
await expect(page.getByText("Audit")).toBeVisible();
await expect(page.getByText("chat_message.sent").first()).toBeVisible();
await expect(page.getByText("approval.requested").first()).toBeVisible();
await expect(page.getByText("Chat message sent").first()).toBeVisible();
await expect(page.getByText("Approval requested").first()).toBeVisible();
await page.getByRole("button", { name: "Approvals" }).click();
await expect(page.getByText("Escalate release").first()).toBeVisible();