import { Button } from "@/src/components/ui/button"; import { Progress } from "@/src/components/ui/progress"; import { api } from "@/src/utils/api"; import { StatusBadge } from "@/src/components/layouts/status-badge"; import { BatchActionStatus } from "@langfuse/shared"; import { Card, CardContent, CardHeader, CardTitle, } from "@/src/components/ui/card"; import Link from "next/link"; import { Check, AlertCircle, Loader2 } from "lucide-react"; type StatusStepProps = { projectId: string; batchActionId: string; dataset: { id: string; name: string }; expectedCount: number; onClose: () => void; }; export function StatusStep({ projectId, batchActionId, dataset, expectedCount, onClose, }: StatusStepProps) { // Poll for status updates const status = api.batchAction.byId.useQuery( { projectId, batchActionId, }, { refetchInterval: 2000, // Poll every 2 seconds }, ); // Use expectedCount as fallback when API hasn't populated totalCount yet const totalCount = status.data?.totalCount ?? expectedCount; const processedCount = status.data?.processedCount ?? 0; const failedCount = status.data?.failedCount ?? 0; const progressPercent = totalCount > 0 ? Math.round((processedCount / totalCount) * 100) : 0; const isComplete = [ BatchActionStatus.Completed, BatchActionStatus.Failed, BatchActionStatus.Partial, ].includes(status.data?.status as BatchActionStatus); const isSuccess = status.data?.status === BatchActionStatus.Completed; const hasPartialSuccess = status.data?.status === BatchActionStatus.Partial || status.data?.status === BatchActionStatus.Completed; return (
{!isComplete && `Adding ${totalCount} observations to ${dataset.name}`} {isSuccess && `${processedCount} observations have been added to ${dataset.name}`} {isComplete && !isSuccess && `${processedCount} observations added, ${failedCount} failed`}
{!isComplete && (You can safely close this dialog. The action is running in the background and you can track its progress in the{" "} batch actions table .
)}Error Summary:
{status.data.log}