🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): deletion of dataset runs (#3209)
marliessophie937b4c0f0f6d
diff --git a/web/src/features/audit-logs/auditLog.ts b/web/src/features/audit-logs/auditLog.tsindex 0b8721996d..d4234d92e9 100644--- a/web/src/features/audit-logs/auditLog.ts+++ b/web/src/features/audit-logs/auditLog.ts@@ -8,6 +8,7 @@ export type AuditableResource =| "comment"| "datasetItem"| "dataset"+ | "datasetRun"| "trace"| "project"| "observation"diff --git a/web/src/features/datasets/components/DatasetRunsTable.tsx b/web/src/features/datasets/components/DatasetRunsTable.tsxindex 6daaaa0fa8..07060b2c81 100644--- a/web/src/features/datasets/components/DatasetRunsTable.tsx+++ b/web/src/features/datasets/components/DatasetRunsTable.tsx@@ -20,12 +20,23 @@ import {} from "@/src/features/scores/components/ScoreDetailColumnHelpers";import { type ScoreAggregate } from "@/src/features/scores/lib/types";import { useIndividualScoreColumns } from "@/src/features/scores/hooks/useIndividualScoreColumns";+import { MoreVertical } from "lucide-react";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuLabel,+ DropdownMenuTrigger,+} from "@/src/components/ui/dropdown-menu";+import { Button } from "@/src/components/ui/button";+import { DeleteDatasetRunButton } from "@/src/features/datasets/components/DeleteDatasetRunButton";++type DatasetRunRowKey = {+ id: string;+ name: string;+};export type DatasetRunRowData = {- key: {- id: string;- name: string;- };+ key: DatasetRunRowKey;createdAt: string;countRunItems: string;avgLatency: number;@@ -45,6 +56,7 @@ export function DatasetRunsTable(props: {pageIndex: withDefault(NumberParam, 0),pageSize: withDefault(NumberParam, 50),});+const [rowHeight, setRowHeight] = useRowHeightLocalStorage("datasetRuns","s",@@ -149,6 +161,35 @@ export function DatasetRunsTable(props: {) : null;},},+ {+ id: "actions",+ accessorKey: "actions",+ header: "Actions",+ size: 70,+ cell: ({ row }) => {+ const key: DatasetRunRowKey = row.getValue("key");+ const { id: datasetRunId } = key;++ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" className="h-8 w-8 p-0">+ <span className="sr-only [position:relative]">Open menu</span>+ <MoreVertical className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DeleteDatasetRunButton+ projectId={props.projectId}+ datasetRunId={datasetRunId}+ fullWidth+ />+ </DropdownMenuContent>+ </DropdownMenu>+ );+ },+ },];const convertToTableRow = (diff --git a/web/src/features/datasets/components/DeleteDatasetRunButton.tsx b/web/src/features/datasets/components/DeleteDatasetRunButton.tsxnew file mode 100644index 0000000000..fcb26d96d7--- /dev/null+++ b/web/src/features/datasets/components/DeleteDatasetRunButton.tsx@@ -0,0 +1,94 @@+import { Trash } from "lucide-react";+import { Button } from "@/src/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/src/components/ui/dialog";+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import { api } from "@/src/utils/api";+import React, { useState } from "react";+import { useRouter } from "next/router";++export const DeleteDatasetRunButton = ({+ projectId,+ datasetRunId,+ fullWidth = false,+ redirectUrl,+}: {+ projectId: string;+ datasetRunId: string;+ fullWidth?: boolean;+ redirectUrl?: string;+}) => {+ const [isDialogOpen, setIsDialogOpen] = useState(false);+ const capture = usePostHogClientCapture();+ const hasAccess = useHasProjectAccess({+ projectId: projectId,+ scope: "datasets:CUD",+ });+ const utils = api.useUtils();+ const router = useRouter();+ const mutDelete = api.datasets.deleteDatasetRun.useMutation({+ onSuccess: () => {+ redirectUrl ? router.push(redirectUrl) : utils.datasets.invalidate();+ },+ });++ const button = fullWidth ? (+ <Button variant="ghost" className="w-full" disabled={!hasAccess}>+ <div className="flex w-full flex-row items-center gap-1">+ <Trash className="h-4 w-4" />+ <span className="text-sm font-normal">Delete</span>+ </div>+ </Button>+ ) : (+ <Button variant="outline" size="icon" disabled={!hasAccess}>+ <Trash className="h-4 w-4" />+ </Button>+ );++ return hasAccess ? (+ <Dialog+ open={isDialogOpen}+ onOpenChange={(isOpen) => {+ if (!mutDelete.isLoading) {+ setIsDialogOpen(isOpen);+ }+ }}+ >+ <DialogTrigger asChild>{button}</DialogTrigger>+ <DialogContent className="sm:max-w-xl">+ <DialogHeader>+ <DialogTitle className="mb-4">Please confirm</DialogTitle>+ <DialogDescription className="text-md p-0">+ This action cannot be undone and removes all the data associated+ with this dataset run.+ </DialogDescription>+ </DialogHeader>+ <Button+ variant="destructive"+ loading={mutDelete.isLoading}+ disabled={mutDelete.isLoading}+ onClick={async (event) => {+ event.preventDefault();+ capture("dataset_run:delete_form_open");+ await mutDelete.mutateAsync({+ projectId,+ datasetRunId,+ });+ setIsDialogOpen(false);+ }}+ >+ Delete Dataset Run+ </Button>+ </DialogContent>+ </Dialog>+ ) : (+ button+ );+};diff --git a/web/src/features/datasets/server/dataset-router.ts b/web/src/features/datasets/server/dataset-router.tsindex 1397a3506c..44e421694f 100644--- a/web/src/features/datasets/server/dataset-router.ts+++ b/web/src/features/datasets/server/dataset-router.ts@@ -801,4 +801,35 @@ export const datasetRouter = createTRPCRouter({},});}),+ deleteDatasetRun: protectedProjectProcedure+ .input(+ z.object({+ projectId: z.string(),+ datasetRunId: z.string(),+ }),+ )+ .mutation(async ({ input, ctx }) => {+ throwIfNoProjectAccess({+ session: ctx.session,+ projectId: input.projectId,+ scope: "datasets:CUD",+ });++ const deletedDatasetRun = await ctx.prisma.datasetRuns.delete({+ where: {+ id_projectId: {+ id: input.datasetRunId,+ projectId: input.projectId,+ },+ },+ });+ await auditLog({+ session: ctx.session,+ resourceType: "datasetRun",+ resourceId: deletedDatasetRun.id,+ action: "delete",+ before: deletedDatasetRun,+ });+ return deletedDatasetRun;+ }),});diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex d31876f5c0..a834f63ad5 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -95,6 +95,7 @@ const events = {"new_from_trace_form_submit","new_from_trace_form_open",],+ dataset_run: ["delete_form_open"],notification: ["click_link", "dismiss_notification"],tag: ["add_existing_tag",diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsxindex 77de035ead..b70c91e28e 100644--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx@@ -2,6 +2,7 @@ import { FullScreenPage } from "@/src/components/layouts/full-screen-page";import Header from "@/src/components/layouts/header";import { JSONView } from "@/src/components/ui/CodeJsonViewer";import { DatasetRunItemsTable } from "@/src/features/datasets/components/DatasetRunItemsTable";+import { DeleteDatasetRunButton } from "@/src/features/datasets/components/DeleteDatasetRunButton";import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";import { api } from "@/src/utils/api";import { useRouter } from "next/router";@@ -36,13 +37,20 @@ export default function Dataset() {{ name: run.data?.name ?? "" },]}actionButtons={- <DetailPageNav- currentId={runId}- path={(id) =>- `/project/${projectId}/datasets/${datasetId}/runs/${id}`- }- listKey="datasetRuns"- />+ <>+ <DeleteDatasetRunButton+ projectId={projectId}+ datasetRunId={runId}+ redirectUrl={`/project/${projectId}/datasets/${datasetId}`}+ />+ <DetailPageNav+ currentId={runId}+ path={(id) =>+ `/project/${projectId}/datasets/${datasetId}/runs/${id}`+ }+ listKey="datasetRuns"+ />+ </>}/><div className="flex flex-col gap-2">