// "API-Aufrufe" on the list chrome the rest of the product wears: the shared // facet filter bar, a ~/ui Table and the same server-side pagination footer the // audit viewer uses. // // It replaces the boilerplate TableSimple/InputFilters/InputSearchWithURL stack // for the tenant tab only — the admin log route keeps ApiKeyLogsDetails, which // also carries row selection and bulk delete. Filtering is server-side, so every // interaction is reported to the route, which turns it into query parameters. import { useTranslation } from "react-i18next"; import type { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropertyDto"; import type { PaginationDto } from "~/application/dtos/data/PaginationDto"; import type { ApiKeyLogDto } from "~/modules/api/dtos/ApiKeyLogDto"; import { useLocaleFormatters } from "~/locale/format"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { EmptyState } from "~/ui/components/EmptyState"; import { Table } from "~/ui/components/Table"; import { ApiFilterBar } from "./ApiFilterBar"; export type ApiLogsActions = { onSearchChange: (value: string) => void; onToggleProperty: (name: string, value: string) => void; onReset: () => void; onPage: (page: number) => void; }; type BadgeTone = React.ComponentProps["farbe"]; /** Same buckets the old SimpleBadge used, mapped onto the kit's feedback tones. */ export function methodTone(method: string): BadgeTone { if (method === "POST") return "subtle-positive"; if (method === "GET") return "subtle-information"; if (method === "PUT" || method === "PATCH") return "subtle-warning"; if (method === "DELETE") return "subtle-negative"; return "subtle-neutral"; } export function statusTone(status: number | null): BadgeTone { if (status === null) return "subtle-warning"; if (status >= 200 && status < 300) return "subtle-positive"; if (status >= 300 && status < 400) return "subtle-warning"; if (status >= 400) return "subtle-negative"; return "subtle-neutral"; } /** Duration buckets of the old ApiCallSpeedBadge, unchanged. */ export function speedLabelKey(duration: number): string { if (duration < 10) return "metrics.speed.lightningFast"; if (duration < 100) return "metrics.speed.fast"; if (duration < 1000) return "metrics.speed.average"; if (duration < 2000) return "metrics.speed.slow"; return "metrics.speed.verySlow"; } export function speedTone(duration: number): BadgeTone { if (duration < 100) return "subtle-positive"; if (duration < 1000) return "subtle-warning"; return "subtle-negative"; } const CELL_CLASS = "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary"; const MUTED_CLASS = "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"; export function ApiLogsPage({ items, properties, pagination, search, actions, }: { items: readonly ApiKeyLogDto[]; properties: readonly FilterablePropertyDto[]; pagination: PaginationDto; search: string; actions: ApiLogsActions; }): React.JSX.Element { const { t } = useTranslation(); const formatters = useLocaleFormatters(); const duration = (value: number | null) => value === null ? ( {t("shared.notSet")} ) : ( {formatters.number(Number(value), { style: "unit", unit: "millisecond", unitDisplay: "short", maximumFractionDigits: 3 })} ); return (
{items.length === 0 ? (
) : (
{t("shared.createdAt")}{t("models.apiKey.alias")}{t("models.apiKeyLog.ip")}{t("models.apiKeyLog.endpoint")}{t("models.apiKeyLog.method")}{t("models.apiKeyLog.status")}{t("models.apiKeyLog.duration")}{t("models.apiKeyLog.speed")}{t("models.apiKeyLog.error")} } > {items.map((item) => ( {item.apiKey?.alias ?? t("shared.notSet")} 0 ? CELL_CLASS : MUTED_CLASS}>{item.ip.length > 0 ? item.ip : t("shared.notSet")} {item.endpoint} {item.method} {item.status === null ? ( {t("shared.notSet")} ) : ( {String(item.status)} )} {duration(item.duration)} {item.duration === null ? ( {t("shared.notSet")} ) : ( {t(speedLabelKey(Number(item.duration)))} )} {/* An empty error column is the normal case — a dash reads quieter there than a spelled-out "not set". */} {item.error || "—"} ))}
)} {/* Server-side pagination, same shape as the audit viewer's footer. */}
{t("shared.pageInfo", { page: pagination.page, totalPages: Math.max(pagination.totalPages, 1), total: formatters.number(pagination.totalItems), })}
{pagination.page > 1 ? ( ) : null} {pagination.page < pagination.totalPages ? ( ) : null}
); }