mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-19 02:15:17 +00:00
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:
@@ -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]">
|
||||||
|
|||||||
@@ -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,145 +654,156 @@ 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"
|
||||||
{organizations?.map((org) => {
|
/>
|
||||||
const isDefault = org.members?.[0]?.isDefault ?? false;
|
<CommandList className="max-h-[min(60vh,24rem)]">
|
||||||
return (
|
<CommandEmpty>No organizations found.</CommandEmpty>
|
||||||
<div
|
<CommandGroup heading="Organizations">
|
||||||
className="flex flex-row items-center justify-between gap-1"
|
{organizations?.map((org) => {
|
||||||
key={org.name}
|
const isDefault = org.members?.[0]?.isDefault ?? false;
|
||||||
>
|
return (
|
||||||
<DropdownMenuItem
|
<CommandItem
|
||||||
onClick={async () => {
|
key={org.id}
|
||||||
await authClient.organization.setActive({
|
value={org.name}
|
||||||
organizationId: org.id,
|
onSelect={async () => {
|
||||||
});
|
setOrganizationSelectorOpen(false);
|
||||||
window.location.reload();
|
await authClient.organization.setActive({
|
||||||
}}
|
|
||||||
className="flex min-w-0 flex-1 gap-2 p-2"
|
|
||||||
>
|
|
||||||
<div className="flex size-6 shrink-0 items-center justify-center rounded-sm border">
|
|
||||||
<Logo
|
|
||||||
className={cn(
|
|
||||||
"transition-all",
|
|
||||||
state === "collapsed" ? "size-4" : "size-5",
|
|
||||||
)}
|
|
||||||
logoUrl={org.logo ?? undefined}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<span className="truncate">{org.name}</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<div className="flex shrink-0 items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className={cn(
|
|
||||||
"group",
|
|
||||||
isDefault
|
|
||||||
? "hover:bg-yellow-500/10"
|
|
||||||
: "hover:bg-blue-500/10",
|
|
||||||
)}
|
|
||||||
isLoading={isSettingDefault && !isDefault}
|
|
||||||
disabled={isDefault}
|
|
||||||
onClick={async (e) => {
|
|
||||||
if (isDefault) return;
|
|
||||||
e.stopPropagation();
|
|
||||||
await setDefaultOrganization({
|
|
||||||
organizationId: org.id,
|
organizationId: org.id,
|
||||||
})
|
});
|
||||||
.then(() => {
|
window.location.reload();
|
||||||
refetch();
|
|
||||||
toast.success("Default organization updated");
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
toast.error(
|
|
||||||
error?.message ||
|
|
||||||
"Error setting default organization",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
title={
|
className="flex items-center justify-between gap-1"
|
||||||
isDefault
|
|
||||||
? "Default organization"
|
|
||||||
: "Set as default"
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{isDefault ? (
|
<div className="flex min-w-0 flex-1 items-center gap-2">
|
||||||
<Star
|
<div className="flex size-6 shrink-0 items-center justify-center rounded-sm border">
|
||||||
fill="#eab308"
|
<Logo
|
||||||
stroke="#eab308"
|
className={cn(
|
||||||
className="size-4 text-yellow-500"
|
"transition-all",
|
||||||
/>
|
state === "collapsed" ? "size-4" : "size-5",
|
||||||
) : (
|
)}
|
||||||
<Star
|
logoUrl={org.logo ?? undefined}
|
||||||
fill="none"
|
/>
|
||||||
stroke="currentColor"
|
</div>
|
||||||
className="size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
|
<span className="truncate">{org.name}</span>
|
||||||
/>
|
</div>
|
||||||
)}
|
|
||||||
</Button>
|
<div
|
||||||
{org.ownerId === session?.user?.id && (
|
className="flex shrink-0 items-center gap-2"
|
||||||
<>
|
onClick={(e) => e.stopPropagation()}
|
||||||
<AddOrganization organizationId={org.id} />
|
onKeyDown={(e) => e.stopPropagation()}
|
||||||
<DialogAction
|
>
|
||||||
title="Delete Organization"
|
<Button
|
||||||
description="Are you sure you want to delete this organization?"
|
variant="ghost"
|
||||||
type="destructive"
|
size="icon"
|
||||||
onClick={async () => {
|
className={cn(
|
||||||
await deleteOrganization({
|
"group",
|
||||||
|
isDefault
|
||||||
|
? "hover:bg-yellow-500/10"
|
||||||
|
: "hover:bg-blue-500/10",
|
||||||
|
)}
|
||||||
|
isLoading={isSettingDefault && !isDefault}
|
||||||
|
disabled={isDefault}
|
||||||
|
onClick={async (e) => {
|
||||||
|
if (isDefault) return;
|
||||||
|
e.stopPropagation();
|
||||||
|
await setDefaultOrganization({
|
||||||
organizationId: org.id,
|
organizationId: org.id,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
refetch();
|
refetch();
|
||||||
toast.success(
|
toast.success(
|
||||||
"Organization deleted successfully",
|
"Default organization updated",
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast.error(
|
toast.error(
|
||||||
error?.message ||
|
error?.message ||
|
||||||
"Error deleting organization",
|
"Error setting default organization",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
title={
|
||||||
|
isDefault
|
||||||
|
? "Default organization"
|
||||||
|
: "Set as default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Button
|
{isDefault ? (
|
||||||
variant="ghost"
|
<Star
|
||||||
size="icon"
|
fill="#eab308"
|
||||||
className="group hover:bg-red-500/10"
|
stroke="#eab308"
|
||||||
isLoading={isRemoving}
|
className="size-4 text-yellow-500"
|
||||||
>
|
/>
|
||||||
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
|
) : (
|
||||||
</Button>
|
<Star
|
||||||
</DialogAction>
|
fill="none"
|
||||||
</>
|
stroke="currentColor"
|
||||||
)}
|
className="size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
|
||||||
</div>
|
/>
|
||||||
</div>
|
)}
|
||||||
);
|
</Button>
|
||||||
})}
|
{org.ownerId === session?.user?.id && (
|
||||||
</div>
|
<>
|
||||||
{(user?.role === "owner" ||
|
<AddOrganization organizationId={org.id} />
|
||||||
user?.role === "admin" ||
|
<DialogAction
|
||||||
isCloud) && (
|
title="Delete Organization"
|
||||||
<>
|
description="Are you sure you want to delete this organization?"
|
||||||
<DropdownMenuSeparator />
|
type="destructive"
|
||||||
<AddOrganization />
|
onClick={async () => {
|
||||||
</>
|
await deleteOrganization({
|
||||||
)}
|
organizationId: org.id,
|
||||||
</DropdownMenuContent>
|
})
|
||||||
</DropdownMenu>
|
.then(() => {
|
||||||
|
refetch();
|
||||||
|
toast.success(
|
||||||
|
"Organization deleted successfully",
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
toast.error(
|
||||||
|
error?.message ||
|
||||||
|
"Error deleting organization",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="group hover:bg-red-500/10"
|
||||||
|
isLoading={isRemoving}
|
||||||
|
>
|
||||||
|
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
|
||||||
|
</Button>
|
||||||
|
</DialogAction>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</CommandItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
{(user?.role === "owner" ||
|
||||||
|
user?.role === "admin" ||
|
||||||
|
isCloud) && (
|
||||||
|
<div className="border-t p-1">
|
||||||
|
<AddOrganization />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Command>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
|
|
||||||
{/* Notification Bell */}
|
{/* Notification Bell */}
|
||||||
|
|||||||
Reference in New Issue
Block a user