// "Übersicht" — API calls grouped by method/endpoint/status, on the same list // chrome as the neighbouring tabs. // // Replaces the boilerplate InputCombobox + InputFilters + TableSimple stack of // ApiKeyLogsSummary for the tenant tab. The grouping control keeps its URL // contract (repeated `groupBy` parameters) and sits inside the filter bar, next // to the facets it orders. The row link into "API-Aufrufe" carries the group's // values as filters, exactly as before. import { useTranslation } from "react-i18next"; import { Link } from "react-router"; import { FeatherLayers } from "@subframe/core"; import type { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropertyDto"; import type { ApiCallSummaryDto } from "~/modules/api/dtos/ApiCallSummaryDto"; import { useLocaleFormatters } from "~/locale/format"; import { Alert } from "~/ui/components/Alert"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { DropdownMenuMultiSelect } from "~/ui/components/DropdownMenuMultiSelect"; import { EmptyState } from "~/ui/components/EmptyState"; import { FilterBar } from "~/ui/components/FilterBar"; import { Table } from "~/ui/components/Table"; import { ApiFilterBar } from "./ApiFilterBar"; import { methodTone, speedLabelKey, speedTone, statusTone } from "./ApiLogsPage"; /** Group-by keys the service accepts; the tenant tab has no tenant grouping. */ export const GROUP_BY_KEYS = ["method", "endpoint", "params", "status"] as const; export type GroupByKey = (typeof GROUP_BY_KEYS)[number]; export type ApiSummaryActions = { onSearchChange: (value: string) => void; onToggleProperty: (name: string, value: string) => void; onToggleGroupBy: (key: GroupByKey) => void; onReset: () => void; }; 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"; const GROUP_LABEL_KEY: Record = { method: "models.apiKeyLog.method", endpoint: "models.apiKeyLog.endpoint", params: "models.apiKeyLog.params", status: "models.apiKeyLog.status", }; export function ApiSummaryPage({ items, properties, groupBy, search, detailHrefFor, actions, }: { items: readonly ApiCallSummaryDto[]; properties: readonly FilterablePropertyDto[]; groupBy: readonly GroupByKey[]; search: string; /** Link into the calls tab, pre-filtered with this row's group values. */ detailHrefFor: (item: ApiCallSummaryDto) => string; actions: ApiSummaryActions; }): React.JSX.Element { const { t } = useTranslation(); const formatters = useLocaleFormatters(); return (
} label={t("models.apiKeyLog.groupBy.prefix")} showCount={groupBy.length > 0} count={groupBy.length > 0 ? String(groupBy.length) : ""} data-ui-id="ui.settings.apiSummary.groupBy" dropdown={ {GROUP_BY_KEYS.map((key) => ( actions.onToggleGroupBy(key)} data-ui-id={`ui.settings.apiSummary.groupBy.${key}`} > {t(GROUP_LABEL_KEY[key])} ))} } /> } /> {groupBy.length === 0 ? ( ) : items.length === 0 ? (
) : (
{groupBy.map((key) => ( {t(GROUP_LABEL_KEY[key])} ))} {t("models.apiKeyLog.apiCalls")}{t("models.apiKeyLog.avgDuration")}{t("models.apiKeyLog.speed")} } > {items.map((item, index) => { const average = item._avg.duration === null ? null : Number(item._avg.duration); return ( {groupBy.map((key) => ( {groupCell(key, item)} ))} {t("models.apiKeyLog.calls", { count: Number(item._count._all), formattedCount: formatters.number(Number(item._count._all)) })} {average === null ? ( {t("shared.notAvailable")} ) : ( {formatters.number(average, { style: "unit", unit: "millisecond", unitDisplay: "short", maximumFractionDigits: 3 })} )} {average === null ? ( {t("shared.notAvailable")} ) : ( {t(speedLabelKey(average))} )} {t("shared.details")} ); })}
)}
); function groupCell(key: GroupByKey, item: ApiCallSummaryDto) { if (key === "method") { return ( {item.method} ); } if (key === "status") { return item.status === null ? ( {t("shared.unknown")} ) : ( {String(item.status)} ); } return {key === "endpoint" ? item.endpoint : item.params}; } }