Skip to content

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

fix(web): open evaluator delete confirmation as centered dialog (#14729)

Tobias Wochinger7533422a8978
diff --git a/web/src/components/ui/confirm-dialog.tsx b/web/src/components/ui/confirm-dialog.tsx
index 95a08b8a64..a292adac04 100644
--- a/web/src/components/ui/confirm-dialog.tsx
+++ b/web/src/components/ui/confirm-dialog.tsx
@@ -62,6 +62,52 @@ export function ConfirmDialog({
confirmDisabled?: boolean;
children?: React.ReactNode;
} & VariantProps<typeof confirmDialogContentVariants>) {
+ const content = (
+ <DialogContent
+ className={confirmDialogContentVariants({ size })}
+ // A confirm carries no unsaved work worth guarding, so an outside click
+ // dismisses it (the shared default keeps outside interaction blocked to
+ // protect form dialogs).
+ closeOnInteractionOutside
+ >
+ <DialogHeader variant="action">
+ <DialogTitle>{title}</DialogTitle>
+ </DialogHeader>
+ <DialogBody>
+ {description ? (
+ <DialogDescription>{description}</DialogDescription>
+ ) : null}
+ {children}
+ </DialogBody>
+ <DialogFooter variant="action">
+ <Button
+ variant="outline"
+ disabled={loading}
+ onClick={() => onOpenChange(false)}
+ >
+ {cancelLabel}
+ </Button>
+ <Button
+ variant={confirmVariant}
+ loading={loading}
+ disabled={confirmDisabled}
+ onClick={onConfirm}
+ >
+ {confirmLabel}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ );
+
+ // Callers commonly reset their state synchronously in onOpenChange (clearing
+ // a type-to-confirm input, nulling the table row the dialog points at), but
+ // Radix keeps the content mounted through the exit animation — so render the
+ // last-open content while closed to avoid a flicker to empty/default values
+ // mid fade-out. Render-phase ref write is deliberate: an effect would run
+ // only after the first closed render, too late to prevent the flicker.
+ const lastOpenContent = React.useRef(content);
+ if (open) lastOpenContent.current = content;
+
return (
<Dialog
open={open}
@@ -73,34 +119,7 @@ export function ConfirmDialog({
}}
>
{trigger ? <DialogTrigger asChild>{trigger}</DialogTrigger> : null}
- <DialogContent className={confirmDialogContentVariants({ size })}>
- <DialogHeader variant="action">
- <DialogTitle>{title}</DialogTitle>
- </DialogHeader>
- <DialogBody>
- {description ? (
- <DialogDescription>{description}</DialogDescription>
- ) : null}
- {children}
- </DialogBody>
- <DialogFooter variant="action">
- <Button
- variant="outline"
- disabled={loading}
- onClick={() => onOpenChange(false)}
- >
- {cancelLabel}
- </Button>
- <Button
- variant={confirmVariant}
- loading={loading}
- disabled={confirmDisabled}
- onClick={onConfirm}
- >
- {confirmLabel}
- </Button>
- </DialogFooter>
- </DialogContent>
+ {open ? content : lastOpenContent.current}
</Dialog>
);
}
diff --git a/web/src/components/ui/dialog-motion.module.css b/web/src/components/ui/dialog-motion.module.css
index 17ca0c9799..6e7682089c 100644
--- a/web/src/components/ui/dialog-motion.module.css
+++ b/web/src/components/ui/dialog-motion.module.css
@@ -10,12 +10,23 @@
animation: dialogContentOut 180ms cubic-bezier(0.4, 0, 1, 1) both;
}
+/* A closing dialog must be inert: its handlers are stale (ConfirmDialog even
+ freezes its last-open content), so e.g. a click landing on the fading
+ confirm button must not fire. Disable pointer events on descendants only —
+ the container keeps Radix's inline `pointer-events: auto`, which we rely on
+ as a shield so clicks during the fade-out do not reach the page beneath. */
+.content[data-state="closed"] * {
+ pointer-events: none;
+}
+
.overlay[data-state="open"] {
animation: dialogOverlayIn 200ms ease-out both;
}
.overlay[data-state="closed"] {
- animation: dialogOverlayOut 150ms ease-in both;
+ /* Same duration as the content exit: the overlay shields the rest of the
+ viewport from clicks for as long as the closing content is visible. */
+ animation: dialogOverlayOut 180ms ease-in both;
}
@keyframes dialogContentIn {
diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx
index 3e0747b780..119afdaf1b 100644
--- a/web/src/components/ui/dialog.tsx
+++ b/web/src/components/ui/dialog.tsx
@@ -38,7 +38,7 @@ const DialogOverlay = React.forwardRef<
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> & {
overlayMode?: DialogOverlayMode;
}
->(({ className, overlayMode = "subtle", ...props }, ref) => (
+>(({ className, overlayMode = "subtle", onClick, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
@@ -47,6 +47,13 @@ const DialogOverlay = React.forwardRef<
dialogOverlayClasses[overlayMode],
className,
)}
+ // The dialog portals its DOM out of the app tree, but React synthetic
+ // events still bubble through the REACT tree — into whatever rendered the
+ // dialog (e.g. a clickable table row). Backdrop clicks must not leak there.
+ onClick={(e) => {
+ onClick?.(e);
+ e.stopPropagation();
+ }}
{...props}
/>
));
@@ -87,6 +94,7 @@ const DialogContent = React.forwardRef<
overlayMode = "subtle",
stopPropagationOnEnterSpace = true,
onEscapeKeyDown,
+ onClick,
size,
...props
},
@@ -125,6 +133,12 @@ const DialogContent = React.forwardRef<
aria-describedby={undefined}
onKeyDown={handleKeyDown}
onEscapeKeyDown={handleEscapeKeyDown}
+ // See DialogOverlay: clicks inside the dialog must not bubble
+ // through the React tree into the component that rendered it.
+ onClick={(e) => {
+ onClick?.(e);
+ e.stopPropagation();
+ }}
onPointerDownOutside={(e) => {
if (!closeOnInteractionOutside) {
e.preventDefault();
diff --git a/web/src/features/evals/components/delete-eval-template-button.tsx b/web/src/features/evals/components/delete-eval-template-button.tsx
deleted file mode 100644
index f9c595663d..0000000000
--- a/web/src/features/evals/components/delete-eval-template-button.tsx
+++ /dev/null
@@ -1,137 +0,0 @@
-import {
- DeleteButton,
- type DeleteButtonProps,
-} from "@/src/components/deleteButton";
-import { showErrorToast } from "@/src/features/notifications/showErrorToast";
-import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
-import { api } from "@/src/utils/api";
-import { ExternalLinkIcon } from "lucide-react";
-import Link from "next/link";
-import { useState } from "react";
-
-type ReferencingEvaluator = {
- id: string;
- scoreName: string;
-};
-
-type DeleteEvalTemplateButtonProps = DeleteButtonProps & {
- // Usage count from already-loaded table data; lets the blocked state render
- // instantly while the usage query is in flight.
- initialUsageCount?: number;
- // The template name; doubles as the type-to-confirm string.
- deleteConfirmation: string;
-};
-
-export function DeleteEvalTemplateButton(props: DeleteEvalTemplateButtonProps) {
- const utils = api.useUtils();
- const {
- itemId,
- projectId,
- scope = "evalTemplate:CUD",
- invalidateFunc = () => utils.evals.invalidate(),
- initialUsageCount,
- deleteConfirmation: templateName,
- } = props;
-
- const templateMutation = api.evals.deleteEvalTemplate.useMutation({
- onSuccess: () => {
- showSuccessToast({
- title: "Evaluator deleted",
- description: `Evaluator "${templateName}" was deleted.`,
- });
- utils.evals.invalidate();
- },
- onError: (error) =>
- showErrorToast("Failed to delete evaluator", error.message),
- });
-
- // Only fetch usage once the user actually opens the delete popover. Once
- // deletion starts, the query must go inactive so post-delete invalidation
- // does not refetch it and surface a NOT_FOUND.
- const [hasOpenedPopover, setHasOpenedPopover] = useState(false);
- const usage = api.evals.evalTemplateUsage.useQuery(
- { projectId, evalTemplateId: itemId },
- {
- enabled:
- hasOpenedPopover &&
- !templateMutation.isPending &&
- !templateMutation.isSuccess,
- },
- );
- const referencingEvaluators = usage.data;
- const usageCount = referencingEvaluators?.length ?? initialUsageCount ?? 0;
-
- const executeDeleteMutation = async (onSuccess: () => void) => {
- try {
- await templateMutation.mutateAsync({
- evalTemplateId: itemId,
- projectId,
- });
- onSuccess();
- } catch {
- // Surfaced via the mutation's onError toast.
- }
- };
-
- const renderEvaluatorLink = (evaluator: ReferencingEvaluator) => (
- <Link
- href={`/project/${projectId}/evals?peek=${evaluator.id}`}
- target="_blank"
- rel="noopener noreferrer"
- className="inline-flex items-center gap-1 text-blue-600 hover:underline"
- >
- {evaluator.scoreName}
- <ExternalLinkIcon className="h-3 w-3" />
- </Link>
- );
-
- const deleteBlocker =
- usageCount > 0 ? (
- <>
- <h2 className="mb-3 font-semibold">Cannot delete</h2>
- <p className="mb-3 max-w-72 text-sm">
- This evaluator is used by {usageCount} running evaluator
- {usageCount === 1 ? "" : "s"}. Delete those running evaluators first.
- </p>
- {referencingEvaluators && referencingEvaluators.length > 0 ? (
- referencingEvaluators.length === 1 ? (
- <div className="max-w-72 text-sm">
- {renderEvaluatorLink(referencingEvaluators[0])}
- </div>
- ) : (
- <ul className="max-h-40 max-w-72 list-inside list-disc overflow-y-auto text-sm">
- {referencingEvaluators.map((evaluator) => (
- <li key={evaluator.id}>{renderEvaluatorLink(evaluator)}</li>
- ))}
- </ul>
- )
- ) : null}
- </>
- ) : undefined;
-
- return (
- <DeleteButton
- {...props}
- scope={scope}
- invalidateFunc={invalidateFunc}
- captureDeleteOpen={(capture, isTableAction) =>
- capture("eval_templates:delete_form_open", {
- source: isTableAction ? "table-single-row" : "template",
- })
- }
- captureDeleteSuccess={(capture, isTableAction) =>
- capture("eval_templates:delete_template_button_click", {
- source: isTableAction ? "table-single-row" : "template",
- })
- }
- entityToDeleteName="evaluator"
- customDeletePrompt="This action cannot be undone. It permanently deletes all versions of this evaluator. Scores already produced by it will not be deleted."
- executeDeleteMutation={executeDeleteMutation}
- isDeleteMutationLoading={templateMutation.isPending}
- deleteBlocker={deleteBlocker}
- onPopoverOpenChange={(open) => {
- if (open) setHasOpenedPopover(true);
- }}
- />
- );
-}
diff --git a/web/src/features/evals/components/delete-eval-template-dialog.tsx b/web/src/features/evals/components/delete-eval-template-dialog.tsx
new file mode 100644
index 0000000000..807bfdaec3
--- /dev/null
+++ b/web/src/features/evals/components/delete-eval-template-dialog.tsx
@@ -0,0 +1,160 @@
+import { ExternalLinkIcon } from "lucide-react";
+import Link from "next/link";
+import { useState } from "react";
+
+import { ConfirmDialog } from "@/src/components/ui/confirm-dialog";
+import { Input } from "@/src/components/ui/input";
+import { Label } from "@/src/components/ui/label";
+import { showErrorToast } from "@/src/features/notifications/showErrorToast";
+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
+import { api } from "@/src/utils/api";
+
+type ReferencingEvaluator = {
+ id: string;
+ scoreName: string;
+};
+
+const EvaluatorLink = ({
+ projectId,
+ evaluator,
+}: {
+ projectId: string;
+ evaluator: ReferencingEvaluator;
+}) => (
+ <Link
+ href={`/project/${projectId}/evals?peek=${evaluator.id}`}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="inline-flex items-center gap-1 text-blue-600 hover:underline"
+ >
+ {evaluator.scoreName}
+ <ExternalLinkIcon className="h-3 w-3" />
+ </Link>
+);
+
+/**
+ * Confirm-then-delete dialog for an eval template. Rendered as a controlled
+ * ConfirmDialog so callers can keep it a sibling of dropdown menus — a confirm
+ * nested inside DropdownMenuContent unmounts when the menu closes (see the
+ * overlay-lifecycle rule in web/AGENTS.md).
+ */
+export function DeleteEvalTemplateDialog({
+ projectId,
+ templateId,
+ templateName,
+ open,
+ onOpenChange,
+ onSuccess,
+ initialUsageCount,
+}: {
+ projectId: string;
+ templateId: string;
+ templateName: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ // Called after successful deletion; the caller owns follow-up side effects
+ // like analytics, redirects, or extra cache invalidation.
+ onSuccess?: () => void;
+ // Usage count from already-loaded table data; lets the blocked state render
+ // instantly while the usage query is in flight.
+ initialUsageCount?: number;
+}) {
+ const utils = api.useUtils();
+ const [confirmationInput, setConfirmationInput] = useState("");
+
+ const templateMutation = api.evals.deleteEvalTemplate.useMutation({
+ onSuccess: () => {
+ showSuccessToast({
+ title: "Evaluator deleted",
+ description: `Evaluator "${templateName}" was deleted.`,
+ });
+ utils.evals.invalidate();
+ },
+ onError: (error) =>
+ showErrorToast("Failed to delete evaluator", error.message),
+ });
+
+ // Once deletion starts, the usage query must go inactive so post-delete
+ // invalidation does not refetch it and surface a NOT_FOUND.
+ const usage = api.evals.evalTemplateUsage.useQuery(
+ { projectId, evalTemplateId: templateId },
+ {
+ enabled:
+ open && !templateMutation.isPending && !templateMutation.isSuccess,
+ },
+ );
+ const referencingEvaluators = usage.data;
+ const usageCount = referencingEvaluators?.length ?? initialUsageCount ?? 0;
+ const isBlocked = usageCount > 0;
+
+ const handleOpenChange = (nextOpen: boolean) => {
+ // Reset the type-to-confirm input on close so the confirmation must be
+ // re-typed each time.
+ if (!nextOpen) setConfirmationInput("");
+ onOpenChange(nextOpen);
+ };
+
+ const handleConfirm = async () => {
+ try {
+ await templateMutation.mutateAsync({
+ evalTemplateId: templateId,
+ projectId,
+ });
+ } catch {
+ // Surfaced via the mutation's onError toast.
+ return;
+ }
+ handleOpenChange(false);
+ onSuccess?.();
+ };
+
+ return (
+ <ConfirmDialog
+ open={open}
+ onOpenChange={handleOpenChange}
+ size="lg"
+ title={isBlocked ? "Cannot delete" : "Please confirm"}
+ description={
+ isBlocked
+ ? `This evaluator is used by ${usageCount} running evaluator${usageCount === 1 ? "" : "s"}. Delete those running evaluators first.`
+ : "This action cannot be undone. It permanently deletes all versions of this evaluator. Scores already produced by it will not be deleted."
+ }
+ confirmLabel="Delete evaluator"
+ loading={templateMutation.isPending}
+ confirmDisabled={isBlocked || confirmationInput !== templateName}
+ onConfirm={handleConfirm}
+ >
+ {isBlocked ? (
+ referencingEvaluators && referencingEvaluators.length > 0 ? (
+ referencingEvaluators.length === 1 ? (
+ <div className="text-sm">
+ <EvaluatorLink
+ projectId={projectId}
+ evaluator={referencingEvaluators[0]}
+ />
+ </div>
+ ) : (
+ <ul className="max-h-40 list-inside list-disc overflow-y-auto text-sm">
+ {referencingEvaluators.map((evaluator) => (
+ <li key={evaluator.id}>
+ <EvaluatorLink projectId={projectId} evaluator={evaluator} />
+ </li>
+ ))}
+ </ul>
+ )
+ ) : null
+ ) : (
+ <div className="grid w-full gap-1.5">
+ <Label htmlFor="delete-evaluator-confirmation">
+ Type &quot;{templateName}&quot; to confirm
+ </Label>
+ <Input
+ id="delete-evaluator-confirmation"
+ value={confirmationInput}
+ onChange={(e) => setConfirmationInput(e.target.value)}
+ />
+ </div>
+ )}
+ </ConfirmDialog>
+ );
+}
diff --git a/web/src/features/evals/components/eval-template-detail.tsx b/web/src/features/evals/components/eval-template-detail.tsx
index 187829d1d1..c1815d63a1 100644
--- a/web/src/features/evals/components/eval-template-detail.tsx
+++ b/web/src/features/evals/components/eval-template-detail.tsx
@@ -25,7 +25,9 @@ import {
SidePanelTitle,
} from "@/src/components/ui/side-panel";
import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";
-import { DeleteEvalTemplateButton } from "@/src/features/evals/components/delete-eval-template-button";
+import { DeleteEvalTemplateDialog } from "@/src/features/evals/components/delete-eval-template-dialog";
+import { IconOnlyButton } from "@/src/components/IconOnlyButton";
+import { TrashIcon } from "lucide-react";
export const EvalTemplateDetail = () => {
const router = useRouter();
@@ -33,6 +35,12 @@ export const EvalTemplateDetail = () => {
const templateId = router.query.id as string;
const mode = router.query.mode;
const isEditing = mode === "edit";
+ const [isDeleteDialogOpen, setIsDeleteDialogOpen] = React.useState(false);
+ const capture = usePostHogClientCapture();
+ const hasDeleteAccess = useHasProjectAccess({
+ projectId,
+ scope: "evalTemplate:CUD",
+ });
// get the current template by id
const template = api.evals.templateById.useQuery({
@@ -108,13 +116,39 @@ export const EvalTemplateDetail = () => {
/>
{template.data?.projectId ? (
- <DeleteEvalTemplateButton
- itemId={templateId}
- projectId={projectId}
- icon
- redirectUrl={`/project/${projectId}/evals/templates`}
- deleteConfirmation={template.data.name}
- />
+ <>
+ <IconOnlyButton
+ icon={<TrashIcon className="h-4 w-4" />}
+ label="Delete"
+ aria-label="delete"
+ variant="outline-solid"
+ size="icon"
+ disabledReason={
+ hasDeleteAccess
+ ? undefined
+ : "You don't have permission to delete this evaluator."
+ }
+ onClick={() => {
+ capture("eval_templates:delete_form_open", {
+ source: "template",
+ });
+ setIsDeleteDialogOpen(true);
+ }}
+ />
+ <DeleteEvalTemplateDialog
+ projectId={projectId}
+ templateId={templateId}
+ templateName={template.data.name}
+ open={isDeleteDialogOpen}
+ onOpenChange={setIsDeleteDialogOpen}
+ onSuccess={() => {
+ capture("eval_templates:delete_template_button_click", {
+ source: "template",
+ });
+ router.push(`/project/${projectId}/evals/templates`);
+ }}
+ />
+ </>
) : null}
</>
),
diff --git a/web/src/features/evals/components/eval-templates-table.tsx b/web/src/features/evals/components/eval-templates-table.tsx
index 1e62c0a866..8cfd525654 100644
--- a/web/src/features/evals/components/eval-templates-table.tsx
+++ b/web/src/features/evals/components/eval-templates-table.tsx
@@ -6,7 +6,7 @@ import useColumnVisibility from "@/src/features/column-visibility/hooks/useColum
import { type RouterOutputs, api } from "@/src/utils/api";
import { safeExtract } from "@/src/utils/map-utils";
import { createColumnHelper } from "@tanstack/react-table";
-import { Copy, MoreVertical, Pen } from "lucide-react";
+import { Copy, MoreVertical, Pen, Trash } from "lucide-react";
import { useQueryParam, StringParam, withDefault } from "use-query-params";
import { useEffect, useMemo, useState } from "react";
import { usePaginationState } from "@/src/hooks/usePaginationState";
@@ -31,7 +31,8 @@ import {
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
-import { DeleteEvalTemplateButton } from "@/src/features/evals/components/delete-eval-template-button";
+import { DeleteEvalTemplateDialog } from "@/src/features/evals/components/delete-eval-template-dialog";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { EvalTemplateForm } from "@/src/features/evals/components/template-form";
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
import { EvalReferencedEvaluators } from "@/src/features/evals/types";
@@ -120,6 +121,115 @@ const templateTableRowHeights: CustomHeights = {
l: "h-8",
};
+// Owns the per-row actions dropdown plus the delete confirm dialog as its
+// sibling (see the overlay-lifecycle rule in web/AGENTS.md). The dialog's
+// open state is local so opening it re-renders only this cell, not the table.
+const EvalTemplateRowActionsMenu = ({
+ projectId,
+ templateId,
+ templateName,
+ usageCount,
+ hasAccess,
+ showClone,
+ showEditAndDelete,
+ onEdit,
+ onClone,
+}: {
+ projectId: string;
+ templateId: string;
+ templateName: string;
+ usageCount?: number;
+ hasAccess: boolean;
+ showClone: boolean;
+ showEditAndDelete: boolean;
+ onEdit: () => void;
+ onClone: () => void;
+}) => {
+ // undefined = never opened: keeps the dialog unmounted for untouched rows,
+ // while close (false) keeps it mounted so the exit animation can play.
+ const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState<boolean>();
+ const capture = usePostHogClientCapture();
+ const utils = api.useUtils();
+ const hasTemplateWriteAccess = useHasProjectAccess({
+ projectId,
+ scope: "evalTemplate:CUD",
+ });
+
+ return (
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="icon-xs" aria-label="actions">
+ <span className="sr-only relative">Open menu</span>
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ {showClone ? (
+ <DropdownMenuItem
+ aria-label="clone"
+ disabled={!hasAccess}
+ onClick={(e) => {
+ e.stopPropagation();
+ onClone();
+ }}
+ >
+ <Copy className="mr-2 h-4 w-4" />
+ Clone
+ </DropdownMenuItem>
+ ) : null}
+ {showEditAndDelete ? (
+ <>
+ <DropdownMenuItem
+ aria-label="edit"
+ disabled={!hasAccess}
+ onClick={(e) => {
+ e.stopPropagation();
+ onEdit();
+ }}
+ >
+ <Pen className="mr-2 h-4 w-4" />
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ aria-label="delete"
+ disabled={!hasTemplateWriteAccess}
+ onClick={(e) => {
+ e.stopPropagation();
+ capture("eval_templates:delete_form_open", {
+ source: "table-single-row",
+ });
+ setIsDeleteDialogOpen(true);
+ }}
+ >
+ <Trash className="mr-2 h-4 w-4" />
+ Delete
+ </DropdownMenuItem>
+ </>
+ ) : null}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {isDeleteDialogOpen !== undefined ? (
+ <DeleteEvalTemplateDialog
+ projectId={projectId}
+ templateId={templateId}
+ templateName={templateName}
+ initialUsageCount={usageCount}
+ open={isDeleteDialogOpen}
+ onOpenChange={setIsDeleteDialogOpen}
+ onSuccess={() => {
+ capture("eval_templates:delete_template_button_click", {
+ source: "table-single-row",
+ });
+ utils.evals.templateNames.invalidate();
+ }}
+ />
+ ) : null}
+ </>
+ );
+};
+
export default function EvalsTemplateTable({
projectId,
}: {
@@ -367,59 +477,17 @@ export default function EvalsTemplateTable({
Use Evaluator
</ActionButton>
{hasMenuItems && id ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size="icon-xs" aria-label="actions">
- <span className="sr-only relative">Open menu</span>
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- {!isUserMaintained && !isCodeTemplate ? (
- <DropdownMenuItem
- aria-label="clone"
- disabled={!hasAccess}
- onClick={(e) => {
- e.stopPropagation();
- setCloneTemplateId(id);
- }}
- >
- <Copy className="mr-2 h-4 w-4" />
- Clone
- </DropdownMenuItem>
- ) : null}
- {isUserMaintained ? (
- <>
- <DropdownMenuItem
- aria-label="edit"
- disabled={!hasAccess}
- onClick={(e) => {
- e.stopPropagation();
- setEditTemplateId(id);
- }}
- >
- <Pen className="mr-2 h-4 w-4" />
- Edit
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <DeleteEvalTemplateButton
- aria-label="delete"
- itemId={id}
- projectId={projectId}
- isTableAction
- className="w-full justify-start"
- deleteConfirmation={row.original.name}
- initialUsageCount={row.original.usageCount}
- invalidateFunc={() => {
- utils.evals.templateNames.invalidate();
- }}
- />
- </DropdownMenuItem>
- </>
- ) : null}
- </DropdownMenuContent>
- </DropdownMenu>
+ <EvalTemplateRowActionsMenu
+ projectId={projectId}
+ templateId={id}
+ templateName={row.original.name}
+ usageCount={row.original.usageCount}
+ hasAccess={hasAccess}
+ showClone={!isUserMaintained && !isCodeTemplate}
+ showEditAndDelete={isUserMaintained}
+ onEdit={() => setEditTemplateId(id)}
+ onClone={() => setCloneTemplateId(id)}
+ />
) : null}
</div>
);