feat: make organization selector larger and searchable (#5052)

Replaces the organization dropdown with a Popover + Command combobox: wider panel and a search input to filter organizations by name.

Closes #5043
This commit is contained in:
Mauricio Siu
2026-08-11 20:55:26 -06:00
committed by GitHub
parent 34c5b688ac
commit 3cad115155
2 changed files with 160 additions and 130 deletions
@@ -14,7 +14,6 @@ import {
DialogTitle, DialogTitle,
DialogTrigger, DialogTrigger,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { import {
Form, Form,
FormControl, FormControl,
@@ -103,16 +102,19 @@ export function AddOrganization({ organizationId }: Props) {
<Dialog open={open} onOpenChange={setOpen}> <Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
{organizationId ? ( {organizationId ? (
<DropdownMenuItem <Button
className="group cursor-pointer hover:bg-blue-500/10" type="button"
onSelect={(e) => e.preventDefault()} variant="ghost"
size="icon"
className="group hover:bg-blue-500/10"
title="Edit organization"
> >
<PenBoxIcon className="size-3.5 text-primary group-hover:text-blue-500" /> <PenBoxIcon className="size-3.5 text-primary group-hover:text-blue-500" />
</DropdownMenuItem> </Button>
) : ( ) : (
<DropdownMenuItem <button
className="gap-2 p-2" type="button"
onSelect={(e) => e.preventDefault()} className="flex w-full items-center gap-2 rounded-md p-2 text-left text-sm hover:bg-accent hover:text-accent-foreground"
> >
<div className="flex size-6 items-center justify-center rounded-md border bg-background"> <div className="flex size-6 items-center justify-center rounded-md border bg-background">
<Plus className="size-4" /> <Plus className="size-4" />
@@ -120,7 +122,7 @@ export function AddOrganization({ organizationId }: Props) {
<div className="font-medium text-muted-foreground"> <div className="font-medium text-muted-foreground">
Add organization Add organization
</div> </div>
</DropdownMenuItem> </button>
)} )}
</DialogTrigger> </DialogTrigger>
<DialogContent className="sm:max-w-[425px]"> <DialogContent className="sm:max-w-[425px]">
+55 -27
View File
@@ -53,14 +53,26 @@ import {
CollapsibleContent, CollapsibleContent,
CollapsibleTrigger, CollapsibleTrigger,
} from "@/components/ui/collapsible"; } from "@/components/ui/collapsible";
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuLabel, DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger, DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"; } from "@/components/ui/dropdown-menu";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { import {
SIDEBAR_COOKIE_NAME, SIDEBAR_COOKIE_NAME,
@@ -565,6 +577,8 @@ function SidebarLogo() {
const [_activeTeam, setActiveTeam] = useState< const [_activeTeam, setActiveTeam] = useState<
typeof activeOrganization | null typeof activeOrganization | null
>(null); >(null);
const [organizationSelectorOpen, setOrganizationSelectorOpen] =
useState(false);
useEffect(() => { useEffect(() => {
if (activeOrganization) { if (activeOrganization) {
@@ -587,8 +601,11 @@ function SidebarLogo() {
> >
{/* Organization Logo and Selector */} {/* Organization Logo and Selector */}
<SidebarMenuItem className={"w-full"}> <SidebarMenuItem className={"w-full"}>
<DropdownMenu> <Popover
<DropdownMenuTrigger asChild> open={organizationSelectorOpen}
onOpenChange={setOrganizationSelectorOpen}
>
<PopoverTrigger asChild>
<SidebarMenuButton <SidebarMenuButton
size={isCollapsed ? "sm" : "lg"} size={isCollapsed ? "sm" : "lg"}
className={cn( className={cn(
@@ -637,33 +654,37 @@ function SidebarLogo() {
className={cn("ml-auto", isCollapsed && "hidden")} className={cn("ml-auto", isCollapsed && "hidden")}
/> />
</SidebarMenuButton> </SidebarMenuButton>
</DropdownMenuTrigger> </PopoverTrigger>
<DropdownMenuContent <PopoverContent
className="w-64 rounded-lg max-h-[min(70vh,28rem)] flex flex-col" className="w-96 p-0"
align="start" align="start"
side={isMobile ? "bottom" : "right"} side={isMobile ? "bottom" : "right"}
sideOffset={4} sideOffset={4}
> >
<DropdownMenuLabel className="text-xs text-muted-foreground shrink-0"> <Command>
Organizations <CommandInput
</DropdownMenuLabel> placeholder="Search organizations..."
<div className="overflow-y-auto overflow-x-hidden min-h-0 -mx-1 px-1"> className="h-9"
/>
<CommandList className="max-h-[min(60vh,24rem)]">
<CommandEmpty>No organizations found.</CommandEmpty>
<CommandGroup heading="Organizations">
{organizations?.map((org) => { {organizations?.map((org) => {
const isDefault = org.members?.[0]?.isDefault ?? false; const isDefault = org.members?.[0]?.isDefault ?? false;
return ( return (
<div <CommandItem
className="flex flex-row items-center justify-between gap-1" key={org.id}
key={org.name} value={org.name}
> onSelect={async () => {
<DropdownMenuItem setOrganizationSelectorOpen(false);
onClick={async () => {
await authClient.organization.setActive({ await authClient.organization.setActive({
organizationId: org.id, organizationId: org.id,
}); });
window.location.reload(); window.location.reload();
}} }}
className="flex min-w-0 flex-1 gap-2 p-2" className="flex items-center justify-between gap-1"
> >
<div className="flex min-w-0 flex-1 items-center gap-2">
<div className="flex size-6 shrink-0 items-center justify-center rounded-sm border"> <div className="flex size-6 shrink-0 items-center justify-center rounded-sm border">
<Logo <Logo
className={cn( className={cn(
@@ -674,9 +695,13 @@ function SidebarLogo() {
/> />
</div> </div>
<span className="truncate">{org.name}</span> <span className="truncate">{org.name}</span>
</DropdownMenuItem> </div>
<div className="flex shrink-0 items-center gap-2"> <div
className="flex shrink-0 items-center gap-2"
onClick={(e) => e.stopPropagation()}
onKeyDown={(e) => e.stopPropagation()}
>
<Button <Button
variant="ghost" variant="ghost"
size="icon" size="icon"
@@ -696,7 +721,9 @@ function SidebarLogo() {
}) })
.then(() => { .then(() => {
refetch(); refetch();
toast.success("Default organization updated"); toast.success(
"Default organization updated",
);
}) })
.catch((error) => { .catch((error) => {
toast.error( toast.error(
@@ -762,20 +789,21 @@ function SidebarLogo() {
</> </>
)} )}
</div> </div>
</div> </CommandItem>
); );
})} })}
</div> </CommandGroup>
</CommandList>
{(user?.role === "owner" || {(user?.role === "owner" ||
user?.role === "admin" || user?.role === "admin" ||
isCloud) && ( isCloud) && (
<> <div className="border-t p-1">
<DropdownMenuSeparator />
<AddOrganization /> <AddOrganization />
</> </div>
)} )}
</DropdownMenuContent> </Command>
</DropdownMenu> </PopoverContent>
</Popover>
</SidebarMenuItem> </SidebarMenuItem>
{/* Notification Bell */} {/* Notification Bell */}