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 (
{/* Status Icon and Title */}
{!isComplete && (
)} {isSuccess && (
)} {isComplete && !isSuccess && (
)}

{!isComplete && "Adding Observations to Dataset"} {isSuccess && "Successfully Added!"} {isComplete && !isSuccess && "Completed with Issues"}

{!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 .

)}
{/* Progress/Results Card */} {(!isComplete || status.data?.log || failedCount > 0) && (
{isComplete ? "Results" : "Progress"}
{!isComplete && totalCount > 0 && ( <>
{processedCount} of {totalCount} processed {progressPercent}%
Processed {processedCount}
Failed 0 ? "text-destructive" : ""}`} > {failedCount}
)} {isComplete && failedCount > 0 && (
Successfully processed {processedCount}
Failed {failedCount}
)} {status.data?.log && (

Error Summary:

                    {status.data.log}
                  
)}
)} {/* Action Buttons */}
{isComplete && hasPartialSuccess && ( )}
); }