diff --git a/web/src/components/runs/cancel-run-button.tsx b/web/src/components/runs/cancel-run-button.tsx index 3440da0e..0bd83c6b 100644 --- a/web/src/components/runs/cancel-run-button.tsx +++ b/web/src/components/runs/cancel-run-button.tsx @@ -1,7 +1,18 @@ +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog.js'; import { Button } from '@/components/ui/button.js'; import { trpc, trpcClient } from '@/lib/trpc.js'; import { useMutation, useQueryClient } from '@tanstack/react-query'; -import { Square } from 'lucide-react'; +import { CheckCircle, Loader2, Square } from 'lucide-react'; +import { useEffect, useState } from 'react'; interface CancelRunButtonProps { runId: string; @@ -11,10 +22,13 @@ interface CancelRunButtonProps { export function CancelRunButton({ runId, status }: CancelRunButtonProps) { const queryClient = useQueryClient(); + const [showDialog, setShowDialog] = useState(false); + const [showSuccess, setShowSuccess] = useState(false); const cancelMutation = useMutation({ mutationFn: () => trpcClient.runs.cancel.mutate({ runId }), onSuccess: () => { + setShowSuccess(true); queryClient.invalidateQueries({ queryKey: trpc.runs.list.queryOptions({}).queryKey }); queryClient.invalidateQueries({ queryKey: trpc.runs.getById.queryOptions({ id: runId }).queryKey, @@ -22,38 +36,83 @@ export function CancelRunButton({ runId, status }: CancelRunButtonProps) { }, }); + // Auto-dismiss success indicator after 2 seconds + useEffect(() => { + if (showSuccess) { + const timer = setTimeout(() => { + setShowSuccess(false); + }, 2000); + return () => clearTimeout(timer); + } + }, [showSuccess]); + if (status !== 'running') { return null; } return ( - - - {cancelMutation.isError && ( - - Failed + <> + + + + {showSuccess && !cancelMutation.isPending && ( + Cancelled + )} + {cancelMutation.isError && !showSuccess && ( + + {cancelMutation.error instanceof Error + ? `Error: ${cancelMutation.error.message}` + : 'Failed'} + + )} - )} - + + + + Cancel Run + + This will terminate the worker container. Are you sure? + + + + Cancel + { + cancelMutation.mutate(); + }} + className="bg-destructive text-destructive-foreground hover:bg-destructive/90" + > + Terminate + + + + + ); }