Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(batch-export): allow canceling jobs from ui (#10844)

marliessophieb84927bdbc00
diff --git a/web/src/features/batch-exports/components/BatchExportsTable.tsx b/web/src/features/batch-exports/components/BatchExportsTable.tsx
index 7f4153cea6..106f99cda2 100644
--- a/web/src/features/batch-exports/components/BatchExportsTable.tsx
+++ b/web/src/features/batch-exports/components/BatchExportsTable.tsx
@@ -14,12 +14,27 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/src/components/ui/tooltip";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+} from "@/src/components/ui/alert-dialog";
+import { useState } from "react";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
export function BatchExportsTable(props: { projectId: string }) {
const [paginationState, setPaginationState] = useQueryParams({
pageIndex: withDefault(NumberParam, 0),
pageSize: withDefault(NumberParam, 10),
});
+ const [cancelDialogOpen, setCancelDialogOpen] = useState(false);
+ const [selectedExportId, setSelectedExportId] = useState<string | null>(null);
const batchExports = api.batchExport.all.useQuery({
projectId: props.projectId,
@@ -27,6 +42,19 @@ export function BatchExportsTable(props: { projectId: string }) {
page: paginationState.pageIndex,
});
+ const cancelBatchExport = api.batchExport.cancel.useMutation({
+ onSuccess: () => {
+ void batchExports.refetch();
+ setCancelDialogOpen(false);
+ setSelectedExportId(null);
+ },
+ });
+
+ const hasAccess = useHasProjectAccess({
+ projectId: props.projectId,
+ scope: "batchExports:create",
+ });
+
const columns = [
{
accessorKey: "name",
@@ -130,6 +158,68 @@ export function BatchExportsTable(props: { projectId: string }) {
return log ?? null;
},
},
+ {
+ accessorKey: "actions",
+ id: "actions",
+ header: "Actions",
+ size: 100,
+ cell: ({ row }) => {
+ const id = row.getValue("id") as string;
+ const status = row.getValue("status") as string;
+
+ // Only show cancel button for queued or processing exports
+ if (status !== "QUEUED" && status !== "PROCESSING") {
+ return null;
+ }
+
+ return (
+ <AlertDialog
+ open={cancelDialogOpen && selectedExportId === id}
+ onOpenChange={(open) => {
+ if (!open) {
+ setCancelDialogOpen(false);
+ setSelectedExportId(null);
+ }
+ }}
+ >
+ <AlertDialogTrigger asChild>
+ <ActionButton
+ hasAccess={hasAccess}
+ size="sm"
+ onClick={() => {
+ setSelectedExportId(id);
+ setCancelDialogOpen(true);
+ }}
+ >
+ Cancel
+ </ActionButton>
+ </AlertDialogTrigger>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Cancel batch export?</AlertDialogTitle>
+ <AlertDialogDescription>
+ Are you sure you want to cancel this batch export? This action
+ cannot be undone.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>No, keep it</AlertDialogCancel>
+ <AlertDialogAction
+ onClick={() => {
+ cancelBatchExport.mutate({
+ projectId: props.projectId,
+ batchExportId: id,
+ });
+ }}
+ >
+ Yes, cancel export
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ );
+ },
+ },
] as LangfuseColumnDef<BatchExport>[];
return (
diff --git a/web/src/features/batch-exports/server/batchExport.ts b/web/src/features/batch-exports/server/batchExport.ts
index 0bb50b21ff..25e61267ce 100644
--- a/web/src/features/batch-exports/server/batchExport.ts
+++ b/web/src/features/batch-exports/server/batchExport.ts
@@ -76,6 +76,25 @@ export const batchExportRouter = createTRPCRouter({
});
}
}),
+ cancel: protectedProjectProcedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ batchExportId: z.string(),
+ }),
+ )
+ .mutation(async ({ input, ctx }) => {
+ throwIfNoProjectAccess({
+ session: ctx.session,
+ projectId: input.projectId,
+ scope: "batchExports:create",
+ });
+
+ await ctx.prisma.batchExport.update({
+ where: { id: input.batchExportId, projectId: input.projectId },
+ data: { status: BatchExportStatus.CANCELLED },
+ });
+ }),
all: protectedProjectProcedure
.input(
z.object({