Skip to content

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

refactor(web): Convert some components to the dialog / popover controller pattern (#15893)

Ben Bachemb49d8c5f5c11
diff --git a/.agents/skills/react-component-guidelines/SKILL.md b/.agents/skills/react-component-guidelines/SKILL.md
index 098398ec45..d66e878f0c 100644
--- a/.agents/skills/react-component-guidelines/SKILL.md
+++ b/.agents/skills/react-component-guidelines/SKILL.md
@@ -36,6 +36,13 @@ Components are useful because they act as an encapsulated unit and therefore pro
- Margin should be applied by the parent component, not contained in a component. The child component should only define the inner spacing of itself and its contents.
- It's bad practice to have a component that returns `null` or `undefined`. Most of the time this suggests that the condition that leads to this state should be handled by the parent component instead, often this can be done in a way close to the current component by using a hook or a HOC.
+## Overlays
+
+- Compose overlays with `DropdownMenuController`, `PopoverController`, or `DialogController`. Trigger presentation should remain in the caller and not be abstracted. If additional behavior is needed, add a feature-specific wrapper that handles things such as permissions, analytics, mutations, or other workflow behavior that should be shared.
+- Keep the controller components outside transient overlays that can trigger it. A popover or dialog opened from a dropdown item must not be owned by `DropdownMenuContent`, which unmounts when the dropdown closes.
+- Consume the controller's render-prop controls instead of duplicating their shape. Do not move the passed `Trigger` into components. Abstract trigger presentation through a ref-forwarding component with explicit variants, while keeping `<Trigger asChild>` at each call site.
+- Compose `<Trigger asChild>` in the caller around a semantic child that forwards its ref and injected props. For example, use `DropdownMenuItem` directly rather than nesting a `Button` inside it.
+
## Deterministic Styling
- Avoid conflicting style names in CSS definitions, even though they might be removed by tailwind-merge or the likes. Make the variants explicit instead by using cva, conditions or lookup tables.
diff --git a/web/src/components/table/ValueCell.tsx b/web/src/components/table/ValueCell.tsx
index cb5f21d698..302709d35e 100644
--- a/web/src/components/table/ValueCell.tsx
+++ b/web/src/components/table/ValueCell.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { memo, type JSX, useState } from "react";
import { useRouter } from "next/router";
import { type Row } from "@tanstack/react-table";
@@ -9,12 +8,11 @@ import { MediaReferenceTag } from "@/src/components/ui/media/MediaReferenceTag";
import { copyTextToClipboard } from "@/src/utils/clipboard";
import { Button } from "@/src/components/ui/button";
import {
- DropdownMenu,
- DropdownMenuContent,
+ DropdownMenuController,
DropdownMenuItem,
DropdownMenuSeparator,
- DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
+import { cn } from "@/src/utils/tailwind";
import {
buildEventsTablePathForMetadataFilter,
type MetadataFilterOperator,
@@ -209,7 +207,7 @@ function resolveKeyPath(row: Row<JsonTableRow>): string {
* only when `metadataActions` is provided, so `useRouter` stays off the hot
* path for the (far more numerous) input/output JSON cells.
*/
-function ValueCellActionsMenu({
+function ValueCellActionsMenuContent({
row,
metadataActions,
}: {
@@ -275,69 +273,51 @@ function ValueCellActionsMenu({
const excludeFilterText = `metadata.${metadataKey} ${excludeOperator} ${displayValue}`;
return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
- size="icon"
- aria-label="Value actions"
- title="Actions"
- className="bg-background/80 hover:bg-background absolute top-1/2 right-1 h-4 w-4 -translate-y-1/2 border p-0 opacity-0 shadow-xs transition-opacity duration-200 group-hover:opacity-100 data-[state=open]:opacity-100"
- onClick={(e) => e.stopPropagation()}
- >
- <EllipsisVertical className="h-3 w-3" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="end"
- className="max-w-[320px]"
- onClick={(e) => e.stopPropagation()}
- >
- <DropdownMenuItem className="text-xs" onSelect={handleCopyData}>
- <Copy className="mr-2 h-3.5 w-3.5 shrink-0" />
- {hasChildren ? "Copy structure" : "Copy value"}
- </DropdownMenuItem>
- <DropdownMenuItem className="text-xs" onSelect={handleCopyPath}>
- <Copy className="mr-2 h-3.5 w-3.5 shrink-0" />
- Copy path
- </DropdownMenuItem>
- {isScalarLeaf && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- className="text-xs"
- onSelect={() => navigateWithFilter(includeOperator)}
- >
- <Filter className="mr-2 h-3.5 w-3.5 shrink-0" />
- <span className="flex min-w-0 flex-col">
- <span>Include in filter</span>
- <span
- className="text-muted-foreground truncate font-mono"
- title={includeFilterText}
- >
- {includeFilterText}
- </span>
+ <>
+ <DropdownMenuItem className="text-xs" onSelect={handleCopyData}>
+ <Copy className="mr-2 h-3.5 w-3.5 shrink-0" />
+ {hasChildren ? "Copy structure" : "Copy value"}
+ </DropdownMenuItem>
+ <DropdownMenuItem className="text-xs" onSelect={handleCopyPath}>
+ <Copy className="mr-2 h-3.5 w-3.5 shrink-0" />
+ Copy path
+ </DropdownMenuItem>
+ {isScalarLeaf && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="text-xs"
+ onSelect={() => navigateWithFilter(includeOperator)}
+ >
+ <Filter className="mr-2 h-3.5 w-3.5 shrink-0" />
+ <span className="flex min-w-0 flex-col">
+ <span>Include in filter</span>
+ <span
+ className="text-muted-foreground truncate font-mono"
+ title={includeFilterText}
+ >
+ {includeFilterText}
</span>
- </DropdownMenuItem>
- <DropdownMenuItem
- className="text-xs"
- onSelect={() => navigateWithFilter(excludeOperator)}
- >
- <FilterX className="mr-2 h-3.5 w-3.5 shrink-0" />
- <span className="flex min-w-0 flex-col">
- <span>Exclude from filter</span>
- <span
- className="text-muted-foreground truncate font-mono"
- title={excludeFilterText}
- >
- {excludeFilterText}
- </span>
+ </span>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ className="text-xs"
+ onSelect={() => navigateWithFilter(excludeOperator)}
+ >
+ <FilterX className="mr-2 h-3.5 w-3.5 shrink-0" />
+ <span className="flex min-w-0 flex-col">
+ <span>Exclude from filter</span>
+ <span
+ className="text-muted-foreground truncate font-mono"
+ title={excludeFilterText}
+ >
+ {excludeFilterText}
</span>
- </DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
+ </span>
+ </DropdownMenuItem>
+ </>
+ )}
+ </>
);
}
@@ -503,7 +483,34 @@ export const ValueCell = memo(
{/* Hover affordance: a one-click copy by default, or an actions menu
(copy + filter shortcuts) in metadata views. */}
{metadataActions ? (
- <ValueCellActionsMenu row={row} metadataActions={metadataActions} />
+ <DropdownMenuController
+ align="end"
+ maxWidth="320px"
+ renderMenu={() => (
+ <ValueCellActionsMenuContent
+ row={row}
+ metadataActions={metadataActions}
+ />
+ )}
+ >
+ {({ isOpen, Trigger }) => (
+ <Trigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ aria-label="Value actions"
+ title="Actions"
+ className={cn(
+ "bg-background/80 hover:bg-background absolute top-1/2 right-1 h-4 w-4 -translate-y-1/2 border p-0 opacity-0 shadow-xs transition-opacity duration-200 group-hover:opacity-100",
+ isOpen && "opacity-100",
+ )}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <EllipsisVertical className="h-3 w-3" />
+ </Button>
+ </Trigger>
+ )}
+ </DropdownMenuController>
) : (
<Button
variant="ghost"
diff --git a/web/src/components/table/use-cases/score-configs.tsx b/web/src/components/table/use-cases/score-configs.tsx
index 2a535408be..7b469a66b0 100644
--- a/web/src/components/table/use-cases/score-configs.tsx
+++ b/web/src/components/table/use-cases/score-configs.tsx
@@ -17,7 +17,7 @@ import {
isCategoricalDataType,
isNumericDataType,
} from "@/src/features/scores/lib/helpers";
-import { Edit, MoreVertical } from "lucide-react";
+import { Archive, Edit, MoreVertical } from "lucide-react";
import { Button } from "@/src/components/ui/button";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
import { SettingsTableCard } from "@/src/components/layouts/settings-table-card";
@@ -28,7 +28,7 @@ import {
DropdownMenuContent,
DropdownMenuItem,
} from "@/src/components/ui/dropdown-menu";
-import { ArchiveScoreConfigButton } from "@/src/features/score-configs/components/ArchiveScoreConfigButton";
+import { ArchiveScoreConfigPopoverController } from "@/src/features/score-configs/components/ArchiveScoreConfigButton";
import { UpsertScoreConfigDialog } from "@/src/features/score-configs/components/UpsertScoreConfigDialog";
type ScoreConfigTableRow = {
@@ -181,31 +181,44 @@ export function ScoreConfigsTable({ projectId }: { projectId: string }) {
const { id: configId, isArchived, name } = row.original;
return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost">
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
- key={configId}
- aria-label="edit"
- onClick={() => setEditConfigId(configId)}
- >
- <Edit className="mr-2 h-4 w-4" />
- Edit
- </DropdownMenuItem>
- <DropdownMenuItem asChild key="archive">
- <ArchiveScoreConfigButton
- configId={configId}
- projectId={projectId}
- isArchived={isArchived}
- name={name}
- />
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ <ArchiveScoreConfigPopoverController
+ configId={configId}
+ projectId={projectId}
+ isArchived={isArchived}
+ name={name}
+ >
+ {({ Anchor, disabled, openPopover }) => (
+ <DropdownMenu>
+ <Anchor asChild>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost">
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ </Anchor>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ key={configId}
+ aria-label="edit"
+ onClick={() => setEditConfigId(configId)}
+ >
+ <Edit className="mr-2 h-4 w-4" />
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ key="archive"
+ disabled={disabled !== undefined}
+ title={disabled?.reason}
+ onClick={(event) => event.stopPropagation()}
+ onSelect={openPopover}
+ >
+ <Archive className="mr-2 h-4 w-4" />
+ Archive
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
+ </ArchiveScoreConfigPopoverController>
);
},
},
diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx
index e76d2b6ecb..dcf229f4a8 100644
--- a/web/src/components/ui/dialog.tsx
+++ b/web/src/components/ui/dialog.tsx
@@ -171,6 +171,41 @@ const DialogContent = React.forwardRef<
);
DialogContent.displayName = DialogPrimitive.Content.displayName;
+/**
+ * Owns dialog open state while callers retain trigger and content presentation.
+ * Use the supplied Trigger to preserve Radix behavior.
+ */
+type DialogControllerProps = {
+ children: (control: {
+ isOpen: boolean;
+ Trigger: typeof DialogTrigger;
+ }) => React.ReactNode;
+ closeOnInteractionOutside: boolean;
+ renderContent: (control: { closeDialog: () => void }) => React.ReactNode;
+ size: React.ComponentProps<typeof DialogContent>["size"];
+};
+
+const DialogController = ({
+ children,
+ closeOnInteractionOutside,
+ renderContent,
+ size,
+}: DialogControllerProps) => {
+ const [isOpen, setIsOpen] = React.useState(false);
+
+ return (
+ <Dialog open={isOpen} onOpenChange={setIsOpen}>
+ {children({ isOpen, Trigger: DialogTrigger })}
+ <DialogContent
+ size={size}
+ closeOnInteractionOutside={closeOnInteractionOutside}
+ >
+ {renderContent({ closeDialog: () => setIsOpen(false) })}
+ </DialogContent>
+ </Dialog>
+ );
+};
+
const dialogHeaderVariants = cva(
"bg-modal sticky top-0 z-30 flex shrink-0 flex-col space-y-1.5 rounded-t-lg p-4",
{
@@ -287,6 +322,7 @@ DialogDescription.displayName = DialogPrimitive.Description.displayName;
export {
Dialog,
+ DialogController,
DialogPortal,
DialogOverlay,
DialogClose,
diff --git a/web/src/components/ui/dropdown-menu.tsx b/web/src/components/ui/dropdown-menu.tsx
index c0c2712665..dbe1126df6 100644
--- a/web/src/components/ui/dropdown-menu.tsx
+++ b/web/src/components/ui/dropdown-menu.tsx
@@ -252,6 +252,48 @@ const DropdownMenuContent = React.forwardRef<
);
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
+/**
+ * Owns dropdown open state while callers retain trigger and menu presentation.
+ * Use the supplied primitives in each render prop to preserve Radix behavior.
+ */
+type DropdownMenuControllerProps = {
+ align: React.ComponentProps<typeof DropdownMenuContent>["align"];
+ children: (control: {
+ isOpen: boolean;
+ Trigger: typeof DropdownMenuTrigger;
+ }) => React.ReactNode;
+ maxWidth?: React.CSSProperties["maxWidth"];
+ /** Customizes Radix focus restoration after the menu closes. */
+ onCloseAutoFocus?: React.ComponentProps<
+ typeof DropdownMenuContent
+ >["onCloseAutoFocus"];
+ renderMenu: () => React.ReactNode;
+};
+
+const DropdownMenuController = ({
+ align,
+ children,
+ maxWidth,
+ onCloseAutoFocus,
+ renderMenu,
+}: DropdownMenuControllerProps) => {
+ const [isOpen, setIsOpen] = React.useState(false);
+
+ return (
+ <DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
+ {children({ isOpen, Trigger: DropdownMenuTrigger })}
+ <DropdownMenuContent
+ align={align}
+ style={maxWidth === undefined ? undefined : { maxWidth }}
+ onClick={(event) => event.stopPropagation()}
+ onCloseAutoFocus={onCloseAutoFocus}
+ >
+ {renderMenu()}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+};
+
/**
* Prefer `DropdownMenuItemWithSecondaryAction` for items that do not require JSX content.
*/
@@ -545,6 +587,7 @@ DropdownMenuShortcut.displayName = "DropdownMenuShortcut";
export {
DropdownMenu,
+ DropdownMenuController,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
diff --git a/web/src/components/ui/popover.tsx b/web/src/components/ui/popover.tsx
index 60bbdc5be5..0cb690c4b0 100644
--- a/web/src/components/ui/popover.tsx
+++ b/web/src/components/ui/popover.tsx
@@ -14,6 +14,8 @@ const Popover = PopoverPrimitive.Root;
const PopoverTrigger = PopoverPrimitive.Trigger;
+const PopoverAnchor = PopoverPrimitive.Anchor;
+
const PopoverContent = React.forwardRef<
React.ComponentRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
@@ -62,8 +64,70 @@ const PopoverContent = React.forwardRef<
);
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
-const PopoverClose = PopoverPrimitive.Close;
+/**
+ * Owns popover open state while callers retain trigger and content presentation.
+ * Use the supplied Trigger to preserve Radix behavior.
+ */
+type PopoverControllerProps = {
+ align: React.ComponentProps<typeof PopoverContent>["align"];
+ children: (control: {
+ disabled: boolean;
+ isOpen: boolean;
+ openPopover: () => void;
+ Anchor: typeof PopoverAnchor;
+ Trigger: typeof PopoverTrigger;
+ }) => React.ReactNode;
+ contentClassName: string;
+ disabled: boolean;
+ modal: boolean;
+ onOpenChange?: (isOpen: boolean) => void;
+ renderContent: (control: { closePopover: () => void }) => React.ReactNode;
+};
-const PopoverAnchor = PopoverPrimitive.Anchor;
+const PopoverController = ({
+ align,
+ children,
+ contentClassName,
+ disabled,
+ modal,
+ onOpenChange,
+ renderContent,
+}: PopoverControllerProps) => {
+ const [isOpen, setIsOpen] = React.useState(false);
+ const handleOpenChange = (nextIsOpen: boolean) => {
+ if (nextIsOpen && disabled) return;
+
+ setIsOpen(nextIsOpen);
+ onOpenChange?.(nextIsOpen);
+ };
+
+ return (
+ <Popover modal={modal} open={isOpen} onOpenChange={handleOpenChange}>
+ {children({
+ disabled,
+ isOpen,
+ openPopover: () => handleOpenChange(true),
+ Anchor: PopoverAnchor,
+ Trigger: PopoverTrigger,
+ })}
+ <PopoverContent
+ align={align}
+ className={contentClassName}
+ onClick={(event) => event.stopPropagation()}
+ >
+ {renderContent({ closePopover: () => setIsOpen(false) })}
+ </PopoverContent>
+ </Popover>
+ );
+};
+
+const PopoverClose = PopoverPrimitive.Close;
-export { Popover, PopoverTrigger, PopoverContent, PopoverClose, PopoverAnchor };
+export {
+ Popover,
+ PopoverController,
+ PopoverTrigger,
+ PopoverContent,
+ PopoverClose,
+ PopoverAnchor,
+};
diff --git a/web/src/features/background-migrations/components/background-migrations.tsx b/web/src/features/background-migrations/components/background-migrations.tsx
index cce931490c..8529ba3226 100644
--- a/web/src/features/background-migrations/components/background-migrations.tsx
+++ b/web/src/features/background-migrations/components/background-migrations.tsx
@@ -3,9 +3,11 @@ import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { api } from "@/src/utils/api";
import { type BackgroundMigration } from "@langfuse/shared";
-import { RetryBackgroundMigration } from "@/src/features/background-migrations/components/retry-background-migration";
+import { RetryBackgroundMigrationPopoverController } from "@/src/features/background-migrations/components/retry-background-migration";
import { StatusBadge } from "@/src/components/ui/StatusBadge/StatusBadge";
import Page from "@/src/components/layouts/page";
+import { Button } from "@/src/components/ui/button";
+import { RotateCcw } from "lucide-react";
export default function BackgroundMigrationsTable() {
const backgroundMigrations = api.backgroundMigrations.all.useQuery();
@@ -73,10 +75,18 @@ export default function BackgroundMigrationsTable() {
const name = row.row.original.name;
const isRetryable = row.row.original.failedAt !== null;
return (
- <RetryBackgroundMigration
+ <RetryBackgroundMigrationPopoverController
backgroundMigrationName={name}
isRetryable={isRetryable}
- />
+ >
+ {({ disabled, Trigger }) => (
+ <Trigger asChild>
+ <Button variant="ghost" size="xs" disabled={disabled}>
+ <RotateCcw className="h-4 w-4" />
+ </Button>
+ </Trigger>
+ )}
+ </RetryBackgroundMigrationPopoverController>
);
},
},
diff --git a/web/src/features/background-migrations/components/retry-background-migration.tsx b/web/src/features/background-migrations/components/retry-background-migration.tsx
index e1604ac773..c0d39b30e3 100644
--- a/web/src/features/background-migrations/components/retry-background-migration.tsx
+++ b/web/src/features/background-migrations/components/retry-background-migration.tsx
@@ -1,26 +1,24 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { Button } from "@/src/components/ui/button";
import { api } from "@/src/utils/api";
import { useState } from "react";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/src/components/ui/popover";
+import type * as React from "react";
+import { PopoverController } from "@/src/components/ui/popover";
import { Input } from "@/src/components/ui/input";
import { Label } from "@/src/components/ui/label";
-import { RotateCcw } from "lucide-react";
import { toast } from "sonner";
-export function RetryBackgroundMigration({
- backgroundMigrationName,
- isRetryable,
-}: {
+type RetryBackgroundMigrationPopoverControllerProps = {
backgroundMigrationName: string;
isRetryable: boolean;
-}) {
+ children: React.ComponentProps<typeof PopoverController>["children"];
+};
+
+export function RetryBackgroundMigrationPopoverController({
+ backgroundMigrationName,
+ isRetryable,
+ children,
+}: RetryBackgroundMigrationPopoverControllerProps) {
const utils = api.useUtils();
- const [isOpen, setIsOpen] = useState(false);
const [adminApiKey, setAdminApiKey] = useState("");
const [isLoading, setIsLoading] = useState(false);
@@ -29,8 +27,6 @@ export function RetryBackgroundMigration({
onSuccess: () => {
utils.backgroundMigrations.invalidate();
toast.success("Migration scheduled for retry");
- setIsOpen(false);
- setAdminApiKey("");
},
onError: (error) => {
toast.error(error?.message || "Failed to retry migration");
@@ -40,7 +36,7 @@ export function RetryBackgroundMigration({
},
});
- const handleRetry = async () => {
+ const handleRetry = async (closePopover: () => void) => {
if (!adminApiKey.trim()) {
toast.error("Admin API key is required");
return;
@@ -51,79 +47,84 @@ export function RetryBackgroundMigration({
name: backgroundMigrationName,
adminApiKey: "Bearer " + adminApiKey.trim(),
});
+ closePopover();
+ setAdminApiKey("");
} catch (_e) {
// Error handled in onError
}
};
return (
- <Popover open={isOpen} onOpenChange={() => setIsOpen((prev) => !prev)}>
- <PopoverTrigger asChild>
- <Button variant="ghost" size="xs" disabled={!isRetryable}>
- <RotateCcw className="h-4 w-4" />
- </Button>
- </PopoverTrigger>
- <PopoverContent className="w-96">
- <h2 className="mb-3 font-bold">Retry Background Migration</h2>
- <p className="mb-4 text-sm">
- This action schedules the migration for retry. Restart the worker
- containers to re-initiate the migration.
- </p>
-
- <div className="mb-4">
- <Label htmlFor="admin-api-key" className="text-sm font-bold">
- Admin API Key
- </Label>
- <Input
- id="admin-api-key"
- type="password"
- placeholder="Enter admin API key"
- value={adminApiKey}
- onChange={(e) => setAdminApiKey(e.target.value)}
- className="mt-1"
- disabled={isLoading}
- autoComplete="off"
- inputMode="text"
- name="admin-api-key"
- />
- <p className="text-muted-foreground mt-1 text-xs">
- Required for security. This key must match your ADMIN_API_KEY
- environment variable{" ("}
- <a
- href="https://langfuse.com/self-hosting/administration/organization-management-api#authentication"
- target="_blank"
- rel="noopener noreferrer"
- className="text-muted-foreground hover:text-primary underline"
- >
- Docs
- </a>
- ).
+ <PopoverController
+ align="center"
+ contentClassName="w-96"
+ disabled={!isRetryable}
+ modal={false}
+ renderContent={({ closePopover }) => (
+ <>
+ <h2 className="mb-3 font-bold">Retry Background Migration</h2>
+ <p className="mb-4 text-sm">
+ This action schedules the migration for retry. Restart the worker
+ containers to re-initiate the migration.
</p>
- </div>
- <div className="flex justify-end space-x-2">
- <Button
- type="button"
- variant="outline"
- onClick={() => {
- setIsOpen(false);
- setAdminApiKey("");
- }}
- disabled={isLoading}
- >
- Cancel
- </Button>
- <Button
- type="button"
- variant="default"
- loading={isLoading}
- onClick={handleRetry}
- disabled={isLoading}
- >
- Retry Migration
- </Button>
- </div>
- </PopoverContent>
- </Popover>
+ <div className="mb-4">
+ <Label htmlFor="admin-api-key" className="text-sm font-bold">
+ Admin API Key
+ </Label>
+ <Input
+ id="admin-api-key"
+ type="password"
+ placeholder="Enter admin API key"
+ value={adminApiKey}
+ onChange={(e) => setAdminApiKey(e.target.value)}
+ className="mt-1"
+ disabled={isLoading}
+ autoComplete="off"
+ inputMode="text"
+ name="admin-api-key"
+ />
+ <p className="text-muted-foreground mt-1 text-xs">
+ Required for security. This key must match your ADMIN_API_KEY
+ environment variable{" ("}
+ <a
+ href="https://langfuse.com/self-hosting/administration/organization-management-api#authentication"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-muted-foreground hover:text-primary underline"
+ >
+ Docs
+ </a>
+ ).
+ </p>
+ </div>
+
+ <div className="flex justify-end space-x-2">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => {
+ closePopover();
+ setAdminApiKey("");
+ }}
+ disabled={isLoading}
+ >
+ Cancel
+ </Button>
+ <Button
+ type="button"
+ variant="default"
+ loading={isLoading}
+ onClick={() => handleRetry(closePopover)}
+ disabled={isLoading}
+ >
+ Retry Migration
+ </Button>
+ </div>
+ </>
+ )}
+ >
+ {children}
+ </PopoverController>
);
}
diff --git a/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx b/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx
index a355a871cd..98431809e3 100644
--- a/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx
+++ b/web/src/features/events/components/outlier-strip/EventsOutlierStrip.tsx
@@ -1,15 +1,13 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
-import { useMemo, useRef, useState } from "react";
+import { forwardRef, useMemo, useRef, useState } from "react";
+import type * as React from "react";
import { ChevronDown } from "lucide-react";
import { type FilterState, type QueryType } from "@langfuse/shared";
import { api } from "@/src/utils/api";
import { cn } from "@/src/utils/tailwind";
import { useElementSize } from "@/src/hooks/useElementSize";
import {
- DropdownMenu,
- DropdownMenuContent,
+ DropdownMenuController,
DropdownMenuItem,
- DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
import { toChartFilters } from "@/src/features/chart-view/lib/chartFilterCompatibility";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
@@ -59,6 +57,41 @@ const MODE_OPTIONS: StripMode[] = ["count", "cost", "latency"];
const modeLabel = (mode: StripMode): string =>
OUTLIER_STRIP_METRICS[mode].shortLabel;
+type OutlierDropdownButtonVariant = "mode" | "aggregation";
+
+const outlierDropdownButtonClasses: Record<
+ OutlierDropdownButtonVariant,
+ string
+> = {
+ mode: "text-foreground hover:text-muted-foreground font-bold",
+ aggregation:
+ "text-muted-foreground hover:text-foreground underline-offset-2 hover:underline",
+};
+
+const OutlierDropdownButton = forwardRef<
+ HTMLButtonElement,
+ {
+ ariaLabel: string;
+ label: string;
+ variant: OutlierDropdownButtonVariant;
+ } & Omit<React.ComponentPropsWithoutRef<"button">, "aria-label" | "className">
+>(({ ariaLabel, label, variant, ...buttonProps }, ref) => (
+ <button
+ {...buttonProps}
+ ref={ref}
+ type="button"
+ aria-label={ariaLabel}
+ className={cn(
+ "flex items-center gap-0.5 text-[13px] leading-none",
+ outlierDropdownButtonClasses[variant],
+ )}
+ >
+ {label}
+ <ChevronDown className="h-2.5 w-2.5" />
+ </button>
+));
+OutlierDropdownButton.displayName = "OutlierDropdownButton";
+
/**
* Prevent Radix's close-refocus ONLY after a pointer-driven selection — the
* programmatic refocus renders as a keyboard-style outline on the trigger.
@@ -82,32 +115,22 @@ const usePointerSelectionFocusGuard = () => {
};
};
-const AggDropdown = ({
- metricLabel,
- value,
+const AggDropdownController = ({
+ children,
options,
onChange,
}: {
- metricLabel: string;
- value: OutlierStripAggKey;
+ children: React.ComponentProps<typeof DropdownMenuController>["children"];
options: readonly OutlierStripAggKey[];
onChange: (agg: OutlierStripAggKey) => void;
}) => {
const focusGuard = usePointerSelectionFocusGuard();
return (
- <span className="flex items-baseline gap-1">
- <DropdownMenu>
- <DropdownMenuTrigger
- aria-label={`${metricLabel} aggregation: ${value}`}
- className="text-muted-foreground hover:text-foreground flex items-center gap-0.5 text-xs leading-none underline-offset-2 hover:underline"
- >
- {value}
- <ChevronDown className="h-2.5 w-2.5" />
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="start"
- onCloseAutoFocus={focusGuard.onCloseAutoFocus}
- >
+ <DropdownMenuController
+ align="start"
+ onCloseAutoFocus={focusGuard.onCloseAutoFocus}
+ renderMenu={() => (
+ <>
{options.map((agg) => (
<DropdownMenuItem
key={agg}
@@ -120,50 +143,47 @@ const AggDropdown = ({
{agg}
</DropdownMenuItem>
))}
- </DropdownMenuContent>
- </DropdownMenu>
- </span>
+ </>
+ )}
+ >
+ {children}
+ </DropdownMenuController>
);
};
-const ModeDropdown = ({
- value,
+const ModeDropdownController = ({
+ children,
options,
onChange,
}: {
- value: StripMode;
+ children: React.ComponentProps<typeof DropdownMenuController>["children"];
options: StripMode[];
onChange: (mode: StripMode) => void;
}) => {
const focusGuard = usePointerSelectionFocusGuard();
return (
- <DropdownMenu>
- <DropdownMenuTrigger
- aria-label={`Chart mode: ${modeLabel(value)}`}
- // Same typography as the Table/Chart tabs (toggleVariants + text-xs).
- className="text-foreground hover:text-muted-foreground flex items-center gap-0.5 text-xs leading-none font-bold"
- >
- {modeLabel(value)}
- <ChevronDown className="h-2.5 w-2.5" />
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="start"
- onCloseAutoFocus={focusGuard.onCloseAutoFocus}
- >
- {options.map((mode) => (
- <DropdownMenuItem
- key={mode}
- onClick={(event) => {
- focusGuard.markPointerSelection(event);
- onChange(mode);
- }}
- className="text-xs"
- >
- {modeLabel(mode)}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
+ <DropdownMenuController
+ align="start"
+ onCloseAutoFocus={focusGuard.onCloseAutoFocus}
+ renderMenu={() => (
+ <>
+ {options.map((mode) => (
+ <DropdownMenuItem
+ key={mode}
+ onClick={(event) => {
+ focusGuard.markPointerSelection(event);
+ onChange(mode);
+ }}
+ className="text-xs"
+ >
+ {modeLabel(mode)}
+ </DropdownMenuItem>
+ ))}
+ </>
+ )}
+ >
+ {children}
+ </DropdownMenuController>
);
};
@@ -393,11 +413,20 @@ export function EventsOutlierStrip({
{!canApplyFilters ? (
<div>
<div className="flex items-baseline gap-1.5">
- <ModeDropdown
- value={mode}
+ <ModeDropdownController
options={MODE_OPTIONS}
onChange={handleModeChange}
- />
+ >
+ {({ Trigger }) => (
+ <Trigger asChild>
+ <OutlierDropdownButton
+ ariaLabel={`Chart mode: ${modeLabel(mode)}`}
+ label={modeLabel(mode)}
+ variant="mode"
+ />
+ </Trigger>
+ )}
+ </ModeDropdownController>
</div>
<OutlierBarStrip
className="mt-1.5"
@@ -428,21 +457,40 @@ export function EventsOutlierStrip({
)}
>
<div className="flex items-baseline gap-1.5">
- <ModeDropdown
- value={mode}
+ <ModeDropdownController
options={MODE_OPTIONS}
onChange={handleModeChange}
- />
+ >
+ {({ Trigger }) => (
+ <Trigger asChild>
+ <OutlierDropdownButton
+ ariaLabel={`Chart mode: ${modeLabel(mode)}`}
+ label={modeLabel(mode)}
+ variant="mode"
+ />
+ </Trigger>
+ )}
+ </ModeDropdownController>
{/* The bar's aggregate must be legible where there is a
choice (p95 vs avg); single-option metrics are
unambiguous and render no aggregation label. */}
{aggOptions.length > 1 && (
- <AggDropdown
- metricLabel={def.shortLabel}
- value={aggregation}
+ <AggDropdownController
options={aggOptions}
onChange={(agg) => setAggregation(mode, agg)}
- />
+ >
+ {({ Trigger }) => (
+ <span className="flex items-baseline gap-1">
+ <Trigger asChild>
+ <OutlierDropdownButton
+ ariaLabel={`${def.shortLabel} aggregation: ${aggregation}`}
+ label={aggregation}
+ variant="aggregation"
+ />
+ </Trigger>
+ </span>
+ )}
+ </AggDropdownController>
)}
</div>
<OutlierBarStrip
diff --git a/web/src/features/prompts/components/PromptVersionDiffDialog.tsx b/web/src/features/prompts/components/PromptVersionDiffDialog.tsx
index 49fa56bb63..4d1c03398b 100644
--- a/web/src/features/prompts/components/PromptVersionDiffDialog.tsx
+++ b/web/src/features/prompts/components/PromptVersionDiffDialog.tsx
@@ -1,25 +1,18 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
-import React from "react";
import { Button } from "@/src/components/ui/button";
import {
- Dialog,
DialogBody,
- DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
- DialogTrigger,
} from "@/src/components/ui/dialog";
import { type Prompt } from "@langfuse/shared";
import DiffViewer from "@/src/components/DiffViewer";
-import { FileDiffIcon } from "lucide-react";
type PromptVersionDiffDialogProps = {
- isOpen: boolean;
- setIsOpen: (open: boolean) => void;
leftPrompt: Prompt;
rightPrompt: Prompt;
+ closeDialog: () => void;
};
// Create a word-based diff that preserves JSON structure
@@ -57,84 +50,51 @@ const createSmartDiff = (
};
};
-export const PromptVersionDiffDialog: React.FC<PromptVersionDiffDialogProps> = (
- props,
+export const PromptVersionDiffDialogContent = (
+ props: PromptVersionDiffDialogProps,
) => {
- const { leftPrompt, rightPrompt, isOpen, setIsOpen } = props;
+ const { leftPrompt, rightPrompt, closeDialog } = props;
return (
- <Dialog
- open={isOpen}
- onOpenChange={(open) => {
- setIsOpen(open);
- }}
- >
- <DialogTrigger asChild>
- <Button
- variant="outline"
- type="button"
- size="icon"
- className="h-7 w-7 px-0"
- onClick={(event) => {
- event.stopPropagation();
- }}
- title="Compare with selected prompt"
- >
- <FileDiffIcon className="h-4 w-4" />
- </Button>
- </DialogTrigger>
+ <>
+ <DialogHeader>
+ <DialogTitle>
+ Changes v{leftPrompt.version} → v{rightPrompt.version}
+ </DialogTitle>
- <DialogContent
- size="xl"
- // prevent event bubbling up and triggering the row's click handler
- onClick={(event) => event.stopPropagation()}
- closeOnInteractionOutside
- >
- <DialogHeader>
- <DialogTitle>
- Changes v{leftPrompt.version} → v{rightPrompt.version}
- </DialogTitle>
-
- <DialogDescription className="flex items-center gap-2">
- <span className="font-bold">Prompt {leftPrompt.name}</span>
- </DialogDescription>
- </DialogHeader>
- <DialogBody>
- <div className="space-y-6">
- <div className="space-y-4">
- <div>
- <h3 className="mb-2 text-base font-bold">Content</h3>
- <DiffViewer
- {...createSmartDiff(leftPrompt, rightPrompt)}
- oldLabel={`v${leftPrompt.version}`}
- newLabel={`v${rightPrompt.version}`}
- oldSubLabel={leftPrompt.commitMessage ?? undefined}
- newSubLabel={rightPrompt.commitMessage ?? undefined}
- />
- </div>
- <div>
- <h3 className="mb-2 text-base font-bold">Config</h3>
- <DiffViewer
- oldString={JSON.stringify(leftPrompt.config, null, 2)}
- newString={JSON.stringify(rightPrompt.config, null, 2)}
- oldLabel={`v${leftPrompt.version}`}
- newLabel={`v${rightPrompt.version}`}
- />
- </div>
+ <DialogDescription className="flex items-center gap-2">
+ <span className="font-bold">Prompt {leftPrompt.name}</span>
+ </DialogDescription>
+ </DialogHeader>
+ <DialogBody>
+ <div className="space-y-6">
+ <div className="space-y-4">
+ <div>
+ <h3 className="mb-2 text-base font-bold">Content</h3>
+ <DiffViewer
+ {...createSmartDiff(leftPrompt, rightPrompt)}
+ oldLabel={`v${leftPrompt.version}`}
+ newLabel={`v${rightPrompt.version}`}
+ oldSubLabel={leftPrompt.commitMessage ?? undefined}
+ newSubLabel={rightPrompt.commitMessage ?? undefined}
+ />
+ </div>
+ <div>
+ <h3 className="mb-2 text-base font-bold">Config</h3>
+ <DiffViewer
+ oldString={JSON.stringify(leftPrompt.config, null, 2)}
+ newString={JSON.stringify(rightPrompt.config, null, 2)}
+ oldLabel={`v${leftPrompt.version}`}
+ newLabel={`v${rightPrompt.version}`}
+ />
</div>
</div>
- </DialogBody>
+ </div>
+ </DialogBody>
- <DialogFooter>
- <Button
- onClick={() => {
- setIsOpen(false);
- }}
- >
- Close
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ <DialogFooter>
+ <Button onClick={closeDialog}>Close</Button>
+ </DialogFooter>
+ </>
);
};
diff --git a/web/src/features/prompts/components/prompt-history.tsx b/web/src/features/prompts/components/prompt-history.tsx
index 948fad14b3..8a9e8c686a 100644
--- a/web/src/features/prompts/components/prompt-history.tsx
+++ b/web/src/features/prompts/components/prompt-history.tsx
@@ -1,15 +1,18 @@
import { type RouterOutputs } from "@/src/utils/api";
import { type NextRouter, useRouter } from "next/router";
import { useState, useRef, useEffect } from "react";
-import { PromptVersionDiffDialog } from "./PromptVersionDiffDialog";
+import { PromptVersionDiffDialogContent } from "./PromptVersionDiffDialog";
import {
Timeline,
TimelineItem,
} from "@/src/features/prompts/components/timeline";
import { Badge } from "@/src/components/ui/badge";
import { CommandItem } from "@/src/components/ui/command";
+import { Button } from "@/src/components/ui/button";
+import { DialogController } from "@/src/components/ui/dialog";
import { SetPromptVersionLabels } from "@/src/features/prompts/components/SetPromptVersionLabels";
import { CommentCountIcon } from "@/src/features/comments/CommentCountIcon";
+import { FileDiffIcon } from "lucide-react";
const PromptHistoryTraceNode = (props: {
index: number;
@@ -21,7 +24,6 @@ const PromptHistoryTraceNode = (props: {
commentCounts?: Map<string, number>;
}) => {
const [isHovered, setIsHovered] = useState(false);
- const [isPromptDiffOpen, setIsPromptDiffOpen] = useState(false);
const [isLabelPopoverOpen, setIsLabelPopoverOpen] = useState(false);
const { prompt } = props;
@@ -151,20 +153,41 @@ const PromptHistoryTraceNode = (props: {
</div>
</div>
<div className="flex flex-row justify-end space-x-1">
- {(isHovered ||
- props.currentPromptVersion === prompt.version ||
- isPromptDiffOpen) &&
- (props.currentPrompt &&
- props.currentPromptVersion !== prompt.version ? (
- <PromptVersionDiffDialog
- isOpen={isPromptDiffOpen}
- setIsOpen={(open) => {
- setIsPromptDiffOpen(open);
- }}
- leftPrompt={prompt}
- rightPrompt={props.currentPrompt}
- />
- ) : null)}
+ {props.currentPrompt &&
+ props.currentPromptVersion !== prompt.version ? (
+ <DialogController
+ size="xl"
+ closeOnInteractionOutside
+ renderContent={({ closeDialog }) => (
+ <PromptVersionDiffDialogContent
+ leftPrompt={prompt}
+ rightPrompt={props.currentPrompt!}
+ closeDialog={closeDialog}
+ />
+ )}
+ >
+ {({ isOpen, Trigger }) =>
+ isHovered ||
+ props.currentPromptVersion === prompt.version ||
+ isOpen ? (
+ <Trigger asChild>
+ <Button
+ variant="outline"
+ type="button"
+ size="icon"
+ className="h-7 w-7 px-0"
+ onClick={(event) => {
+ event.stopPropagation();
+ }}
+ title="Compare with selected prompt"
+ >
+ <FileDiffIcon className="h-4 w-4" />
+ </Button>
+ </Trigger>
+ ) : null
+ }
+ </DialogController>
+ ) : null}
</div>
</div>
</div>
diff --git a/web/src/features/score-configs/components/ArchiveScoreConfigButton.tsx b/web/src/features/score-configs/components/ArchiveScoreConfigButton.tsx
index 51ba7c0015..b36c3a21c5 100644
--- a/web/src/features/score-configs/components/ArchiveScoreConfigButton.tsx
+++ b/web/src/features/score-configs/components/ArchiveScoreConfigButton.tsx
@@ -1,28 +1,31 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
-import { Archive } from "lucide-react";
import { Button } from "@/src/components/ui/button";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/src/components/ui/popover";
-import React from "react";
+import { PopoverController } from "@/src/components/ui/popover";
+import type * as React from "react";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { api } from "@/src/utils/api";
import { useEmptyScoreConfigs } from "@/src/features/scores/hooks/useEmptyConfigs";
-export const ArchiveScoreConfigButton = ({
- configId,
- projectId,
- isArchived,
- name,
-}: {
+type ArchiveScoreConfigPopoverControllerProps = {
+ children: (
+ control: Omit<
+ Parameters<React.ComponentProps<typeof PopoverController>["children"]>[0],
+ "disabled"
+ > & { disabled: { reason: string } | undefined },
+ ) => React.ReactNode;
configId: string;
projectId: string;
isArchived: boolean;
name: string;
-}) => {
+};
+
+export const ArchiveScoreConfigPopoverController = ({
+ children,
+ configId,
+ projectId,
+ isArchived,
+ name,
+}: ArchiveScoreConfigPopoverControllerProps) => {
const capture = usePostHogClientCapture();
const { emptySelectedConfigIds, setEmptySelectedConfigIds } =
useEmptyScoreConfigs();
@@ -37,56 +40,58 @@ export const ArchiveScoreConfigButton = ({
onSuccess: () => utils.scoreConfigs.invalidate(),
});
+ const disabled = hasAccess
+ ? undefined
+ : { reason: "You don't have permission to archive this score config." };
+
return (
- <Popover>
- <PopoverTrigger asChild>
- <Button
- variant="ghost"
- className="flex w-full items-center justify-start"
- disabled={!hasAccess}
- onClick={(e) => {
- e.stopPropagation();
- capture("score_configs:archive_form_open");
- }}
- >
- <Archive className="mr-2 h-4 w-4"></Archive>
- Archive
- </Button>
- </PopoverTrigger>
- <PopoverContent
- onClick={(e) => e.stopPropagation()}
- className="max-w-[500px]"
- >
- <h2 className="mb-3 font-bold">
- {isArchived ? "Restore config" : "Archive config"}
- </h2>
- <p className="mb-3 text-sm">
- Your config is currently{" "}
- {isArchived
- ? `archived. Restore if you want to use "${name}" in annotation again.`
- : `active. Archive if you no longer want to use "${name}" in annotation. Historic "${name}" scores will still be shown and can be deleted. You can restore your config at any point.`}
- </p>
- <div className="flex justify-end space-x-4">
- <Button
- type="button"
- variant={isArchived ? "default" : "destructive"}
- loading={configMutation.isPending}
- onClick={() => {
- configMutation.mutateAsync({
- projectId,
- id: configId,
- isArchived: !isArchived,
- });
- setEmptySelectedConfigIds(
- emptySelectedConfigIds.filter((id) => id !== configId),
- );
- capture("score_configs:archive_form_submit");
- }}
- >
- Confirm
- </Button>
- </div>
- </PopoverContent>
- </Popover>
+ <PopoverController
+ align="center"
+ contentClassName="max-w-[500px]"
+ disabled={disabled !== undefined}
+ modal
+ onOpenChange={(isOpen) => {
+ if (isOpen && hasAccess) {
+ capture("score_configs:archive_form_open");
+ }
+ }}
+ renderContent={() => (
+ <>
+ <h2 className="mb-3 font-bold">
+ {isArchived ? "Restore config" : "Archive config"}
+ </h2>
+ <p className="mb-3 text-sm">
+ Your config is currently{" "}
+ {isArchived
+ ? `archived. Restore if you want to use "${name}" in annotation again.`
+ : `active. Archive if you no longer want to use "${name}" in annotation. Historic "${name}" scores will still be shown and can be deleted. You can restore your config at any point.`}
+ </p>
+ <div className="flex justify-end space-x-4">
+ <Button
+ type="button"
+ variant={isArchived ? "default" : "destructive"}
+ loading={configMutation.isPending}
+ onClick={() => {
+ configMutation.mutateAsync({
+ projectId,
+ id: configId,
+ isArchived: !isArchived,
+ });
+ setEmptySelectedConfigIds(
+ emptySelectedConfigIds.filter((id) => id !== configId),
+ );
+ capture("score_configs:archive_form_submit");
+ }}
+ >
+ Confirm
+ </Button>
+ </div>
+ </>
+ )}
+ >
+ {({ Anchor, isOpen, openPopover, Trigger }) =>
+ children({ disabled, isOpen, openPopover, Anchor, Trigger })
+ }
+ </PopoverController>
);
};