Skip to content

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

refactor(web): Replace some legacy dropdowns with `DropdownMenu` (#17790)

Ben Bachemc393d14be439
diff --git a/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx b/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx
index 240d4390ba..020cdedd61 100644
--- a/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx
+++ b/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx
@@ -100,6 +100,7 @@ type DropdownMenuItem = {
disabled?: { reason: string };
id: string;
title: string;
+ tooltip?: string;
icon?: LucideIcon;
type: "item";
variant?: "default" | "destructive";
@@ -554,7 +555,7 @@ function DropdownMenuNode({
role="menuitem"
tabIndex={activeIndex === index ? 0 : -1}
aria-disabled={item.disabled ? "true" : undefined}
- title={item.disabled?.reason}
+ title={item.disabled?.reason ?? item.tooltip}
ref={(element) => {
listRef.current[index] = element;
}}
diff --git a/web/src/features/annotation-queues/components/AnnotationQueueItemsTable.tsx b/web/src/features/annotation-queues/components/AnnotationQueueItemsTable.tsx
index db9beaf16e..fd7fa162c6 100644
--- a/web/src/features/annotation-queues/components/AnnotationQueueItemsTable.tsx
+++ b/web/src/features/annotation-queues/components/AnnotationQueueItemsTable.tsx
@@ -15,12 +15,7 @@ import { ChevronDown, ListTree, Trash } from "lucide-react";
import { type RouterOutput } from "@/src/utils/types";
import { type RowSelectionState } from "@tanstack/react-table";
import { useState } from "react";
-import {
- DropdownMenu,
- DropdownMenuTrigger,
- DropdownMenuContent,
- DropdownMenuItem,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import { Button } from "@/src/components/ui/button";
import {
Dialog,
@@ -98,24 +93,29 @@ const QueueItemTableMultiSelectAction = ({
return (
<>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button disabled={selectedItemIds.length < 1}>
+ <DropdownMenu
+ disabled={selectedItemIds.length < 1}
+ items={[
+ {
+ type: "item",
+ id: "delete",
+ title: "Delete",
+ icon: Trash,
+ disabled: hasDeleteAccess
+ ? undefined
+ : { reason: "Missing permission to delete queue items" },
+ onClick: () => {
+ setOpen(true);
+ },
+ },
+ ]}
+ >
+ {({ getTriggerProps }) => (
+ <Button disabled={selectedItemIds.length < 1} {...getTriggerProps()}>
Actions ({selectedItemIds.length} selected)
<ChevronDown className="h-5 w-5" />
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
- disabled={!hasDeleteAccess}
- onClick={() => {
- setOpen(true);
- }}
- >
- <Trash className="mr-2 h-4 w-4" />
- <span>Delete</span>
- </DropdownMenuItem>
- </DropdownMenuContent>
+ )}
</DropdownMenu>
<Dialog
open={open}
diff --git a/web/src/features/datasets/DatasetRunPage.tsx b/web/src/features/datasets/DatasetRunPage.tsx
index 1e410af63c..0fb7dc1907 100644
--- a/web/src/features/datasets/DatasetRunPage.tsx
+++ b/web/src/features/datasets/DatasetRunPage.tsx
@@ -9,12 +9,7 @@ import Link from "next/link";
import { useRouter } from "next/router";
import { useEffect } from "react";
import Page from "@/src/components/layouts/page";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import {
SidePanel,
SidePanelContent,
@@ -93,18 +88,29 @@ function DatasetRunLegacy() {
redirectUrl={`/project/${projectId}/datasets/${datasetId}/experiments`}
>
{({ disabled, openDialog }) => (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="outline" size="icon">
+ <DropdownMenu
+ items={[
+ {
+ type: "item",
+ id: "delete",
+ title: "Delete",
+ icon: Trash,
+ disabled: disabled
+ ? { reason: "Missing permission to delete this run" }
+ : undefined,
+ onClick: openDialog,
+ },
+ ]}
+ >
+ {({ getTriggerProps }) => (
+ <Button
+ variant="outline"
+ size="icon"
+ {...getTriggerProps()}
+ >
<MoreVertical className="h-4 w-4" />
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem disabled={disabled} onSelect={openDialog}>
- <Trash className="h-4 w-4" />
- <span>Delete</span>
- </DropdownMenuItem>
- </DropdownMenuContent>
+ )}
</DropdownMenu>
)}
</DeleteDatasetRunDialogController>
diff --git a/web/src/features/evals/pages/remap-evaluator.tsx b/web/src/features/evals/pages/remap-evaluator.tsx
index 2aa425fbd1..3cf7859d6a 100644
--- a/web/src/features/evals/pages/remap-evaluator.tsx
+++ b/web/src/features/evals/pages/remap-evaluator.tsx
@@ -15,13 +15,8 @@ import { Button } from "@/src/components/ui/button";
import { Callout } from "@/src/components/design-system/Callout/Callout";
import { DismissController } from "@/src/components/DismissController";
import { Separator } from "@/src/components/ui/separator";
-import {
- DropdownMenu,
- DropdownMenuTrigger,
- DropdownMenuContent,
- DropdownMenuItem,
-} from "@/src/components/ui/dropdown-menu";
-import { BotMessageSquare, ChevronDown, Zap } from "lucide-react";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
+import { BotMessageSquare, Check, ChevronDown, Zap } from "lucide-react";
import { useEvalCapabilities } from "@/src/features/evals/hooks/useEvalCapabilities";
import {
useIsInAppAgentLauncherVisible,
@@ -322,30 +317,40 @@ export default function RemapEvaluatorPage() {
? "Save & mark legacy inactive"
: "Save & delete legacy"}
</Button>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <DropdownMenu
+ disabled={isLoading}
+ placement="bottom-end"
+ items={[
+ {
+ type: "item",
+ id: "mark-inactive",
+ title: "Save & mark legacy inactive",
+ icon:
+ legacyAction === "mark-inactive"
+ ? Check
+ : undefined,
+ onClick: () => setLegacyAction("mark-inactive"),
+ },
+ {
+ type: "item",
+ id: "delete",
+ title: "Save & delete legacy",
+ icon:
+ legacyAction === "delete" ? Check : undefined,
+ onClick: () => setLegacyAction("delete"),
+ },
+ ]}
+ >
+ {({ getTriggerProps }) => (
<Button
type="button"
disabled={isLoading}
className="mt-3 rounded-l-none rounded-r-md border-l-2"
+ {...getTriggerProps()}
>
<ChevronDown className="h-4 w-4" />
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onClick={() => setLegacyAction("mark-inactive")}
- >
- {legacyAction === "mark-inactive" && "✓ "}
- Save & mark legacy inactive
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={() => setLegacyAction("delete")}
- >
- {legacyAction === "delete" && "✓ "}
- Save & delete legacy
- </DropdownMenuItem>
- </DropdownMenuContent>
+ )}
</DropdownMenu>
</div>
</div>
diff --git a/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.stories.tsx b/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.stories.tsx
index 38c66c4b19..7aeadff633 100644
--- a/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.stories.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.stories.tsx
@@ -36,13 +36,12 @@ export const OpenMenu = meta.story({
onDelete: fn(),
},
play: async ({ canvas, canvasElement }) => {
- await userEvent.click(
- canvas.getByRole("button", { name: "Evaluator actions" }),
- );
+ const trigger = canvas.getByRole("button", { name: "Evaluator actions" });
+ await userEvent.click(trigger);
+ await expect(trigger).toHaveAttribute("aria-expanded", "true");
const body = within(canvasElement.ownerDocument.body);
const menuElement = await body.findByRole("menu");
- await expect(menuElement).toHaveAttribute("data-state", "open");
const menu = within(menuElement);
await expect(
menu.getByRole("menuitem", { name: "View executions" }),
diff --git a/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.tsx b/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.tsx
index 0ff40cb60e..39aac84093 100644
--- a/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.tsx
+++ b/web/src/features/evals/v2/components/Evaluators/EvaluatorActionsCell/EvaluatorActionsCell.tsx
@@ -8,12 +8,7 @@ import {
} from "lucide-react";
import { Button } from "@/src/components/ui/button";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
export function EvaluatorActionsCell({
@@ -50,39 +45,56 @@ export function EvaluatorActionsCell({
View scores
<SquarePercent className="ml-1 h-3.5 w-3.5" />
</Button>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <DropdownMenu
+ placement="bottom-end"
+ items={[
+ ...(canViewExecutions
+ ? [
+ {
+ type: "item" as const,
+ id: "view-executions",
+ title: "View executions",
+ icon: ListTree,
+ onClick: onViewExecutions,
+ },
+ ]
+ : []),
+ {
+ type: "item",
+ id: "edit",
+ title: "Edit",
+ icon: Pencil,
+ onClick: onEdit,
+ },
+ {
+ type: "item",
+ id: "clone",
+ title: "Clone",
+ icon: Copy,
+ onClick: onClone,
+ },
+ {
+ type: "item",
+ id: "delete",
+ title: "Delete",
+ icon: Trash2,
+ onClick: onDelete,
+ },
+ ]}
+ >
+ {({ getTriggerProps }) => (
<Button
type="button"
variant="ghost"
size="icon-xs"
aria-label="Evaluator actions"
className="shrink-0"
+ {...getTriggerProps()}
>
<span className="sr-only">Open menu</span>
<MoreVertical className="h-4 w-4" />
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {canViewExecutions ? (
- <DropdownMenuItem onClick={onViewExecutions}>
- <ListTree className="mr-2 h-4 w-4" />
- View executions
- </DropdownMenuItem>
- ) : null}
- <DropdownMenuItem onClick={onEdit}>
- <Pencil className="mr-2 h-4 w-4" />
- Edit
- </DropdownMenuItem>
- <DropdownMenuItem onClick={onClone}>
- <Copy className="mr-2 h-4 w-4" />
- Clone
- </DropdownMenuItem>
- <DropdownMenuItem onClick={onDelete}>
- <Trash2 className="mr-2 h-4 w-4" />
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
+ )}
</DropdownMenu>
</div>
);
diff --git a/web/src/features/evals/v2/components/Rules/RulesTable/RulesTable.tsx b/web/src/features/evals/v2/components/Rules/RulesTable/RulesTable.tsx
index 60d7e862e6..fa2e59471d 100644
--- a/web/src/features/evals/v2/components/Rules/RulesTable/RulesTable.tsx
+++ b/web/src/features/evals/v2/components/Rules/RulesTable/RulesTable.tsx
@@ -19,12 +19,7 @@ import { SingleLineOverflowList } from "@/src/components/SingleLineOverflowList"
import { Badge } from "@/src/components/ui/badge";
import { Button } from "@/src/components/ui/button";
import { ConfirmDialog } from "@/src/components/ui/confirm-dialog";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import { CreateRuleDialog } from "@/src/features/evals/v2/components/Rules/CreateRuleDialog/CreateRuleDialog";
import { EditRuleDialog } from "@/src/features/evals/v2/components/Rules/EditRuleDialog/EditRuleDialog";
import { RulesOverviewSelectionBar } from "@/src/features/evals/v2/components/Rules/RulesTable/components/RulesOverviewSelectionBar/RulesOverviewSelectionBar";
@@ -434,41 +429,54 @@ export function RulesTable({
>
View traces <ExternalLink className="ml-1 h-3.5 w-3.5" />
</Button>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <DropdownMenu
+ placement="bottom-end"
+ items={[
+ ...(navigationAction === "edit"
+ ? [
+ {
+ type: "item" as const,
+ id: "edit",
+ title: "Edit",
+ icon: Pencil,
+ onClick: () => setEditRuleId(row.original.id),
+ },
+ ]
+ : []),
+ {
+ type: "item",
+ id: "clone",
+ title: "Clone",
+ icon: Copy,
+ disabled:
+ hasWriteAccess && navigationAction === "edit"
+ ? undefined
+ : { reason: "This rule cannot be cloned" },
+ onClick: () => setCloneRule(row.original),
+ },
+ {
+ type: "item",
+ id: "delete",
+ title: "Delete",
+ icon: Trash2,
+ disabled: hasWriteAccess
+ ? undefined
+ : { reason: "Missing permission to delete rules" },
+ onClick: () => setDeleteIds([row.original.id]),
+ },
+ ]}
+ >
+ {({ getTriggerProps }) => (
<Button
type="button"
variant="ghost"
size="icon-xs"
aria-label={`Actions for ${row.original.name}`}
+ {...getTriggerProps()}
>
<MoreVertical className="h-4 w-4" />
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {navigationAction === "edit" ? (
- <DropdownMenuItem
- onClick={() => setEditRuleId(row.original.id)}
- >
- <Pencil className="mr-2 h-4 w-4" />
- Edit
- </DropdownMenuItem>
- ) : null}
- <DropdownMenuItem
- disabled={!hasWriteAccess || navigationAction !== "edit"}
- onClick={() => setCloneRule(row.original)}
- >
- <Copy className="mr-2 h-4 w-4" />
- Clone
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={!hasWriteAccess}
- onClick={() => setDeleteIds([row.original.id])}
- >
- <Trash2 className="mr-2 h-4 w-4" />
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
+ )}
</DropdownMenu>
</div>
);
diff --git a/web/src/features/monitors/components/MonitorAutomationsPanel.create.clienttest.tsx b/web/src/features/monitors/components/MonitorAutomationsPanel.create.clienttest.tsx
index 6d710caa28..d9669e55ba 100644
--- a/web/src/features/monitors/components/MonitorAutomationsPanel.create.clienttest.tsx
+++ b/web/src/features/monitors/components/MonitorAutomationsPanel.create.clienttest.tsx
@@ -1,4 +1,14 @@
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { LayerProvider } from "@/src/context/LayerContext/LayerContext";
+
+vi.stubGlobal(
+ "ResizeObserver",
+ class ResizeObserver {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+);
const existingRow = {
id: "auto-1",
@@ -58,9 +68,7 @@ import { MonitorAutomationsPanel } from "./MonitorAutomationsPanel";
/** openCreateDialog opens the "+ Automation" menu and picks one of its items. */
const openCreateDialog = async (item: RegExp) => {
- fireEvent.keyDown(screen.getByRole("button", { name: /^automation$/i }), {
- key: "Enter",
- });
+ fireEvent.click(screen.getByRole("button", { name: /^automation$/i }));
fireEvent.click(await screen.findByRole("menuitem", { name: item }));
};
@@ -82,6 +90,7 @@ describe("MonitorAutomationsPanel automation creation", () => {
triggerIds={["trig-1"]}
onTriggerIdsChange={onTriggerIdsChange}
/>,
+ { wrapper: LayerProvider },
);
await openCreateDialog(/new automation/i);
@@ -107,7 +116,7 @@ describe("MonitorAutomationsPanel automation creation", () => {
onTriggerIdsChange={onTriggerIdsChange}
/>
);
- const { rerender } = render(panel());
+ const { rerender } = render(panel(), { wrapper: LayerProvider });
await openCreateDialog(/^webhook$/i);
// The create invalidates the list, so the first automation lands while the
@@ -142,7 +151,7 @@ describe("MonitorAutomationsPanel automation creation", () => {
onTriggerIdsChange={onTriggerIdsChange}
/>
);
- const { rerender } = render(panel([]));
+ const { rerender } = render(panel([]), { wrapper: LayerProvider });
await openCreateDialog(/new automation/i);
fireEvent.click(await screen.findByRole("button", { name: /stub save/i }));
diff --git a/web/src/features/monitors/components/MonitorAutomationsPanel.tsx b/web/src/features/monitors/components/MonitorAutomationsPanel.tsx
index 6ec0203812..367d2cc69b 100644
--- a/web/src/features/monitors/components/MonitorAutomationsPanel.tsx
+++ b/web/src/features/monitors/components/MonitorAutomationsPanel.tsx
@@ -20,12 +20,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/src/components/ui/dialog";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import {
AutomationForm,
WebhookSecretRender,
@@ -45,6 +40,14 @@ const actionLabel: Record<ActionTypes, string> = {
GITHUB_DISPATCH: "GitHub Dispatch",
};
+const actionIcon = {
+ WEBHOOK: WebhookIcon,
+ // eslint-disable-next-line @typescript-eslint/no-deprecated -- Preserve existing automation brand icons until their replacements are migrated.
+ SLACK: Slack,
+ // eslint-disable-next-line @typescript-eslint/no-deprecated -- Preserve existing automation brand icons until their replacements are migrated.
+ GITHUB_DISPATCH: Github,
+} satisfies Record<ActionTypes, typeof WebhookIcon>;
+
/** MonitorAutomationsPanel lets the user select which automations fire for a monitor via explicit trigger IDs. */
export const MonitorAutomationsPanel = ({
projectId,
@@ -283,33 +286,38 @@ const AddAutomationDropdown = ({
return (
<>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <DropdownMenu
+ disabled={isDisabled}
+ placement="bottom-end"
+ items={[
+ {
+ type: "item",
+ id: "new",
+ title: "New automation",
+ icon: Plus,
+ onClick: () => setDraft({}),
+ },
+ ...ActionTypeSchema.options.map((actionType) => ({
+ type: "item" as const,
+ id: actionType,
+ title: actionLabel[actionType],
+ icon: actionIcon[actionType],
+ onClick: () => setDraft({ actionType }),
+ })),
+ ]}
+ >
+ {({ getTriggerProps }) => (
<Button
variant="outline"
size="lg"
disabled={isDisabled}
className={fullWidth ? "w-full" : undefined}
+ {...getTriggerProps()}
>
<Plus className="mr-2 h-4 w-4" />
Automation
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="w-48">
- <DropdownMenuItem onSelect={() => setDraft({})}>
- <Plus className="mr-2 h-3.5 w-3.5" />
- New automation
- </DropdownMenuItem>
- {ActionTypeSchema.options.map((t) => (
- <DropdownMenuItem
- key={t}
- onSelect={() => setDraft({ actionType: t })}
- >
- <ActionIcon type={t} className="mr-2 h-3.5 w-3.5" />
- {actionLabel[t]}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
+ )}
</DropdownMenu>
<Dialog
open={draft !== null}
diff --git a/web/src/features/prompts/PromptsPage.tsx b/web/src/features/prompts/PromptsPage.tsx
index 46f1dfdda6..b2efaf57bd 100644
--- a/web/src/features/prompts/PromptsPage.tsx
+++ b/web/src/features/prompts/PromptsPage.tsx
@@ -15,12 +15,7 @@ import { useState } from "react";
import { AutomationButton } from "@/src/features/automations";
import { ImportPromptsButtonDialogController } from "@/src/features/prompts/components/ImportPromptsButtonDialogController";
import { Button } from "@/src/components/ui/button";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { toast } from "sonner";
@@ -131,21 +126,34 @@ export default function PromptsPage() {
<>
{projectId && <AutomationButton projectId={projectId} />}
{hasReadAccess && (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="outline" disabled={isExporting}>
+ <DropdownMenu
+ disabled={isExporting}
+ placement="bottom-end"
+ items={[
+ {
+ type: "item",
+ id: "latest",
+ title: "Latest version per prompt",
+ onClick: () => handleExport("latest"),
+ },
+ {
+ type: "item",
+ id: "all",
+ title: "All versions",
+ onClick: () => handleExport("all"),
+ },
+ ]}
+ >
+ {({ getTriggerProps }) => (
+ <Button
+ variant="outline"
+ disabled={isExporting}
+ {...getTriggerProps()}
+ >
<UploadIcon className="mr-1 h-4 w-4" />
{isExporting ? "Exporting…" : "Export"}
</Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem onClick={() => handleExport("latest")}>
- Latest version per prompt
- </DropdownMenuItem>
- <DropdownMenuItem onClick={() => handleExport("all")}>
- All versions
- </DropdownMenuItem>
- </DropdownMenuContent>
+ )}
</DropdownMenu>
)}
{projectId && (
diff --git a/web/src/features/widgets/components/DashboardWidget.tsx b/web/src/features/widgets/components/DashboardWidget.tsx
index 2f26142aab..536d4909e3 100644
--- a/web/src/features/widgets/components/DashboardWidget.tsx
+++ b/web/src/features/widgets/components/DashboardWidget.tsx
@@ -43,13 +43,7 @@ import {
} from "@/src/features/widgets/utils/import-export-utils";
import { copyTextToClipboard } from "@/src/utils/clipboard";
import { useCaptureWidgetHighCardinalityError } from "@/src/features/widgets/hooks/useWidgetQueryErrorCapture";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
import {
formatMetricName,
mergeWidgetAndDashboardFilters,
@@ -680,79 +674,92 @@ export function DashboardWidget({
) : null}
</>
)}
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <DropdownMenu
+ placement="bottom-end"
+ items={[
+ ...(tableView
+ ? [
+ {
+ type: "item" as const,
+ id: "view-as-table",
+ title: viewAsTableHint
+ ? `View as table (${viewAsTableHint.count} filter${viewAsTableHint.count === 1 ? "" : "s"} not shown in the table)`
+ : "View as table",
+ tooltip: viewAsTableHint?.title,
+ icon: TableIcon,
+ onClick: handleViewAsTable,
+ },
+ {
+ id: "table-separator",
+ type: "separator" as const,
+ },
+ ]
+ : []),
+ {
+ type: "item",
+ id: "copy",
+ title: "Copy widget",
+ icon: CopyIcon,
+ onClick: handleCopyToClipboard,
+ },
+ ...(onDuplicateWidget
+ ? [
+ {
+ type: "item" as const,
+ id: "clone",
+ title: "Clone",
+ icon: CopyPlusIcon,
+ onClick: () =>
+ onDuplicateWidget(placement, widgetExportSource),
+ },
+ ]
+ : []),
+ { id: "download-separator", type: "separator" },
+ {
+ type: "item",
+ id: "download-json",
+ title: "Download as JSON",
+ icon: FileJsonIcon,
+ onClick: handleDownloadJson,
+ },
+ {
+ type: "item",
+ id: "download-csv",
+ title: "Download data as CSV",
+ icon: DownloadIcon,
+ disabled: queryResult.isPending
+ ? { reason: "Chart data is still loading" }
+ : undefined,
+ onClick: () =>
+ downloadChartDataCsv(transformedData, widget.data.name),
+ },
+ ...(!readOnly && (hasCUDAccess || isLockedEditable)
+ ? [
+ {
+ id: "delete-separator",
+ type: "separator" as const,
+ },
+ {
+ type: "item" as const,
+ id: "delete",
+ title: "Delete",
+ icon: TrashIcon,
+ variant: "destructive" as const,
+ onClick: handleDelete,
+ },
+ ]
+ : []),
+ ]}
+ >
+ {({ getTriggerProps }) => (
<button
- className="text-muted-foreground hover:text-foreground hidden group-hover:block data-[state=open]:block"
+ className="text-muted-foreground hover:text-foreground hidden group-hover:block aria-expanded:block"
aria-label="Widget actions"
+ {...getTriggerProps()}
>
<MoreVerticalIcon size={16} />
</button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {tableView && (
- <>
- <DropdownMenuItem
- onClick={handleViewAsTable}
- title={viewAsTableHint?.title}
- >
- <TableIcon className="mr-2 h-4 w-4" />
- <span className="flex flex-col">
- <span>View as table</span>
- {viewAsTableHint && (
- <span className="text-muted-foreground text-xs">
- {viewAsTableHint.count} filter
- {viewAsTableHint.count === 1 ? "" : "s"} not shown in
- the table
- </span>
- )}
- </span>
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- </>
- )}
- <DropdownMenuItem onClick={handleCopyToClipboard}>
- <CopyIcon className="mr-2 h-4 w-4" />
- Copy widget
- </DropdownMenuItem>
- {onDuplicateWidget && (
- <DropdownMenuItem
- onClick={() =>
- onDuplicateWidget(placement, widgetExportSource)
- }
- >
- <CopyPlusIcon className="mr-2 h-4 w-4" />
- Clone
- </DropdownMenuItem>
- )}
- <DropdownMenuSeparator />
- <DropdownMenuItem onClick={handleDownloadJson}>
- <FileJsonIcon className="mr-2 h-4 w-4" />
- Download as JSON
- </DropdownMenuItem>
- {/* Chart data download needs the query result to have loaded */}
- <DropdownMenuItem
- disabled={queryResult.isPending}
- onClick={() =>
- downloadChartDataCsv(transformedData, widget.data.name)
- }
- >
- <DownloadIcon className="mr-2 h-4 w-4" />
- Download data as CSV
- </DropdownMenuItem>
- {!readOnly && (hasCUDAccess || isLockedEditable) && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- onClick={handleDelete}
- className="text-destructive focus:text-destructive"
- >
- <TrashIcon className="mr-2 h-4 w-4" />
- Delete
- </DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
+ )}
</DropdownMenu>
</div>
</div>
diff --git a/web/src/features/widgets/components/PresetDashboardWidget.tsx b/web/src/features/widgets/components/PresetDashboardWidget.tsx
index f674629e3a..2eac2fe502 100644
--- a/web/src/features/widgets/components/PresetDashboardWidget.tsx
+++ b/web/src/features/widgets/components/PresetDashboardWidget.tsx
@@ -19,13 +19,7 @@ import {
import { buildPresetExport } from "@/src/features/dashboard/utils/dashboard-import-export";
import { copyTextToClipboard } from "@/src/utils/clipboard";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "@/src/components/ui/dropdown-menu";
+import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
/**
* A "preset" dashboard placement: renders a registered curated component by
@@ -241,46 +235,58 @@ export function PresetDashboardWidget({
</div>
{/* The menu (copy) stays available on read-only surfaces like Home —
only the edit affordances (drag, delete) are gated. */}
- <div className="bg-background/95 absolute top-2 right-2 z-10 hidden items-center gap-2 rounded-md border px-1.5 py-1 shadow-sm group-hover:flex has-data-[state=open]:flex">
+ <div className="bg-background/95 absolute top-2 right-2 z-10 hidden items-center gap-2 rounded-md border px-1.5 py-1 shadow-sm group-hover:flex has-aria-expanded:flex">
{!readOnly && (hasCUDAccess || isLockedEditable) && (
<GripVerticalIcon
size={16}
className="drag-handle text-muted-foreground hover:text-foreground hidden cursor-grab active:cursor-grabbing lg:block"
/>
)}
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <DropdownMenu
+ placement="bottom-end"
+ items={[
+ {
+ type: "item",
+ id: "copy",
+ title: "Copy card",
+ icon: CopyIcon,
+ onClick: handleCopyToClipboard,
+ },
+ ...(onDuplicatePreset
+ ? [
+ {
+ type: "item" as const,
+ id: "clone",
+ title: "Clone",
+ icon: CopyPlusIcon,
+ onClick: () => onDuplicatePreset(placement),
+ },
+ ]
+ : []),
+ ...(!readOnly && (hasCUDAccess || isLockedEditable)
+ ? [
+ { id: "delete-separator", type: "separator" as const },
+ {
+ type: "item" as const,
+ id: "delete",
+ title: "Delete",
+ icon: TrashIcon,
+ variant: "destructive" as const,
+ onClick: handleDelete,
+ },
+ ]
+ : []),
+ ]}
+ >
+ {({ getTriggerProps }) => (
<button
className="text-muted-foreground hover:text-foreground"
aria-label="Widget actions"
+ {...getTriggerProps()}
>
<MoreVerticalIcon size={16} />
</button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem onClick={handleCopyToClipboard}>
- <CopyIcon className="mr-2 h-4 w-4" />
- Copy card
- </DropdownMenuItem>
- {onDuplicatePreset && (
- <DropdownMenuItem onClick={() => onDuplicatePreset(placement)}>
- <CopyPlusIcon className="mr-2 h-4 w-4" />
- Clone
- </DropdownMenuItem>
- )}
- {!readOnly && (hasCUDAccess || isLockedEditable) && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- onClick={handleDelete}
- className="text-destructive focus:text-destructive"
- >
- <TrashIcon className="mr-2 h-4 w-4" />
- Delete
- </DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
+ )}
</DropdownMenu>
</div>
</div>