Skip to content

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

fix(web): Improve Project & Organization Dropdowns (#15227)

Ben Bachem64cf4b8529a7
diff --git a/web/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu.stories.tsx b/web/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu.stories.tsx
new file mode 100644
index 0000000000..1407f44a56
--- /dev/null
+++ b/web/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu.stories.tsx
@@ -0,0 +1,78 @@
+import type { ComponentProps } from "react";
+import preview from "../../../.storybook/preview";
+import {
+ DropdownMenu,
+ DropdownMenuTrigger,
+} from "@/src/components/ui/dropdown-menu";
+import { OrganizationDropdownMenu } from "./OrganizationDropdownMenu";
+
+type Organization = Extract<
+ ComponentProps<typeof OrganizationDropdownMenu>,
+ { state: "loaded" }
+>["organizations"][number];
+
+const createOrganization = (id: string, name: string): Organization => ({
+ id,
+ name,
+ role: "OWNER",
+ cloudConfig: undefined,
+ plan: "cloud:hobby",
+ metadata: {},
+ aiFeaturesEnabled: false,
+ aiTelemetryEnabled: false,
+ projects: [],
+});
+
+const organizations = [
+ createOrganization("org-acme", "Acme Inc."),
+ createOrganization("org-globex", "Globex Corporation"),
+ createOrganization("org-initech", "Initech"),
+ createOrganization(
+ "org-long-name",
+ "An organization name that is too long to fit in the menu",
+ ),
+];
+
+const meta = preview.meta({
+ component: OrganizationDropdownMenu,
+ args: {
+ canCreateOrganizations: true,
+ getOrgPath: (organizationId) => `/organization/${organizationId}`,
+ },
+ render: (args) => (
+ <DropdownMenu defaultOpen>
+ <DropdownMenuTrigger>Trigger</DropdownMenuTrigger>
+ <OrganizationDropdownMenu {...args} />
+ </DropdownMenu>
+ ),
+});
+
+export const Default = meta.story({
+ args: {
+ state: "loaded",
+ organizations,
+ },
+});
+
+export const Many = meta.story({
+ args: {
+ state: "loaded",
+ organizations: Array.from({ length: 10 }, (_, index) =>
+ createOrganization(`org-${index + 1}`, `Organization ${index + 1}`),
+ ),
+ },
+});
+
+export const WithoutCreation = meta.story({
+ args: {
+ state: "loaded",
+ organizations,
+ canCreateOrganizations: false,
+ },
+});
+
+export const Loading = meta.story({
+ args: {
+ state: "loading",
+ },
+});
diff --git a/web/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu.tsx b/web/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu.tsx
new file mode 100644
index 0000000000..e89d04a79c
--- /dev/null
+++ b/web/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu.tsx
@@ -0,0 +1,73 @@
+import {
+ DropdownMenuContent,
+ DropdownMenuItemWithSecondaryAction,
+ DropdownMenuSeparator,
+ DropdownMenuLoadingItem,
+} from "@/src/components/ui/dropdown-menu";
+import { PlusIcon, Settings } from "lucide-react";
+import { type Session } from "next-auth";
+import { Fragment } from "react";
+import { env } from "@/src/env.mjs";
+import { createOrganizationRoute } from "@/src/features/setup/setupRoutes";
+
+type Organization = NonNullable<Session["user"]>["organizations"][number];
+
+type OrganizationDropdownMenuProps = {
+ canCreateOrganizations: boolean;
+ getOrgPath: (organizationId: string) => string;
+} & (
+ | { state: "loading" }
+ | {
+ state: "loaded";
+ organizations: Organization[];
+ }
+);
+
+export function OrganizationDropdownMenu(props: OrganizationDropdownMenuProps) {
+ const { canCreateOrganizations, getOrgPath } = props;
+
+ return (
+ <DropdownMenuContent align="start" header="Organizations" maxHeight="15rem">
+ {props.state === "loaded" ? (
+ [...props.organizations]
+ .sort((a, b) => {
+ // sort demo org to the bottom
+ const isDemoA = env.NEXT_PUBLIC_DEMO_ORG_ID === a.id;
+ const isDemoB = env.NEXT_PUBLIC_DEMO_ORG_ID === b.id;
+ if (isDemoA) return 1;
+ if (isDemoB) return -1;
+ return 0;
+ })
+ .map((dropdownOrg) => (
+ <Fragment key={dropdownOrg.id}>
+ {env.NEXT_PUBLIC_DEMO_ORG_ID === dropdownOrg.id && (
+ <DropdownMenuSeparator />
+ )}
+ <DropdownMenuItemWithSecondaryAction
+ title={dropdownOrg.name}
+ href={getOrgPath(dropdownOrg.id)}
+ secondaryAction={{
+ href: `/organization/${dropdownOrg.id}/settings`,
+ ariaLabel: `Go to settings for ${dropdownOrg.name}`,
+ icon: Settings,
+ }}
+ />
+ </Fragment>
+ ))
+ ) : (
+ <DropdownMenuLoadingItem />
+ )}
+
+ {canCreateOrganizations && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItemWithSecondaryAction
+ title="New Organization"
+ href={createOrganizationRoute}
+ icon={PlusIcon}
+ />
+ </>
+ )}
+ </DropdownMenuContent>
+ );
+}
diff --git a/web/src/components/ProjectDropdownMenu/ProjectDropdownMenu.stories.tsx b/web/src/components/ProjectDropdownMenu/ProjectDropdownMenu.stories.tsx
new file mode 100644
index 0000000000..07dbe752f3
--- /dev/null
+++ b/web/src/components/ProjectDropdownMenu/ProjectDropdownMenu.stories.tsx
@@ -0,0 +1,78 @@
+import type { ComponentProps } from "react";
+import preview from "../../../.storybook/preview";
+import {
+ DropdownMenu,
+ DropdownMenuTrigger,
+} from "@/src/components/ui/dropdown-menu";
+import { ProjectDropdownMenu } from "./ProjectDropdownMenu";
+
+type Project = Extract<
+ ComponentProps<typeof ProjectDropdownMenu>,
+ { state: "loaded" }
+>["projects"][number];
+
+const createProject = (id: string, name: string): Project => ({
+ id,
+ name,
+ role: "ADMIN",
+ deletedAt: null,
+ retentionDays: null,
+ hasTraces: false,
+ metadata: {},
+ createdAt: new Date().toISOString(),
+});
+
+const projects = [
+ createProject("project-analytics", "Analytics"),
+ createProject("project-production", "Production"),
+ createProject("project-staging", "Staging"),
+ createProject(
+ "project-long-name",
+ "A project name that is too long to fit in the menu",
+ ),
+];
+
+const meta = preview.meta({
+ component: ProjectDropdownMenu,
+ args: {
+ organizationId: "org-acme",
+ canCreateProjects: true,
+ getProjectPath: (projectId) => `/project/${projectId}`,
+ },
+ render: (args) => (
+ <DropdownMenu defaultOpen>
+ <DropdownMenuTrigger>Trigger</DropdownMenuTrigger>
+ <ProjectDropdownMenu {...args} />
+ </DropdownMenu>
+ ),
+});
+
+export const Default = meta.story({
+ args: {
+ state: "loaded",
+ projects,
+ },
+});
+
+export const Many = meta.story({
+ args: {
+ state: "loaded",
+ projects: Array.from({ length: 10 }, (_, index) =>
+ createProject(`project-${index + 1}`, `Project ${index + 1}`),
+ ),
+ },
+});
+
+export const WithoutCreation = meta.story({
+ args: {
+ state: "loaded",
+ projects,
+ canCreateProjects: false,
+ },
+});
+
+export const Loading = meta.story({
+ args: {
+ state: "loading",
+ },
+});
diff --git a/web/src/components/ProjectDropdownMenu/ProjectDropdownMenu.tsx b/web/src/components/ProjectDropdownMenu/ProjectDropdownMenu.tsx
new file mode 100644
index 0000000000..fbc2d62ac5
--- /dev/null
+++ b/web/src/components/ProjectDropdownMenu/ProjectDropdownMenu.tsx
@@ -0,0 +1,65 @@
+import {
+ DropdownMenuContent,
+ DropdownMenuItemWithSecondaryAction,
+ DropdownMenuSeparator,
+ DropdownMenuLoadingItem,
+} from "@/src/components/ui/dropdown-menu";
+import { createProjectRoute } from "@/src/features/setup/setupRoutes";
+import { PlusIcon, Settings } from "lucide-react";
+import { type Session } from "next-auth";
+
+type Project = NonNullable<
+ Session["user"]
+>["organizations"][number]["projects"][number];
+
+type ProjectDropdownMenuProps = {
+ organizationId: string;
+ canCreateProjects: boolean;
+ getProjectPath: (projectId: string) => string;
+} & (
+ | { state: "loading" }
+ | {
+ state: "loaded";
+ projects: Project[];
+ }
+);
+
+export function ProjectDropdownMenu(props: ProjectDropdownMenuProps) {
+ const { organizationId, canCreateProjects, getProjectPath } = props;
+
+ return (
+ <DropdownMenuContent align="start" header="Projects" maxHeight="15rem">
+ {props.state === "loaded" ? (
+ props.projects.map((dropdownProject) => (
+ <DropdownMenuItemWithSecondaryAction
+ key={dropdownProject.id}
+ title={dropdownProject.name}
+ href={getProjectPath(dropdownProject.id)}
+ secondaryAction={{
+ href: `/project/${dropdownProject.id}/settings`,
+ ariaLabel: `Go to settings for ${dropdownProject.name}`,
+ icon: Settings,
+ }}
+ />
+ ))
+ ) : (
+ <>
+ <DropdownMenuLoadingItem />
+ <DropdownMenuLoadingItem />
+ <DropdownMenuLoadingItem />
+ </>
+ )}
+
+ {canCreateProjects && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItemWithSecondaryAction
+ title="New Project"
+ href={createProjectRoute(organizationId)}
+ icon={PlusIcon}
+ />
+ </>
+ )}
+ </DropdownMenuContent>
+ );
+}
diff --git a/web/src/components/layouts/breadcrumb.tsx b/web/src/components/layouts/breadcrumb.tsx
index e4141c43cf..3d22d2b8bf 100644
--- a/web/src/components/layouts/breadcrumb.tsx
+++ b/web/src/components/layouts/breadcrumb.tsx
@@ -8,35 +8,19 @@ import {
import { Fragment } from "react";
import {
DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
-import { ChevronDownIcon, PlusIcon, Settings, Slash } from "lucide-react";
-import Spinner from "@/src/components/design-system/Spinner/Spinner";
-import { Button } from "@/src/components/ui/button";
+import { ChevronDownIcon, Slash } from "lucide-react";
import { env } from "@/src/env.mjs";
import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";
import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess";
-import {
- createOrganizationRoute,
- createProjectRoute,
-} from "@/src/features/setup/setupRoutes";
import { isCloudPlan, planLabels } from "@langfuse/shared";
import Link from "next/link";
import { Badge } from "@/src/components/ui/badge";
-
-const LoadingMenuItem = () => (
- <DropdownMenuItem>
- <span className="mr-1.5 inline-flex">
- <Spinner size="sm" />
- </span>
- Loading...
- </DropdownMenuItem>
-);
+import { OrganizationDropdownMenu } from "@/src/components/OrganizationDropdownMenu/OrganizationDropdownMenu";
+import { ProjectDropdownMenu } from "@/src/components/ProjectDropdownMenu/ProjectDropdownMenu";
const BreadcrumbComponent = ({
items,
@@ -108,89 +92,13 @@ const BreadcrumbComponent = ({
)}
<ChevronDownIcon className="h-4 w-4" />
</DropdownMenuTrigger>
- <DropdownMenuContent align="start">
- <DropdownMenuItem className="font-bold" asChild>
- <Link href="/" className="cursor-pointer">
- Organizations
- </Link>
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <div className="max-h-36 overflow-y-auto">
- {organizations ? (
- organizations
- .sort((a, b) => {
- // sort demo org to the bottom
- const isDemoA = env.NEXT_PUBLIC_DEMO_ORG_ID === a.id;
- const isDemoB = env.NEXT_PUBLIC_DEMO_ORG_ID === b.id;
- if (isDemoA) return 1;
- if (isDemoB) return -1;
- return 0;
- })
- .map((dropdownOrg) => (
- <Fragment key={dropdownOrg.id}>
- {env.NEXT_PUBLIC_DEMO_ORG_ID === dropdownOrg.id && (
- <DropdownMenuSeparator />
- )}
- <DropdownMenuItem asChild>
- <Link
- href={getOrgPath(dropdownOrg.id)}
- className="flex cursor-pointer justify-between"
- >
- <span
- className="max-w-36 overflow-hidden text-ellipsis whitespace-nowrap"
- title={dropdownOrg.name}
- >
- {dropdownOrg.name}
- </span>
- <Button
- asChild
- variant="ghost"
- size="xs"
- className="hover:bg-background -my-1 ml-4"
- >
- <div
- onClick={(e) => {
- e.preventDefault();
- e.stopPropagation();
- router.push(
- `/organization/${dropdownOrg.id}/settings`,
- );
- }}
- >
- <Settings size={12} />
- </div>
- </Button>
- </Link>
- </DropdownMenuItem>
- </Fragment>
- ))
- ) : (
- <LoadingMenuItem />
- )}
- </div>
-
- {canCreateOrganizations && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem asChild>
- <Button
- variant="ghost"
- size="xs"
- className="h-8 w-full text-sm font-normal"
- asChild
- >
- <Link href={createOrganizationRoute}>
- <PlusIcon
- className="mr-1.5 h-4 w-4"
- aria-hidden="true"
- />
- New Organization
- </Link>
- </Button>
- </DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
+ <OrganizationDropdownMenu
+ {...(organizations
+ ? { state: "loaded", organizations }
+ : { state: "loading" })}
+ canCreateOrganizations={!!canCreateOrganizations}
+ getOrgPath={getOrgPath}
+ />
</DropdownMenu>
)}
{organization && project && (
@@ -203,80 +111,19 @@ const BreadcrumbComponent = ({
{project?.name ?? "Project"}
<ChevronDownIcon className="h-4 w-4" />
</DropdownMenuTrigger>
- <DropdownMenuContent align="start">
- <DropdownMenuItem asChild className="font-bold">
- <Link
- href={`/organization/${organization.id}`}
- className="cursor-pointer"
- >
- Projects
- </Link>
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <div className="max-h-36 overflow-y-auto">
- {organizations ? (
- organizations
- .find((org) => org.id === organization.id)
- ?.projects.map((dropdownProject) => (
- <DropdownMenuItem key={dropdownProject.id} asChild>
- <Link
- href={getProjectPath(dropdownProject.id)}
- className="flex cursor-pointer justify-between"
- >
- <span
- className="max-w-36 overflow-hidden text-ellipsis whitespace-nowrap"
- title={dropdownProject.name}
- >
- {dropdownProject.name}
- </span>
- <Button
- asChild
- variant="ghost"
- size="xs"
- className="hover:bg-background -my-1 ml-4"
- >
- <div
- onClick={(e) => {
- e.preventDefault();
- e.stopPropagation();
- router.push(
- `/project/${dropdownProject.id}/settings`,
- );
- }}
- >
- <Settings size={12} />
- </div>
- </Button>
- </Link>
- </DropdownMenuItem>
- ))
- ) : (
- <LoadingMenuItem />
- )}
- </div>
-
- {canCreateProjects && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem asChild>
- <Button
- variant="ghost"
- size="xs"
- className="h-8 w-full text-sm font-normal"
- asChild
- >
- <Link href={createProjectRoute(organization.id)}>
- <PlusIcon
- className="mr-1.5 h-4 w-4"
- aria-hidden="true"
- />
- New Project
- </Link>
- </Button>
- </DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
+ <ProjectDropdownMenu
+ organizationId={organization.id}
+ {...(organizations
+ ? {
+ state: "loaded",
+ projects:
+ organizations.find((org) => org.id === organization.id)
+ ?.projects ?? [],
+ }
+ : { state: "loading" })}
+ canCreateProjects={!!canCreateProjects}
+ getProjectPath={getProjectPath}
+ />
</DropdownMenu>
</>
)}
diff --git a/web/src/components/ui/dropdown-menu.tsx b/web/src/components/ui/dropdown-menu.tsx
index 091a40b375..f2dabfba70 100644
--- a/web/src/components/ui/dropdown-menu.tsx
+++ b/web/src/components/ui/dropdown-menu.tsx
@@ -2,10 +2,20 @@
import * as React from "react";
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
-import { Check, ChevronRight, Circle, Minus } from "lucide-react";
+import { cva } from "class-variance-authority";
+import {
+ Check,
+ ChevronRight,
+ Circle,
+ Minus,
+ type LucideIcon,
+} from "lucide-react";
+import Link from "next/link";
import { cn } from "@/src/utils/tailwind";
import { useLayerContainer } from "@/src/components/ui/layer";
+import { Skeleton } from "@/src/components/ui/skeleton";
+import { useScrollGradients } from "@/src/hooks/useScrollGradients";
const DropdownMenu = DropdownMenuPrimitive.Root;
@@ -67,29 +77,181 @@ const DropdownMenuSubContent = React.forwardRef<
DropdownMenuSubContent.displayName =
DropdownMenuPrimitive.SubContent.displayName;
+const dropdownMenuLabelVariants = cva("px-2 py-1.5 text-sm font-bold");
+
+const dropdownMenuContentVariants = cva(
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 min-w-32 overflow-hidden rounded-md border shadow-md",
+ {
+ variants: {
+ // Header content provides its own full-width header and padded body.
+ // Headerless content needs the default padding on the Radix container.
+ hasHeader: {
+ true: null,
+ false: "p-1",
+ },
+ },
+ },
+);
+
+const dropdownMenuScrollGradientVariants = cva(
+ "before:pointer-events-none before:sticky before:z-2 before:-mx-1 before:-mb-6 before:block before:h-6 before:bg-linear-to-b before:from-popover before:to-transparent before:content-[''] after:pointer-events-none after:sticky after:bottom-0 after:z-2 after:-mx-1 after:-mt-6 after:block after:h-6 after:bg-linear-to-t after:from-popover after:to-transparent after:content-['']",
+ {
+ variants: {
+ hasHeader: {
+ true: "before:top-[calc(2.5rem-1px)]",
+ false: "before:top-0",
+ },
+ showTopGradient: {
+ true: "before:opacity-100",
+ false: "before:opacity-0",
+ },
+ showBottomGradient: {
+ true: "after:opacity-100",
+ false: "after:opacity-0",
+ },
+ },
+ },
+);
+
+type DropdownMenuContentProps = React.ComponentPropsWithoutRef<
+ typeof DropdownMenuPrimitive.Content
+> & {
+ header?: React.ReactNode;
+ maxHeight?: React.CSSProperties["maxHeight"];
+};
+
+const DropdownContentWrapper = React.forwardRef<
+ React.ComponentRef<typeof DropdownMenuPrimitive.Content>,
+ Omit<DropdownMenuContentProps, "children"> & {
+ children:
+ | React.ReactNode
+ | ((gradients: { top: boolean; bottom: boolean }) => React.ReactNode);
+ }
+>(
+ (
+ { children, className, header, sideOffset = 4, maxHeight, style, ...props },
+ ref,
+ ) => {
+ const container = useLayerContainer("popover");
+ const { register, recompute, top, bottom } = useScrollGradients<
+ React.ComponentRef<typeof DropdownMenuPrimitive.Content>
+ >(maxHeight !== undefined);
+ const content =
+ typeof children === "function" ? children({ top, bottom }) : children;
+
+ return (
+ <DropdownMenuPrimitive.Portal container={container}>
+ <DropdownMenuPrimitive.Content
+ ref={(element) => {
+ register(element);
+ if (typeof ref === "function") {
+ ref(element);
+ } else if (ref) {
+ ref.current = element;
+ }
+ }}
+ sideOffset={sideOffset}
+ className={cn(
+ dropdownMenuContentVariants({
+ hasHeader: header != null,
+ className,
+ }),
+ maxHeight !== undefined &&
+ header == null &&
+ dropdownMenuScrollGradientVariants({
+ hasHeader: false,
+ showTopGradient: top,
+ showBottomGradient: bottom,
+ }),
+ )}
+ style={
+ maxHeight === undefined
+ ? style
+ : { ...style, maxHeight, overflowY: "auto" }
+ }
+ {...props}
+ onScroll={(event) => {
+ recompute();
+ props.onScroll?.(event);
+ }}
+ >
+ {content}
+ </DropdownMenuPrimitive.Content>
+ </DropdownMenuPrimitive.Portal>
+ );
+ },
+);
+DropdownContentWrapper.displayName = "DropdownContentWrapper";
+
const DropdownMenuContent = React.forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Content>,
- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
->(({ className, sideOffset = 4, ...props }, ref) => {
- // Route into the `popover` overlay layer (above `modal`). null until mounted
- // → falls back to <body>, SSR-parity. Layer order, not z-index, stacks it.
- const container = useLayerContainer("popover");
- return (
- <DropdownMenuPrimitive.Portal container={container}>
- <DropdownMenuPrimitive.Content
+ DropdownMenuContentProps
+>(
+ (
+ { children, className, header, sideOffset = 4, maxHeight, style, ...props },
+ ref,
+ ) => {
+ if (header != null) {
+ // The sticky header sits outside the padded body so its background and
+ // border cover the full width of the scroll container.
+ return (
+ <DropdownContentWrapper
+ ref={ref}
+ className={className}
+ header={header}
+ sideOffset={sideOffset}
+ maxHeight={maxHeight}
+ style={style}
+ {...props}
+ >
+ {({ top, bottom }) => (
+ <>
+ <div
+ className={cn(
+ dropdownMenuLabelVariants(),
+ "border-border bg-popover sticky top-0 z-1 border-b px-3 py-2.5",
+ )}
+ >
+ {header}
+ </div>
+ <div
+ className={cn(
+ "p-1",
+ maxHeight !== undefined &&
+ dropdownMenuScrollGradientVariants({
+ hasHeader: true,
+ showTopGradient: top,
+ showBottomGradient: bottom,
+ }),
+ )}
+ >
+ {children}
+ </div>
+ </>
+ )}
+ </DropdownContentWrapper>
+ );
+ }
+
+ return (
+ <DropdownContentWrapper
ref={ref}
+ className={className}
sideOffset={sideOffset}
- className={cn(
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 min-w-32 overflow-hidden rounded-md border p-1 shadow-md",
- className,
- )}
+ maxHeight={maxHeight}
+ style={style}
{...props}
- />
- </DropdownMenuPrimitive.Portal>
- );
-});
+ >
+ {children}
+ </DropdownContentWrapper>
+ );
+ },
+);
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
+/**
+ * Prefer `DropdownMenuItemWithSecondaryAction` for items that do not require JSX content.
+ */
const DropdownMenuItem = React.forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
@@ -108,6 +270,117 @@ const DropdownMenuItem = React.forwardRef<
));
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
+type DropdownMenuItemAction =
+ | {
+ href: React.ComponentProps<typeof Link>["href"];
+ onClick?: never;
+ }
+ | {
+ href?: never;
+ onClick: () => void;
+ };
+
+type DropdownMenuItemWithSecondaryActionProps = {
+ icon?: LucideIcon;
+ title: string;
+ secondaryAction?: DropdownMenuItemAction & {
+ ariaLabel?: string;
+ icon: LucideIcon;
+ };
+} & DropdownMenuItemAction;
+
+const dropdownMenuItemPrimaryActionVariants = cva(
+ "flex min-w-0 flex-1 cursor-pointer items-center px-2 py-1.5",
+);
+
+const dropdownMenuItemSecondaryActionVariants = cva(
+ "hover:bg-border dark:hover:bg-white/10 flex size-6 shrink-0 cursor-pointer items-center justify-center rounded mr-1",
+);
+
+const DropdownMenuItemWithSecondaryAction = (
+ props: DropdownMenuItemWithSecondaryActionProps,
+) => {
+ const secondaryAction = props.secondaryAction;
+ const PrimaryActionIcon = props.icon;
+ const SecondaryActionIcon = secondaryAction?.icon;
+ const primaryContent = (
+ <>
+ {PrimaryActionIcon && (
+ <PrimaryActionIcon className="mr-1.5 size-4" aria-hidden="true" />
+ )}
+ <span
+ className="max-w-36 overflow-hidden text-ellipsis whitespace-nowrap"
+ title={props.title}
+ >
+ {props.title}
+ </span>
+ </>
+ );
+ let secondaryActionContent: React.ReactNode = null;
+
+ if (secondaryAction && SecondaryActionIcon) {
+ if (secondaryAction.href !== undefined) {
+ secondaryActionContent = (
+ <Link
+ href={secondaryAction.href}
+ aria-label={secondaryAction.ariaLabel}
+ className={dropdownMenuItemSecondaryActionVariants()}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <SecondaryActionIcon size={12} />
+ </Link>
+ );
+ } else {
+ secondaryActionContent = (
+ <button
+ type="button"
+ aria-label={secondaryAction.ariaLabel}
+ className={dropdownMenuItemSecondaryActionVariants()}
+ onClick={(event) => {
+ event.stopPropagation();
+ secondaryAction.onClick();
+ }}
+ >
+ <SecondaryActionIcon size={12} />
+ </button>
+ );
+ }
+ }
+
+ return (
+ <div className="flex h-8">
+ {props.href !== undefined ? (
+ <DropdownMenuItem asChild className="h-8 min-w-0 flex-1 p-0">
+ <Link
+ href={props.href}
+ className={dropdownMenuItemPrimaryActionVariants()}
+ >
+ {primaryContent}
+ </Link>
+ </DropdownMenuItem>
+ ) : (
+ <DropdownMenuItem asChild className="h-8 min-w-0 flex-1 p-0">
+ <button
+ type="button"
+ className={dropdownMenuItemPrimaryActionVariants()}
+ onClick={props.onClick}
+ >
+ {primaryContent}
+ </button>
+ </DropdownMenuItem>
+ )}
+
+ {secondaryActionContent}
+ </div>
+ );
+};
+
+const DropdownMenuLoadingItem = () => (
+ <DropdownMenuItem disabled aria-label="Loading">
+ <Skeleton variant="contrast" className="h-4 w-24" />
+ </DropdownMenuItem>
+);
+
const DropdownMenuCheckboxItem = React.forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.CheckboxItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
@@ -163,7 +436,7 @@ const DropdownMenuLabel = React.forwardRef<
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Label
ref={ref}
- className={cn("px-2 py-1.5 text-sm font-bold", inset && "pl-8", className)}
+ className={cn(dropdownMenuLabelVariants(), inset && "pl-8", className)}
{...props}
/>
));
@@ -175,7 +448,7 @@ const DropdownMenuSeparator = React.forwardRef<
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.Separator
ref={ref}
- className={cn("bg-muted -mx-1 my-1 h-px", className)}
+ className={cn("bg-border -mx-1 my-1 h-px", className)}
{...props}
/>
));
@@ -199,6 +472,8 @@ export {
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuItemWithSecondaryAction,
+ DropdownMenuLoadingItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioItem,
DropdownMenuLabel,
diff --git a/web/src/components/ui/skeleton.tsx b/web/src/components/ui/skeleton.tsx
index 2cdfbb7930..a6cabcf1e7 100644
--- a/web/src/components/ui/skeleton.tsx
+++ b/web/src/components/ui/skeleton.tsx
@@ -1,14 +1,27 @@
+import { cva, type VariantProps } from "class-variance-authority";
+
import { cn } from "@/src/utils/tailwind";
+const skeletonVariants = cva("animate-pulse rounded-md", {
+ variants: {
+ variant: {
+ default: "bg-muted",
+ contrast: "bg-border-contrast",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+});
+
function Skeleton({
className,
+ variant,
...props
-}: React.HTMLAttributes<HTMLDivElement>) {
+}: React.HTMLAttributes<HTMLDivElement> &
+ VariantProps<typeof skeletonVariants>) {
return (
- <div
- className={cn("bg-muted animate-pulse rounded-md", className)}
- {...props}
- />
+ <div className={cn(skeletonVariants({ variant }), className)} {...props} />
);
}
diff --git a/web/src/hooks/useScrollGradients.ts b/web/src/hooks/useScrollGradients.ts
new file mode 100644
index 0000000000..49c9f01e00
--- /dev/null
+++ b/web/src/hooks/useScrollGradients.ts
@@ -0,0 +1,64 @@
+import { useCallback, useEffect, useRef, useState } from "react";
+
+const SCROLL_EDGE_THRESHOLD_PX = 10;
+
+/**
+ * Tracks whether a scroll container has hidden content above or below it.
+ * Re-measures when the container resizes or its DOM content changes so callers
+ * can render scroll affordances at the active edges.
+ */
+export function useScrollGradients<TElement extends HTMLElement>(
+ enabled: boolean,
+) {
+ const contentRef = useRef<TElement>(null);
+ const [{ top, bottom }, setScrollGradients] = useState({
+ top: false,
+ bottom: false,
+ });
+ const register = useCallback((element: TElement | null) => {
+ contentRef.current = element;
+ }, []);
+ const recompute = useCallback(() => {
+ const element = contentRef.current;
+ if (!element || !enabled) return;
+
+ const maxScrollTop = element.scrollHeight - element.clientHeight;
+ const nextTop =
+ maxScrollTop > SCROLL_EDGE_THRESHOLD_PX &&
+ element.scrollTop > SCROLL_EDGE_THRESHOLD_PX;
+ const nextBottom =
+ maxScrollTop > SCROLL_EDGE_THRESHOLD_PX &&
+ element.scrollTop < maxScrollTop - SCROLL_EDGE_THRESHOLD_PX;
+
+ setScrollGradients((current) => {
+ if (current.top === nextTop && current.bottom === nextBottom) {
+ return current;
+ }
+ return { top: nextTop, bottom: nextBottom };
+ });
+ }, [enabled]);
+
+ useEffect(() => {
+ const element = contentRef.current;
+ if (!element || !enabled) return;
+
+ const update = () => recompute();
+ update();
+
+ const resizeObserver = new ResizeObserver(update);
+ resizeObserver.observe(element);
+ const mutationObserver = new MutationObserver(update);
+ mutationObserver.observe(element, {
+ childList: true,
+ subtree: true,
+ characterData: true,
+ });
+
+ return () => {
+ resizeObserver.disconnect();
+ mutationObserver.disconnect();
+ };
+ }, [enabled, recompute]);
+
+ return { register, recompute, top, bottom };
+}