import { DataTable } from "@/src/components/table/data-table"; import { type LangfuseColumnDef } from "@/src/components/table/types"; import { api } from "@/src/utils/api"; import { safeExtract } from "@/src/utils/map-utils"; import { StatusBadge } from "@/src/components/layouts/status-badge"; import { NumberParam, useQueryParams, withDefault } from "use-query-params"; import { InfoIcon } from "lucide-react"; import { Avatar, AvatarImage } from "@/src/components/ui/avatar"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/src/components/ui/tooltip"; import { LocalIsoDate } from "@/src/components/LocalIsoDate"; type BatchActionRow = { id: string; actionType: string; tableName: string; status: string; totalCount: number | null; processedCount: number | null; failedCount: number | null; createdAt: Date; finishedAt: Date | null; log: string | null; user: { name: string | null; image: string | null; } | null; }; export function BatchActionsTable(props: { projectId: string }) { const [paginationState, setPaginationState] = useQueryParams({ pageIndex: withDefault(NumberParam, 0), pageSize: withDefault(NumberParam, 10), }); const batchActions = api.batchAction.all.useQuery({ projectId: props.projectId, limit: paginationState.pageSize, page: paginationState.pageIndex, }); const columns: LangfuseColumnDef[] = [ { accessorKey: "actionType", id: "actionType", header: "Action Type", size: 200, cell: ({ row }) => { const actionType = row.getValue("actionType") as string; const formattedType = actionType .split("-") .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" "); return {formattedType}; }, }, { accessorKey: "tableName", id: "tableName", header: "Table", size: 120, cell: ({ row }) => { const tableName = row.getValue("tableName") as string; return {tableName}; }, }, { accessorKey: "status", id: "status", header: "Status", size: 110, cell: ({ row }) => { const status = row.getValue("status") as string; return ( ); }, }, { accessorKey: "progress", id: "progress", header: "Progress", size: 150, cell: ({ row }) => { const totalCount = row.original.totalCount; const processedCount = row.original.processedCount ?? 0; const failedCount = row.original.failedCount ?? 0; if (!totalCount) return -; return (
{processedCount} / {totalCount}
{failedCount > 0 && (
{failedCount} failed
)}
); }, }, { accessorKey: "createdAt", id: "createdAt", header: "Created", size: 150, cell: ({ row }) => { const createdAt = row.getValue("createdAt") as Date; return ; }, }, { accessorKey: "finishedAt", id: "finishedAt", header: "Finished", size: 150, cell: ({ row }) => { const finishedAt = row.getValue("finishedAt") as Date | null; return finishedAt ? ( ) : ( - ); }, }, { accessorKey: "user", id: "user", header: "Created By", size: 150, cell: ({ row }) => { const user = row.getValue("user") as { name: string | null; image: string | null; } | null; return (
{user?.name ?? "Unknown"}
); }, }, { accessorKey: "log", id: "log", header: "Log", size: 300, cell: ({ row }) => { const log = row.getValue("log") as string | null; return log ? (
{log}
                  {log}
                
) : null; }, }, ]; return ( ); }