import { SectionEmpty, SkeletonLine, Table, Text } from "@cloudhal/ui"; import { ClockCounterClockwise } from "@phosphor-icons/react"; import { useQuery } from "@tanstack/react-query"; import { useT } from "../i18n/index.tsx"; import { api, isNotEnabled } from "../lib/api.ts"; import { apiErrorText } from "../lib/api-errors.ts"; import { DecisionCell, useToolLabel } from "./Audit.tsx"; import { RelativeTime } from "./RelativeTime.tsx"; /** Compact "Recent activity" table for the site overview: the five newest audit events. */ export function RecentActivity({ siteId, limit = 5 }: { siteId: string; limit?: number }) { const t = useT(); const label = useToolLabel(); const recent = useQuery({ queryKey: ["activity", siteId, "recent", limit], queryFn: () => api.activity.list(siteId, { limit }), retry: (count, error) => !isNotEnabled(error) && count < 1, }); if (recent.isPending) { return (
); } const items = recent.data?.items ?? []; if (items.length === 0) { return ( } title={ recent.error && !isNotEnabled(recent.error) ? t("errors.title") : t("activity.recentEmpty") } description={ isNotEnabled(recent.error) ? t("activity.notEnabledDescription") : recent.error ? apiErrorText(t, recent.error) : t("activity.recentEmptyDescription") } /> ); } return ( {items.map((r) => (
{label(r.tool)}
{r.actor.name ?? r.actor.id} ยท
))}
); }