Skip to content

Commit 34e8577

Browse files
committed
feat: make organization selector larger and searchable
Replaces the organization dropdown with a Popover + Command combobox: wider panel and a search input to filter organizations by name. Closes #5043
1 parent 34c5b68 commit 34e8577

2 files changed

Lines changed: 160 additions & 130 deletions

File tree

‎apps/dokploy/components/dashboard/organization/handle-organization.tsx‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
DialogTitle,
1515
DialogTrigger,
1616
} from "@/components/ui/dialog";
17-
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
1817
import {
1918
Form,
2019
FormControl,
@@ -103,24 +102,27 @@ export function AddOrganization({ organizationId }: Props) {
103102
<Dialog open={open} onOpenChange={setOpen}>
104103
<DialogTrigger asChild>
105104
{organizationId ? (
106-
<DropdownMenuItem
107-
className="group cursor-pointer hover:bg-blue-500/10"
108-
onSelect={(e) => e.preventDefault()}
105+
<Button
106+
type="button"
107+
variant="ghost"
108+
size="icon"
109+
className="group hover:bg-blue-500/10"
110+
title="Edit organization"
109111
>
110112
<PenBoxIcon className="size-3.5 text-primary group-hover:text-blue-500" />
111-
</DropdownMenuItem>
113+
</Button>
112114
) : (
113-
<DropdownMenuItem
114-
className="gap-2 p-2"
115-
onSelect={(e) => e.preventDefault()}
115+
<button
116+
type="button"
117+
className="flex w-full items-center gap-2 rounded-md p-2 text-left text-sm hover:bg-accent hover:text-accent-foreground"
116118
>
117119
<div className="flex size-6 items-center justify-center rounded-md border bg-background">
118120
<Plus className="size-4" />
119121
</div>
120122
<div className="font-medium text-muted-foreground">
121123
Add organization
122124
</div>
123-
</DropdownMenuItem>
125+
</button>
124126
)}
125127
</DialogTrigger>
126128
<DialogContent className="sm:max-w-[425px]">

‎apps/dokploy/components/layouts/side.tsx‎

Lines changed: 149 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,26 @@ import {
5353
CollapsibleContent,
5454
CollapsibleTrigger,
5555
} from "@/components/ui/collapsible";
56+
import {
57+
Command,
58+
CommandEmpty,
59+
CommandGroup,
60+
CommandInput,
61+
CommandItem,
62+
CommandList,
63+
} from "@/components/ui/command";
5664
import {
5765
DropdownMenu,
5866
DropdownMenuContent,
5967
DropdownMenuItem,
6068
DropdownMenuLabel,
61-
DropdownMenuSeparator,
6269
DropdownMenuTrigger,
6370
} from "@/components/ui/dropdown-menu";
71+
import {
72+
Popover,
73+
PopoverContent,
74+
PopoverTrigger,
75+
} from "@/components/ui/popover";
6476
import { Separator } from "@/components/ui/separator";
6577
import {
6678
SIDEBAR_COOKIE_NAME,
@@ -565,6 +577,8 @@ function SidebarLogo() {
565577
const [_activeTeam, setActiveTeam] = useState<
566578
typeof activeOrganization | null
567579
>(null);
580+
const [organizationSelectorOpen, setOrganizationSelectorOpen] =
581+
useState(false);
568582

569583
useEffect(() => {
570584
if (activeOrganization) {
@@ -587,8 +601,11 @@ function SidebarLogo() {
587601
>
588602
{/* Organization Logo and Selector */}
589603
<SidebarMenuItem className={"w-full"}>
590-
<DropdownMenu>
591-
<DropdownMenuTrigger asChild>
604+
<Popover
605+
open={organizationSelectorOpen}
606+
onOpenChange={setOrganizationSelectorOpen}
607+
>
608+
<PopoverTrigger asChild>
592609
<SidebarMenuButton
593610
size={isCollapsed ? "sm" : "lg"}
594611
className={cn(
@@ -637,145 +654,156 @@ function SidebarLogo() {
637654
className={cn("ml-auto", isCollapsed && "hidden")}
638655
/>
639656
</SidebarMenuButton>
640-
</DropdownMenuTrigger>
641-
<DropdownMenuContent
642-
className="w-64 rounded-lg max-h-[min(70vh,28rem)] flex flex-col"
657+
</PopoverTrigger>
658+
<PopoverContent
659+
className="w-96 p-0"
643660
align="start"
644661
side={isMobile ? "bottom" : "right"}
645662
sideOffset={4}
646663
>
647-
<DropdownMenuLabel className="text-xs text-muted-foreground shrink-0">
648-
Organizations
649-
</DropdownMenuLabel>
650-
<div className="overflow-y-auto overflow-x-hidden min-h-0 -mx-1 px-1">
651-
{organizations?.map((org) => {
652-
const isDefault = org.members?.[0]?.isDefault ?? false;
653-
return (
654-
<div
655-
className="flex flex-row items-center justify-between gap-1"
656-
key={org.name}
657-
>
658-
<DropdownMenuItem
659-
onClick={async () => {
660-
await authClient.organization.setActive({
661-
organizationId: org.id,
662-
});
663-
window.location.reload();
664-
}}
665-
className="flex min-w-0 flex-1 gap-2 p-2"
666-
>
667-
<div className="flex size-6 shrink-0 items-center justify-center rounded-sm border">
668-
<Logo
669-
className={cn(
670-
"transition-all",
671-
state === "collapsed" ? "size-4" : "size-5",
672-
)}
673-
logoUrl={org.logo ?? undefined}
674-
/>
675-
</div>
676-
<span className="truncate">{org.name}</span>
677-
</DropdownMenuItem>
678-
679-
<div className="flex shrink-0 items-center gap-2">
680-
<Button
681-
variant="ghost"
682-
size="icon"
683-
className={cn(
684-
"group",
685-
isDefault
686-
? "hover:bg-yellow-500/10"
687-
: "hover:bg-blue-500/10",
688-
)}
689-
isLoading={isSettingDefault && !isDefault}
690-
disabled={isDefault}
691-
onClick={async (e) => {
692-
if (isDefault) return;
693-
e.stopPropagation();
694-
await setDefaultOrganization({
664+
<Command>
665+
<CommandInput
666+
placeholder="Search organizations..."
667+
className="h-9"
668+
/>
669+
<CommandList className="max-h-[min(60vh,24rem)]">
670+
<CommandEmpty>No organizations found.</CommandEmpty>
671+
<CommandGroup heading="Organizations">
672+
{organizations?.map((org) => {
673+
const isDefault = org.members?.[0]?.isDefault ?? false;
674+
return (
675+
<CommandItem
676+
key={org.id}
677+
value={org.name}
678+
onSelect={async () => {
679+
setOrganizationSelectorOpen(false);
680+
await authClient.organization.setActive({
695681
organizationId: org.id,
696-
})
697-
.then(() => {
698-
refetch();
699-
toast.success("Default organization updated");
700-
})
701-
.catch((error) => {
702-
toast.error(
703-
error?.message ||
704-
"Error setting default organization",
705-
);
706-
});
682+
});
683+
window.location.reload();
707684
}}
708-
title={
709-
isDefault
710-
? "Default organization"
711-
: "Set as default"
712-
}
685+
className="flex items-center justify-between gap-1"
713686
>
714-
{isDefault ? (
715-
<Star
716-
fill="#eab308"
717-
stroke="#eab308"
718-
className="size-4 text-yellow-500"
719-
/>
720-
) : (
721-
<Star
722-
fill="none"
723-
stroke="currentColor"
724-
className="size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
725-
/>
726-
)}
727-
</Button>
728-
{org.ownerId === session?.user?.id && (
729-
<>
730-
<AddOrganization organizationId={org.id} />
731-
<DialogAction
732-
title="Delete Organization"
733-
description="Are you sure you want to delete this organization?"
734-
type="destructive"
735-
onClick={async () => {
736-
await deleteOrganization({
687+
<div className="flex min-w-0 flex-1 items-center gap-2">
688+
<div className="flex size-6 shrink-0 items-center justify-center rounded-sm border">
689+
<Logo
690+
className={cn(
691+
"transition-all",
692+
state === "collapsed" ? "size-4" : "size-5",
693+
)}
694+
logoUrl={org.logo ?? undefined}
695+
/>
696+
</div>
697+
<span className="truncate">{org.name}</span>
698+
</div>
699+
700+
<div
701+
className="flex shrink-0 items-center gap-2"
702+
onClick={(e) => e.stopPropagation()}
703+
onKeyDown={(e) => e.stopPropagation()}
704+
>
705+
<Button
706+
variant="ghost"
707+
size="icon"
708+
className={cn(
709+
"group",
710+
isDefault
711+
? "hover:bg-yellow-500/10"
712+
: "hover:bg-blue-500/10",
713+
)}
714+
isLoading={isSettingDefault && !isDefault}
715+
disabled={isDefault}
716+
onClick={async (e) => {
717+
if (isDefault) return;
718+
e.stopPropagation();
719+
await setDefaultOrganization({
737720
organizationId: org.id,
738721
})
739722
.then(() => {
740723
refetch();
741724
toast.success(
742-
"Organization deleted successfully",
725+
"Default organization updated",
743726
);
744727
})
745728
.catch((error) => {
746729
toast.error(
747730
error?.message ||
748-
"Error deleting organization",
731+
"Error setting default organization",
749732
);
750733
});
751734
}}
735+
title={
736+
isDefault
737+
? "Default organization"
738+
: "Set as default"
739+
}
752740
>
753-
<Button
754-
variant="ghost"
755-
size="icon"
756-
className="group hover:bg-red-500/10"
757-
isLoading={isRemoving}
758-
>
759-
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
760-
</Button>
761-
</DialogAction>
762-
</>
763-
)}
764-
</div>
765-
</div>
766-
);
767-
})}
768-
</div>
769-
{(user?.role === "owner" ||
770-
user?.role === "admin" ||
771-
isCloud) && (
772-
<>
773-
<DropdownMenuSeparator />
774-
<AddOrganization />
775-
</>
776-
)}
777-
</DropdownMenuContent>
778-
</DropdownMenu>
741+
{isDefault ? (
742+
<Star
743+
fill="#eab308"
744+
stroke="#eab308"
745+
className="size-4 text-yellow-500"
746+
/>
747+
) : (
748+
<Star
749+
fill="none"
750+
stroke="currentColor"
751+
className="size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
752+
/>
753+
)}
754+
</Button>
755+
{org.ownerId === session?.user?.id && (
756+
<>
757+
<AddOrganization organizationId={org.id} />
758+
<DialogAction
759+
title="Delete Organization"
760+
description="Are you sure you want to delete this organization?"
761+
type="destructive"
762+
onClick={async () => {
763+
await deleteOrganization({
764+
organizationId: org.id,
765+
})
766+
.then(() => {
767+
refetch();
768+
toast.success(
769+
"Organization deleted successfully",
770+
);
771+
})
772+
.catch((error) => {
773+
toast.error(
774+
error?.message ||
775+
"Error deleting organization",
776+
);
777+
});
778+
}}
779+
>
780+
<Button
781+
variant="ghost"
782+
size="icon"
783+
className="group hover:bg-red-500/10"
784+
isLoading={isRemoving}
785+
>
786+
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
787+
</Button>
788+
</DialogAction>
789+
</>
790+
)}
791+
</div>
792+
</CommandItem>
793+
);
794+
})}
795+
</CommandGroup>
796+
</CommandList>
797+
{(user?.role === "owner" ||
798+
user?.role === "admin" ||
799+
isCloud) && (
800+
<div className="border-t p-1">
801+
<AddOrganization />
802+
</div>
803+
)}
804+
</Command>
805+
</PopoverContent>
806+
</Popover>
779807
</SidebarMenuItem>
780808

781809
{/* Notification Bell */}

0 commit comments

Comments
 (0)