Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+4
@@ -29,6 +29,10 @@ describe("AuditExportPage (interim-UI)", () => {
|
||||
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();
|
||||
expect(container.querySelector('input[type="hidden"][name="export"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.csv"]')).toHaveAttribute("name", "export");
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.csv"]')).toHaveAttribute("value", "csv");
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.pdf"]')).toHaveAttribute("value", "pdf");
|
||||
});
|
||||
|
||||
it("renders the success panel with signed-URL download link", () => {
|
||||
|
||||
+139
-68
@@ -6,8 +6,13 @@
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArchive, FeatherDownload } from "@subframe/core";
|
||||
import type { AuditExportResultVM, AuditExportVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Loader } from "~/ui/components/Loader";
|
||||
import { PageIntro } from "../shared/PageShell";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
@@ -19,14 +24,48 @@ export type AuditExportPageProps = {
|
||||
vm: AuditExportVM;
|
||||
/** Normalized storage-export action result (null = nothing submitted yet). */
|
||||
result: AuditExportResultVM | null;
|
||||
/**
|
||||
* AK-SET-01: the tenant variant is tenantId-locked and has no storage export —
|
||||
* it streams CSV/PDF only. Admin keeps the full surface.
|
||||
*/
|
||||
scope?: "admin" | "tenant";
|
||||
/** Tenant slug for the tenant-scoped description. */
|
||||
tenantSlug?: string;
|
||||
/** Inside the Compliance hub (AK-SET-01) the hub owns the header. */
|
||||
embedded?: boolean;
|
||||
};
|
||||
|
||||
export function AuditExportPage({ vm, result }: AuditExportPageProps) {
|
||||
export function AuditExportPage({ vm, result, scope = "admin", tenantSlug, embedded = false }: AuditExportPageProps) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
const isTenant = scope === "tenant";
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
// Loading / not-ready: a bare marker div left the user with a blank page, so
|
||||
// the states are spelled out (DoD E23/E24).
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export">
|
||||
<Card>
|
||||
<div className="flex w-full items-center gap-3" data-ui-id="ui.audit.export.loading">
|
||||
<Loader />
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("settings:auditExport.loading")}</span>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (vm.status === "error") {
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export">
|
||||
<EmptyState outlined variant="error" title={t("settings:auditExport.error.title")} body={t(vm.error.messageKey)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export" />;
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export">
|
||||
<EmptyState outlined title={t("settings:auditExport.empty.title")} body={t("settings:auditExport.empty.body")} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const data = vm.data;
|
||||
@@ -34,73 +73,103 @@ export function AuditExportPage({ vm, result }: AuditExportPageProps) {
|
||||
|
||||
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}`) }))}
|
||||
/>
|
||||
{/* Header: the hub supplies it when embedded, otherwise it stays here. */}
|
||||
{embedded ? (
|
||||
<PageIntro uiId="ui.audit.export.intro">
|
||||
{isTenant
|
||||
? t("settings:auditExport.description", { tenantSlug: tenantSlug ?? "", maxRows: numberFormatter.format(data.maxRows) })
|
||||
: t("settings:auditExport.descriptionAdmin", { maxRows: numberFormatter.format(data.maxRows) })}
|
||||
</PageIntro>
|
||||
) : (
|
||||
<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">
|
||||
{isTenant
|
||||
? t("settings:auditExport.description", { tenantSlug: tenantSlug ?? "", maxRows: numberFormatter.format(data.maxRows) })
|
||||
: t("settings:auditExport.descriptionAdmin", { maxRows: numberFormatter.format(data.maxRows) })}
|
||||
</span>
|
||||
</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>
|
||||
{/* One form, three submit paths: GET csv / GET pdf / POST storage export.
|
||||
Filters sit in a Card on a responsive grid: as a bare flex row the two
|
||||
date fields (w-full by default) each claimed a whole line, which left
|
||||
the screen looking like a stack of full-bleed inputs rather than a
|
||||
filter form. */}
|
||||
<form method="get" data-ui-id="ui.audit.export.form">
|
||||
<Card className="gap-6">
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings:auditExport.filters.title")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("settings:auditExport.filters.hint")}
|
||||
</span>
|
||||
</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>
|
||||
<div className="grid w-full gap-4 [grid-template-columns:repeat(auto-fit,minmax(200px,1fr))]">
|
||||
<DateField label={t("settings:auditExport.filters.fromUtc")} name="from" defaultValue={data.defaultFrom} />
|
||||
<DateField label={t("settings:auditExport.filters.toUtc")} name="to" defaultValue={data.defaultTo} />
|
||||
{isTenant ? null : (
|
||||
<TextInput className="w-full max-w-full" 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>
|
||||
|
||||
{isTenant ? null : (
|
||||
<div className="grid w-full gap-4 sm:grid-cols-[2fr_1fr]">
|
||||
{/* Purpose is mandatory for the storage export (DoD 3) — message slot names the rule. */}
|
||||
<TextInput
|
||||
className="w-full max-w-full"
|
||||
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="w-full max-w-full">
|
||||
{data.formatOptions.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{t(`settings:${option.labelKey}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex w-full flex-wrap items-center justify-end gap-2 border-t border-solid border-border-default pt-4">
|
||||
<Button type="submit" name="export" value="csv" variant="secondary" icon={<FeatherDownload />} data-ui-id="ui.audit.export.csv">
|
||||
{t("settings:auditExport.downloadCsv")}
|
||||
</Button>
|
||||
<Button type="submit" name="export" value="pdf" variant="secondary" icon={<FeatherDownload />} data-ui-id="ui.audit.export.pdf">
|
||||
{t("settings:auditExport.downloadPdf")}
|
||||
</Button>
|
||||
{isTenant ? null : (
|
||||
<Button type="submit" formMethod="post" icon={<FeatherArchive />} data-ui-id="ui.audit.export.storage">
|
||||
{t("settings:auditExport.storage.submit")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
</form>
|
||||
|
||||
<AuditExportResultPanel result={result} />
|
||||
@@ -122,7 +191,9 @@ function SelectWithAny({
|
||||
// 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]">
|
||||
// max-w-full lifts the kit's built-in 320px cap so the select fills its grid
|
||||
// column instead of ending short of the field beside it.
|
||||
<Select name={name} label={label} showLabel defaultValue={FILTER_ALL} className="w-full max-w-full">
|
||||
<Select.Item value={FILTER_ALL}>{anyLabel}</Select.Item>
|
||||
{options.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
|
||||
+64
-5
@@ -10,7 +10,17 @@ 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 filter: AuditListFilterState = {
|
||||
from: null,
|
||||
to: null,
|
||||
tenantId: null,
|
||||
actorType: null,
|
||||
actorId: null,
|
||||
action: null,
|
||||
outcome: null,
|
||||
targetType: null,
|
||||
targetId: null,
|
||||
};
|
||||
const pagination: AuditListPagination = { page: 1, pageSize: 25, total: 2, totalPages: 1 };
|
||||
|
||||
function inputRow(overrides: Partial<AuditListInputRow> = {}): AuditListInputRow {
|
||||
@@ -37,7 +47,7 @@ function renderPage(vm: ReturnType<typeof buildVM>, onApply = vi.fn()) {
|
||||
return render(
|
||||
<Router>
|
||||
<AuditListPage vm={vm} exportHref="/admin/audit-export" actions={{ onApply }} />
|
||||
</Router>,
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,11 +61,60 @@ describe("AuditListPage (interim-UI)", () => {
|
||||
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" })]));
|
||||
it("shows the persisted summary in the detail drawer", () => {
|
||||
const { container, getByText } = renderPage(buildVM([inputRow({ summaryText: "Kontakt umbenannt", metadata: { source: "settings" }, hasMetadata: true })]));
|
||||
fireEvent.click(container.querySelector('[data-ui-id="ui.audit.list.detail"]')!);
|
||||
expect(getByText("Kontakt umbenannt")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows actor names and understandable actions instead of technical values", () => {
|
||||
const technicalId = "cms2q01t70000zz4ymxuk5hba";
|
||||
const technicalAction = "admin.login.fallback.success";
|
||||
const { container } = renderPage(
|
||||
buildVM([
|
||||
inputRow({
|
||||
actorType: "admin",
|
||||
actorName: "Raffael Sheikh",
|
||||
actorId: technicalId,
|
||||
action: technicalAction,
|
||||
targetType: null,
|
||||
targetId: null,
|
||||
}),
|
||||
])
|
||||
);
|
||||
|
||||
const table = container.querySelector('[data-ui-id="ui.audit.list.table"]');
|
||||
expect(table).toHaveTextContent("Raffael Sheikh");
|
||||
expect(table).toHaveTextContent("settings:audit.action.adminFallbackLoginSuccess");
|
||||
expect(table).not.toHaveTextContent(technicalId);
|
||||
expect(table).not.toHaveTextContent(technicalAction);
|
||||
});
|
||||
|
||||
it("keeps technical filters behind an optional advanced section", () => {
|
||||
const { container, getByText } = renderPage(buildVM([inputRow()]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.filter.advanced"]')).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(getByText("settings:audit.viewer.filters.more"));
|
||||
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.filter.advanced"]')).toBeInTheDocument();
|
||||
expect(getByText("settings:audit.viewer.filters.less")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("gives the primary filter controls accessible names", () => {
|
||||
const { getByRole } = renderPage(buildVM([inputRow()]));
|
||||
|
||||
expect(
|
||||
getByRole("combobox", {
|
||||
name: "settings:audit.viewer.filters.actorType: settings:auditExport.filters.any",
|
||||
})
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
getByRole("combobox", {
|
||||
name: "settings:audit.viewer.filters.outcome: settings:auditExport.filters.any",
|
||||
})
|
||||
).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();
|
||||
@@ -70,7 +129,7 @@ describe("AuditListPage (interim-UI)", () => {
|
||||
afterDiff: { name: "Neu GmbH", apiKey: "[REDACTED]" },
|
||||
summaryText: "Firma umbenannt",
|
||||
}),
|
||||
]),
|
||||
])
|
||||
);
|
||||
const detailButton = container.querySelector('[data-ui-id="ui.audit.list.detail"]');
|
||||
expect(detailButton).toBeInTheDocument();
|
||||
|
||||
+217
-85
@@ -6,7 +6,7 @@
|
||||
// "value changed" placeholder. Final Subframe optics land as a tracked
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AuditListFilterState, AuditListRow, AuditListVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
@@ -17,13 +17,25 @@ 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";
|
||||
import { LIVE_FILTER_DEBOUNCE_MS } from "~/hooks/use-live-filter";
|
||||
import { APP_TIME_ZONE } from "~/locale/format";
|
||||
|
||||
// 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;
|
||||
const EMPTY_FILTER: AuditListFilterState = {
|
||||
from: null,
|
||||
to: null,
|
||||
tenantId: null,
|
||||
actorType: null,
|
||||
actorId: null,
|
||||
action: null,
|
||||
outcome: null,
|
||||
targetType: null,
|
||||
targetId: null,
|
||||
};
|
||||
|
||||
export type AuditListQuery = AuditListFilterState & { page: number };
|
||||
|
||||
@@ -37,15 +49,49 @@ export type AuditListPageProps = {
|
||||
/** Href of the export screen (shown when the VM allows exporting). */
|
||||
exportHref: string;
|
||||
actions: AuditListActions;
|
||||
/** Suppresses the inline title/CTA row when the route renders its own page header. */
|
||||
hideHeader?: boolean;
|
||||
};
|
||||
|
||||
function actorTypeKey(actorType: string): string {
|
||||
return actorType === "api_key" ? "apiKey" : actorType;
|
||||
}
|
||||
|
||||
export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
function hasAdvancedFilter(filter: AuditListFilterState): boolean {
|
||||
return Boolean(filter.tenantId || filter.actorId || filter.action || filter.targetType || filter.targetId);
|
||||
}
|
||||
|
||||
function hasAnyFilter(filter: AuditListFilterState): boolean {
|
||||
return Object.values(filter).some(Boolean);
|
||||
}
|
||||
|
||||
function outcomeTone(outcome: string): "green-subtle" | "red-subtle" | "orange-subtle" | "neutral-subtle" {
|
||||
if (outcome === "success") return "green-subtle";
|
||||
if (outcome === "failure") return "red-subtle";
|
||||
if (outcome === "blocked") return "orange-subtle";
|
||||
return "neutral-subtle";
|
||||
}
|
||||
|
||||
function readableTargetType(value: string): string {
|
||||
return value
|
||||
.replace(/^Admin(?=[A-Z])/, "")
|
||||
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
||||
.replaceAll("_", " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function AuditListPage({ vm, exportHref, actions, hideHeader = false }: AuditListPageProps) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
const [openRowId, setOpenRowId] = useState<string | null>(null);
|
||||
const [advancedFilterOverride, setAdvancedFilterOverride] = useState<boolean | null>(null);
|
||||
// Live filter: text/date field edits re-apply the whole (uncontrolled) form
|
||||
// debounced; the selects below already navigate on change.
|
||||
const filterDebounceRef = useRef<number | null>(null);
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (filterDebounceRef.current) window.clearTimeout(filterDebounceRef.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
@@ -53,12 +99,10 @@ export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
}
|
||||
|
||||
const { rows, filter, pagination, canExport, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" });
|
||||
const openRow = openRowId ? (rows.find((row) => row.id === openRowId) ?? null) : null;
|
||||
|
||||
const showAdvancedFilters = advancedFilterOverride ?? hasAdvancedFilter(filter);
|
||||
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 });
|
||||
@@ -66,83 +110,152 @@ export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
|
||||
function applyFilterForm(form: HTMLFormElement) {
|
||||
const data = new FormData(form);
|
||||
const text = (name: string) => {
|
||||
const text = (name: string, current: string | null) => {
|
||||
if (!data.has(name)) return current;
|
||||
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"),
|
||||
from: text("from", filter.from),
|
||||
to: text("to", filter.to),
|
||||
tenantId: text("tenantId", filter.tenantId),
|
||||
actorId: text("actorId", filter.actorId),
|
||||
action: text("action", filter.action),
|
||||
targetType: text("targetType", filter.targetType),
|
||||
targetId: text("targetId", filter.targetId),
|
||||
});
|
||||
}
|
||||
|
||||
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>
|
||||
{hideHeader ? null : (
|
||||
<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>
|
||||
{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 className="flex flex-wrap items-center gap-3" data-ui-id="ui.audit.list.summary">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">
|
||||
{t("settings:audit.viewer.resultCount", {
|
||||
count: pagination.total,
|
||||
formattedCount: new Intl.NumberFormat(i18n.language).format(pagination.total),
|
||||
})}
|
||||
</span>
|
||||
{vm.data.summary.failedRows > 0 ? (
|
||||
<Tag_Label tone="red-subtle" size="small" noAction>
|
||||
{t("settings:audit.viewer.problemCount", { count: vm.data.summary.failedRows })}
|
||||
</Tag_Label>
|
||||
) : (
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{t("settings:audit.viewer.noProblems")}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Filter bar: text/date fields submit via the apply button; selects navigate on change */}
|
||||
<form
|
||||
className="flex flex-wrap items-end gap-4"
|
||||
className="flex flex-col gap-4"
|
||||
data-ui-id="ui.audit.list.filter"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
if (filterDebounceRef.current) window.clearTimeout(filterDebounceRef.current);
|
||||
applyFilterForm(event.currentTarget);
|
||||
}}
|
||||
onChange={(event) => {
|
||||
// Selects apply directly via onValueChange — their (hidden) native
|
||||
// select change must not schedule a second, redundant apply.
|
||||
if (event.target instanceof HTMLSelectElement) return;
|
||||
const form = event.currentTarget;
|
||||
if (filterDebounceRef.current) window.clearTimeout(filterDebounceRef.current);
|
||||
filterDebounceRef.current = window.setTimeout(() => applyFilterForm(form), LIVE_FILTER_DEBOUNCE_MS);
|
||||
}}
|
||||
>
|
||||
<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>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<TextInput className="max-w-[220px]" label={t("settings:audit.viewer.filters.from")} showLabel type="date">
|
||||
<TextInput.Input name="from" type="date" defaultValue={filter.from ?? ""} />
|
||||
</TextInput>
|
||||
<TextInput className="max-w-[220px]" label={t("settings:audit.viewer.filters.to")} showLabel type="date">
|
||||
<TextInput.Input name="to" type="date" defaultValue={filter.to ?? ""} />
|
||||
</TextInput>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings:audit.viewer.filters.actorType")}
|
||||
showLabel
|
||||
highContrastText
|
||||
triggerAriaLabel={`${t("settings:audit.viewer.filters.actorType")}: ${
|
||||
filter.actorType ? t(`settings:auditExport.actorTypes.${actorTypeKey(filter.actorType)}`) : t("settings:auditExport.filters.any")
|
||||
}`}
|
||||
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:audit.viewer.filters.outcome")}
|
||||
showLabel
|
||||
highContrastText
|
||||
triggerAriaLabel={`${t("settings:audit.viewer.filters.outcome")}: ${
|
||||
filter.outcome ? t(`settings:auditExport.outcomes.${filter.outcome}`) : t("settings:auditExport.filters.any")
|
||||
}`}
|
||||
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>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
aria-expanded={showAdvancedFilters}
|
||||
aria-controls="audit-advanced-filters"
|
||||
onClick={() => setAdvancedFilterOverride(!showAdvancedFilters)}
|
||||
>
|
||||
{showAdvancedFilters ? t("settings:audit.viewer.filters.less") : t("settings:audit.viewer.filters.more")}
|
||||
</Button>
|
||||
{hasAnyFilter(filter) ? (
|
||||
<Button variant="ghost" size="small" onClick={() => actions.onApply({ ...EMPTY_FILTER, page: 1 })}>
|
||||
{t("settings:audit.viewer.filters.reset")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{showAdvancedFilters ? (
|
||||
<div id="audit-advanced-filters" className="flex flex-wrap items-end gap-4" data-ui-id="ui.audit.list.filter.advanced">
|
||||
<TextInput className="max-w-[220px]" label={t("settings:audit.viewer.filters.accountId")} showLabel>
|
||||
<TextInput.Input name="tenantId" defaultValue={filter.tenantId ?? ""} placeholder={t("settings:audit.viewer.filters.accountIdPlaceholder")} />
|
||||
</TextInput>
|
||||
<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-[220px]" label={t("settings:audit.viewer.filters.actorId")} showLabel>
|
||||
<TextInput.Input name="actorId" defaultValue={filter.actorId ?? ""} placeholder={t("settings:audit.viewer.filters.actorIdPlaceholder")} />
|
||||
</TextInput>
|
||||
<TextInput className="max-w-[200px]" label={t("settings:audit.viewer.filters.targetType")} showLabel>
|
||||
<TextInput.Input name="targetType" defaultValue={filter.targetType ?? ""} />
|
||||
</TextInput>
|
||||
<TextInput className="max-w-[220px]" label={t("settings:audit.viewer.filters.targetId")} showLabel>
|
||||
<TextInput.Input name="targetId" defaultValue={filter.targetId ?? ""} />
|
||||
</TextInput>
|
||||
</div>
|
||||
) : null}
|
||||
</form>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
@@ -159,7 +272,6 @@ export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
<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>
|
||||
}
|
||||
@@ -167,7 +279,7 @@ export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
{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">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary whitespace-nowrap">
|
||||
{dateTimeFormatter.format(new Date(row.createdAtIso))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
@@ -176,26 +288,21 @@ export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
<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>
|
||||
<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>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(`settings:${row.actionLabelKey}`)}</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")}
|
||||
{row.targetType ? readableTargetType(row.targetType) : t("settings:audit.viewer.drawer.platform")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
<Tag_Label tone={outcomeTone(row.outcome)} size="small" noAction>
|
||||
{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>
|
||||
</Tag_Label>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{row.hasDetail ? (
|
||||
@@ -240,7 +347,17 @@ export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
|
||||
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" });
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" });
|
||||
const actorLabel = row?.actorLabel.startsWith("audit.") ? t(`settings:${row.actorLabel}`) : row?.actorLabel;
|
||||
const actionLabel = row ? t(`settings:${row.actionLabelKey}`) : "";
|
||||
const summaryLabel = row
|
||||
? (row.summaryText ??
|
||||
t(`settings:${row.summaryKey}`, {
|
||||
...row.summaryParams,
|
||||
actor: actorLabel,
|
||||
action: actionLabel,
|
||||
}))
|
||||
: "";
|
||||
|
||||
return (
|
||||
<Drawer open={row !== null} onOpenChange={(open: boolean) => (open ? undefined : onClose())}>
|
||||
@@ -250,13 +367,21 @@ function AuditDetailDrawer({ row, onClose }: { row: AuditListRow | null; onClose
|
||||
<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}
|
||||
{dateTimeFormatter.format(new Date(row.createdAtIso))} · {actionLabel}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{row.summaryText ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary">{row.summaryText}</span>
|
||||
) : null}
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary">{summaryLabel}</span>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3" data-ui-id="ui.audit.list.drawer.facts">
|
||||
<Fact label={t("settings:audit.viewer.drawer.tenantId")} value={row.tenantId ?? t("settings:audit.viewer.drawer.platform")} />
|
||||
<Fact label={t("settings:audit.viewer.drawer.actor")} value={actorLabel ?? t("settings:audit.viewer.drawer.emptyValue")} />
|
||||
<Fact label={t("settings:audit.viewer.drawer.actorType")} value={t(`settings:${row.actorKindLabelKey}`)} />
|
||||
<Fact label={t("settings:audit.viewer.drawer.outcome")} value={t(`settings:auditExport.outcomes.${row.outcome}`, row.outcome)} />
|
||||
<Fact label={t("settings:audit.viewer.drawer.targetType")} value={row.targetType ?? t("settings:audit.viewer.drawer.emptyValue")} />
|
||||
<Fact label={t("settings:audit.viewer.drawer.targetId")} value={row.targetId ?? t("settings:audit.viewer.drawer.emptyValue")} />
|
||||
<Fact label={t("settings:audit.viewer.drawer.actionCode")} value={row.action} />
|
||||
</div>
|
||||
|
||||
{row.diff.length > 0 ? (
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.audit.list.drawer.diff">
|
||||
@@ -308,15 +433,13 @@ function AuditDetailDrawer({ row, onClose }: { row: AuditListRow | null; onClose
|
||||
<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">
|
||||
<pre className="border-border-default text-body-default-regular-0 text-text-neutral-secondary max-h-80 w-full overflow-auto rounded-[4px] border border-solid p-3 font-mono">
|
||||
{row.metadataJson}
|
||||
</pre>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{row.diff.length === 0 && !row.metadataJson ? (
|
||||
<Alert variant="neutral" title={t("settings:audit.viewer.drawer.empty")} />
|
||||
) : 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">
|
||||
@@ -331,3 +454,12 @@ function AuditDetailDrawer({ row, onClose }: { row: AuditListRow | null; onClose
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
function Fact({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="border-border-default min-w-0 rounded-[4px] border border-solid px-3 py-2">
|
||||
<div className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{label}</div>
|
||||
<div className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary truncate">{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user