Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildAuditExportVM } from "@hivegrid/view-models";
|
||||
|
||||
import { AuditExportPage } from "./AuditExportPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const vm = buildAuditExportVM({ defaultFrom: "2026-06-06", defaultTo: "2026-07-06", maxRows: 50000 });
|
||||
|
||||
function renderPage(result: Parameters<typeof AuditExportPage>[0]["result"] = null) {
|
||||
return render(
|
||||
<Router>
|
||||
<AuditExportPage vm={vm} result={result} />
|
||||
</Router>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("AuditExportPage (interim-UI)", () => {
|
||||
it("renders the export form with purpose field and all three submit paths", () => {
|
||||
const { container } = renderPage();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.form"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.purpose"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.csv"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.pdf"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.storage"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the success panel with signed-URL download link", () => {
|
||||
const { container } = renderPage({ ok: true, url: "https://storage/x", rowCount: 12, integrityOk: true, expiresDays: 2 });
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.result"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.download"]')).toHaveAttribute("href", "https://storage/x");
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.error"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the plain-text error banner for a rejected export", () => {
|
||||
const { container, getByText } = renderPage({ ok: false, errorKey: "auditExport.storage.errorPurpose" });
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.error"]')).toBeInTheDocument();
|
||||
expect(getByText("settings:auditExport.storage.errorPurpose")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
// AK-P3 Interim-UI (AD-28) — Audit-Export preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built AuditExportVM plus the
|
||||
// normalized action result passed as props. Submits are plain HTML forms against
|
||||
// the hosting route (GET streams CSV/PDF, POST runs the storage export) — no
|
||||
// useLoaderData/useFetcher in here. Final Subframe optics land as a tracked
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AuditExportResultVM, AuditExportVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "../tasks/DateField";
|
||||
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
export type AuditExportPageProps = {
|
||||
vm: AuditExportVM;
|
||||
/** Normalized storage-export action result (null = nothing submitted yet). */
|
||||
result: AuditExportResultVM | null;
|
||||
};
|
||||
|
||||
export function AuditExportPage({ vm, result }: AuditExportPageProps) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export" />;
|
||||
}
|
||||
|
||||
const data = vm.data;
|
||||
const numberFormatter = new Intl.NumberFormat(i18n.language);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export">
|
||||
{/* Header: title + subtitle (0px rhythm) */}
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("translations:models.log.plural")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings:auditExport.descriptionAdmin", { maxRows: numberFormatter.format(data.maxRows) })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* One form, three submit paths: GET csv / GET pdf / POST storage export. */}
|
||||
<form method="get" className="flex flex-col gap-4" data-ui-id="ui.audit.export.form">
|
||||
<input type="hidden" name="export" value="csv" />
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<DateField label={t("settings:auditExport.filters.fromUtc")} name="from" defaultValue={data.defaultFrom} />
|
||||
<DateField label={t("settings:auditExport.filters.toUtc")} name="to" defaultValue={data.defaultTo} />
|
||||
<TextInput className="max-w-[240px]" label={t("settings:auditExport.filters.tenantIdOptional")} showLabel>
|
||||
<TextInput.Input name="tenantId" placeholder={t("settings:auditExport.filters.tenantIdPlaceholder")} />
|
||||
</TextInput>
|
||||
<SelectWithAny
|
||||
name="regulatoryScope"
|
||||
label={t("settings:auditExport.filters.regulatoryScope")}
|
||||
anyLabel={t("settings:auditExport.filters.any")}
|
||||
options={data.regulatoryScopeOptions.map((option) => ({ value: option.value, label: t(`settings:${option.labelKey}`) }))}
|
||||
/>
|
||||
<SelectWithAny
|
||||
name="actorType"
|
||||
label={t("settings:auditExport.filters.actorType")}
|
||||
anyLabel={t("settings:auditExport.filters.any")}
|
||||
options={data.actorTypeOptions.map((option) => ({ value: option.value, label: t(`settings:${option.labelKey}`) }))}
|
||||
/>
|
||||
<SelectWithAny
|
||||
name="outcome"
|
||||
label={t("settings:auditExport.filters.outcome")}
|
||||
anyLabel={t("settings:auditExport.filters.any")}
|
||||
options={data.outcomeOptions.map((option) => ({ value: option.value, label: t(`settings:${option.labelKey}`) }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
{/* Purpose is mandatory for the storage export (DoD 3) — message slot names the rule. */}
|
||||
<TextInput
|
||||
className="w-full max-w-[480px]"
|
||||
label={t("settings:auditExport.storage.purpose")}
|
||||
showLabel
|
||||
message={t("settings:auditExport.storage.purposePlaceholder")}
|
||||
>
|
||||
<TextInput.Input name="purpose" data-ui-id="ui.audit.export.purpose" />
|
||||
</TextInput>
|
||||
<Select name="format" label={t("settings:auditExport.storage.format")} showLabel defaultValue="csv" className="max-w-[200px]">
|
||||
{data.formatOptions.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{t(`settings:${option.labelKey}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" variant="secondary" data-ui-id="ui.audit.export.csv">
|
||||
{t("settings:auditExport.downloadCsv")}
|
||||
</Button>
|
||||
<Button type="submit" name="export" value="pdf" variant="secondary" data-ui-id="ui.audit.export.pdf">
|
||||
{t("settings:auditExport.downloadPdf")}
|
||||
</Button>
|
||||
<Button type="submit" formMethod="post" data-ui-id="ui.audit.export.storage">
|
||||
{t("settings:auditExport.storage.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<AuditExportResultPanel result={result} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectWithAny({
|
||||
name,
|
||||
label,
|
||||
anyLabel,
|
||||
options,
|
||||
}: {
|
||||
name: string;
|
||||
label: string;
|
||||
anyLabel: string;
|
||||
options: readonly { value: string; label: string }[];
|
||||
}) {
|
||||
// Native form Select: the FILTER_ALL sentinel maps to "no filter" server-side
|
||||
// (the route drops it before parsing filters).
|
||||
return (
|
||||
<Select name={name} label={label} showLabel defaultValue={FILTER_ALL} className="max-w-[200px]">
|
||||
<Select.Item value={FILTER_ALL}>{anyLabel}</Select.Item>
|
||||
{options.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
function AuditExportResultPanel({ result }: { result: AuditExportResultVM | null }) {
|
||||
const { t, i18n } = useTranslation(["settings"]);
|
||||
if (!result) return null;
|
||||
if (!result.ok) {
|
||||
return (
|
||||
<div data-ui-id="ui.audit.export.error">
|
||||
<Alert variant="error" title={t(`settings:${result.errorKey}`)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div data-ui-id="ui.audit.export.result">
|
||||
<Alert
|
||||
variant={result.integrityOk ? "success" : "warning"}
|
||||
title={t("settings:auditExport.storage.success", {
|
||||
rowCount: new Intl.NumberFormat(i18n.language).format(result.rowCount),
|
||||
days: result.expiresDays,
|
||||
})}
|
||||
description={
|
||||
<span className="flex flex-wrap items-center gap-2">
|
||||
<a href={result.url} rel="noreferrer" className="text-text-feedback-link-default underline" data-ui-id="ui.audit.export.download">
|
||||
{t("settings:auditExport.storage.downloadLink")}
|
||||
</a>
|
||||
{!result.integrityOk ? <span>{t("settings:auditExport.storage.integrityWarning")}</span> : null}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildAuditListVM, type AuditListFilterState, type AuditListInputRow, type AuditListPagination } from "@hivegrid/view-models";
|
||||
|
||||
import { AuditListPage } from "./AuditListPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const filter: AuditListFilterState = { from: null, to: null, actorType: null, action: null, outcome: null, targetType: null };
|
||||
const pagination: AuditListPagination = { page: 1, pageSize: 25, total: 2, totalPages: 1 };
|
||||
|
||||
function inputRow(overrides: Partial<AuditListInputRow> = {}): AuditListInputRow {
|
||||
return {
|
||||
id: "a1",
|
||||
createdAtIso: "2026-07-01T08:00:00.000Z",
|
||||
actorType: "user",
|
||||
actorEmail: "akeshan@example.com",
|
||||
actorId: "u1",
|
||||
action: "kontakt.updated",
|
||||
targetType: "Kontakt",
|
||||
targetId: "k1",
|
||||
outcome: "success",
|
||||
hasMetadata: false,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function buildVM(rows: AuditListInputRow[]) {
|
||||
return buildAuditListVM({ rows, filter, pagination, canExport: true });
|
||||
}
|
||||
|
||||
function renderPage(vm: ReturnType<typeof buildVM>, onApply = vi.fn()) {
|
||||
return render(
|
||||
<Router>
|
||||
<AuditListPage vm={vm} exportHref="/admin/audit-export" actions={{ onApply }} />
|
||||
</Router>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("AuditListPage (interim-UI)", () => {
|
||||
it("renders the list surface, filter bar, table rows and export CTA", () => {
|
||||
const { container } = renderPage(buildVM([inputRow(), inputRow({ id: "a2", actorType: "system", actorEmail: null, actorId: null })]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.filter"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.table"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="a1"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.export"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("prefers the persisted summary text over the derived key", () => {
|
||||
const { getByText } = renderPage(buildVM([inputRow({ summaryText: "Kontakt umbenannt" })]));
|
||||
expect(getByText("Kontakt umbenannt")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no rows", () => {
|
||||
const { container } = renderPage(buildVM([]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.empty"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens the detail drawer with a field-by-field diff and masked entries", () => {
|
||||
const { container } = renderPage(
|
||||
buildVM([
|
||||
inputRow({
|
||||
beforeDiff: { name: "Alt GmbH", apiKey: "[REDACTED]" },
|
||||
afterDiff: { name: "Neu GmbH", apiKey: "[REDACTED]" },
|
||||
summaryText: "Firma umbenannt",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
const detailButton = container.querySelector('[data-ui-id="ui.audit.list.detail"]');
|
||||
expect(detailButton).toBeInTheDocument();
|
||||
fireEvent.click(detailButton!);
|
||||
|
||||
// Drawer content can live in a portal — query the document.
|
||||
expect(document.querySelector('[data-ui-id="ui.audit.list.drawer"]')).toBeInTheDocument();
|
||||
expect(document.querySelector('[data-diff-field="name"]')).toBeInTheDocument();
|
||||
const masked = document.querySelector('[data-diff-field="apiKey"]');
|
||||
expect(masked).toHaveAttribute("data-diff-masked", "true");
|
||||
expect(masked?.textContent).not.toContain("[REDACTED]");
|
||||
});
|
||||
|
||||
it("hides the detail button for rows without diff or metadata", () => {
|
||||
const { container } = renderPage(buildVM([inputRow()]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.detail"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("navigates server-side when the filter form is applied", () => {
|
||||
const onApply = vi.fn();
|
||||
const { container } = renderPage(buildVM([inputRow()]), onApply);
|
||||
const form = container.querySelector('[data-ui-id="ui.audit.list.filter"]');
|
||||
fireEvent.submit(form!);
|
||||
expect(onApply).toHaveBeenCalledWith(expect.objectContaining({ page: 1 }));
|
||||
});
|
||||
});
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
// AK-P3 Interim-UI (AD-28) — Audit-Viewer preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built AuditListVM passed as
|
||||
// a prop and reports filter/page changes through injected actions (server-side
|
||||
// navigation). No useLoaderData, no server imports. The detail drawer shows the
|
||||
// persisted field-by-field diff (DoD 2) with masked entries rendered as a
|
||||
// "value changed" placeholder. Final Subframe optics land as a tracked
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AuditListFilterState, AuditListRow, AuditListVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Drawer } from "~/ui/components/Drawer";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "../tasks/DateField";
|
||||
|
||||
// Non-empty sentinel for the "any" option (empty string is not a valid Select value).
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
const ACTOR_TYPES = ["user", "admin", "api_key", "system", "plugin"] as const;
|
||||
const OUTCOMES = ["success", "failure", "blocked"] as const;
|
||||
|
||||
export type AuditListQuery = AuditListFilterState & { page: number };
|
||||
|
||||
export type AuditListActions = {
|
||||
/** Navigate (GET) to the same route with the given filter/page state. */
|
||||
onApply: (query: AuditListQuery) => void;
|
||||
};
|
||||
|
||||
export type AuditListPageProps = {
|
||||
vm: AuditListVM;
|
||||
/** Href of the export screen (shown when the VM allows exporting). */
|
||||
exportHref: string;
|
||||
actions: AuditListActions;
|
||||
};
|
||||
|
||||
function actorTypeKey(actorType: string): string {
|
||||
return actorType === "api_key" ? "apiKey" : actorType;
|
||||
}
|
||||
|
||||
export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
const [openRowId, setOpenRowId] = useState<string | null>(null);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.list" />;
|
||||
}
|
||||
|
||||
const { rows, filter, pagination, canExport, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
const openRow = openRowId ? (rows.find((row) => row.id === openRowId) ?? null) : null;
|
||||
|
||||
const actorLabel = (raw: string) => (raw.startsWith("audit.") ? t(`settings:${raw}`) : raw);
|
||||
const summaryLabel = (row: AuditListRow) =>
|
||||
row.summaryText ?? t(`settings:${row.summaryKey}`, { ...row.summaryParams, actor: actorLabel(row.summaryParams.actor ?? "") });
|
||||
|
||||
function apply(patch: Partial<AuditListQuery>) {
|
||||
actions.onApply({ ...filter, page: 1, ...patch });
|
||||
}
|
||||
|
||||
function applyFilterForm(form: HTMLFormElement) {
|
||||
const data = new FormData(form);
|
||||
const text = (name: string) => {
|
||||
const value = data.get(name);
|
||||
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
||||
};
|
||||
apply({
|
||||
from: text("from"),
|
||||
to: text("to"),
|
||||
action: text("action"),
|
||||
targetType: text("targetType"),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.list">
|
||||
{/* Header: title + subtitle (0px rhythm) + export CTA */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("settings:audit.viewer.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings:audit.viewer.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canExport ? (
|
||||
<a href={exportHref} className="no-underline" data-ui-id="ui.audit.list.export">
|
||||
<Button variant="secondary">{t("settings:audit.viewer.exportLink")}</Button>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Filter bar: text/date fields submit via the apply button; selects navigate on change */}
|
||||
<form
|
||||
className="flex flex-wrap items-end gap-4"
|
||||
data-ui-id="ui.audit.list.filter"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
applyFilterForm(event.currentTarget);
|
||||
}}
|
||||
>
|
||||
<DateField label={t("settings:auditExport.filters.fromUtc")} name="from" defaultValue={filter.from ?? ""} />
|
||||
<DateField label={t("settings:auditExport.filters.toUtc")} name="to" defaultValue={filter.to ?? ""} />
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings:auditExport.filters.actorType")}
|
||||
showLabel
|
||||
value={filter.actorType ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => apply({ actorType: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings:auditExport.filters.any")}</Select.Item>
|
||||
{ACTOR_TYPES.map((actorType) => (
|
||||
<Select.Item key={actorType} value={actorType}>
|
||||
{t(`settings:auditExport.actorTypes.${actorTypeKey(actorType)}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings:auditExport.filters.outcome")}
|
||||
showLabel
|
||||
value={filter.outcome ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => apply({ outcome: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings:auditExport.filters.any")}</Select.Item>
|
||||
{OUTCOMES.map((outcome) => (
|
||||
<Select.Item key={outcome} value={outcome}>
|
||||
{t(`settings:auditExport.outcomes.${outcome}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput className="max-w-[220px]" label={t("settings:audit.viewer.filters.action")} showLabel>
|
||||
<TextInput.Input name="action" defaultValue={filter.action ?? ""} placeholder={t("settings:audit.viewer.filters.actionPlaceholder")} />
|
||||
</TextInput>
|
||||
<TextInput className="max-w-[200px]" label={t("settings:audit.viewer.filters.targetType")} showLabel>
|
||||
<TextInput.Input name="targetType" defaultValue={filter.targetType ?? ""} />
|
||||
</TextInput>
|
||||
<Button type="submit" data-ui-id="ui.audit.list.filter.apply">
|
||||
{t("settings:audit.viewer.applyFilters")}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.audit.list.empty">
|
||||
<EmptyState title={t(`settings:${emptyHeadlineKey}`)} body={t(`settings:${emptyBodyKey}`)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.audit.list.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.time")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.actor")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.action")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.subject")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.outcome")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.summary")}</Table.HeaderCell>
|
||||
<Table.HeaderCell />
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{dateTimeFormatter.format(new Date(row.createdAtIso))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-2">
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t(`settings:${row.actorKindLabelKey}`)}
|
||||
</Tag_Label>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{actorLabel(row.actorLabel)}
|
||||
</span>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="font-mono text-body-default-regular-0 text-text-neutral-secondary">{row.action}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.targetType ? `${row.targetType}${row.targetId ? ` #${row.targetId}` : ""}` : t("settings:audit.viewer.drawer.emptyValue")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(`settings:auditExport.outcomes.${row.outcome}`, row.outcome)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{summaryLabel(row)}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{row.hasDetail ? (
|
||||
<Button variant="tertiary" size="small" onClick={() => setOpenRowId(row.id)} data-ui-id="ui.audit.list.detail">
|
||||
{t("settings:audit.viewer.detailButton")}
|
||||
</Button>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Server-side pagination */}
|
||||
<div className="flex items-center justify-between" data-ui-id="ui.audit.list.pagination">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t("settings:audit.viewer.pageInfo", {
|
||||
page: pagination.page,
|
||||
totalPages: pagination.totalPages,
|
||||
total: new Intl.NumberFormat(i18n.language).format(pagination.total),
|
||||
})}
|
||||
</span>
|
||||
<div className="flex gap-2">
|
||||
{pagination.page > 1 ? (
|
||||
<Button variant="tertiary" onClick={() => apply({ page: pagination.page - 1 })}>
|
||||
{t("settings:audit.viewer.prev")}
|
||||
</Button>
|
||||
) : null}
|
||||
{pagination.page < pagination.totalPages ? (
|
||||
<Button variant="tertiary" onClick={() => apply({ page: pagination.page + 1 })}>
|
||||
{t("settings:audit.viewer.next")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AuditDetailDrawer row={openRow} onClose={() => setOpenRowId(null)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AuditDetailDrawer({ row, onClose }: { row: AuditListRow | null; onClose: () => void }) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
|
||||
return (
|
||||
<Drawer open={row !== null} onOpenChange={(open: boolean) => (open ? undefined : onClose())}>
|
||||
<Drawer.Content>
|
||||
{row ? (
|
||||
<div className="flex w-96 max-w-full flex-col gap-6 p-6" data-ui-id="ui.audit.list.drawer">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings:audit.viewer.drawer.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{dateTimeFormatter.format(new Date(row.createdAtIso))} · {row.action}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{row.summaryText ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary">{row.summaryText}</span>
|
||||
) : null}
|
||||
|
||||
{row.diff.length > 0 ? (
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.audit.list.drawer.diff">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings:audit.viewer.drawer.diffTitle")}
|
||||
</span>
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.drawer.field")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.drawer.before")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.drawer.after")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{row.diff.map((entry) => (
|
||||
<Table.Row key={entry.field} data-diff-field={entry.field} data-diff-masked={entry.masked}>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{entry.field}</span>
|
||||
</Table.Cell>
|
||||
{entry.masked ? (
|
||||
<Table.Cell colSpan={2}>
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t("settings:audit.viewer.drawer.masked")}
|
||||
</Tag_Label>
|
||||
</Table.Cell>
|
||||
) : (
|
||||
<>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{entry.before ?? t("settings:audit.viewer.drawer.emptyValue")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{entry.after ?? t("settings:audit.viewer.drawer.emptyValue")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</>
|
||||
)}
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{row.metadataJson ? (
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.audit.list.drawer.metadata">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings:audit.viewer.drawer.metadataTitle")}
|
||||
</span>
|
||||
<pre className="max-h-80 w-full overflow-auto rounded-[4px] border border-solid border-border-default p-3 font-mono text-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.metadataJson}
|
||||
</pre>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{row.diff.length === 0 && !row.metadataJson ? (
|
||||
<Alert variant="neutral" title={t("settings:audit.viewer.drawer.empty")} />
|
||||
) : null}
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="secondary" onClick={onClose} data-ui-id="ui.audit.list.drawer.close">
|
||||
{t("settings:audit.viewer.drawer.close")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</Drawer.Content>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user