({
projects,
organizations,
align = 'start',
}: ProjectSelectorProps)
| 29 | } |
| 30 | |
| 31 | export default function ProjectSelector({ |
| 32 | projects, |
| 33 | organizations, |
| 34 | align = 'start', |
| 35 | }: ProjectSelectorProps) { |
| 36 | const router = useRouter(); |
| 37 | const { organizationId, projectId } = useAppParams(); |
| 38 | const { isAdmin } = useOrganizationAccess(organizationId); |
| 39 | const [open, setOpen] = useState(false); |
| 40 | |
| 41 | const changeProject = (newProjectId: string) => { |
| 42 | if (organizationId && projectId) { |
| 43 | // Navigate to the new project keeping the current path structure |
| 44 | router.navigate({ |
| 45 | to: '/$organizationId/$projectId', |
| 46 | params: { |
| 47 | organizationId, |
| 48 | projectId: newProjectId, |
| 49 | }, |
| 50 | }); |
| 51 | } else { |
| 52 | router.navigate({ |
| 53 | to: '/$organizationId/$projectId', |
| 54 | params: { |
| 55 | organizationId: organizationId!, |
| 56 | projectId: newProjectId, |
| 57 | }, |
| 58 | }); |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | const changeOrganization = (newOrganizationId: string) => { |
| 63 | router.navigate({ |
| 64 | to: '/$organizationId', |
| 65 | params: { |
| 66 | organizationId: newOrganizationId, |
| 67 | }, |
| 68 | }); |
| 69 | }; |
| 70 | |
| 71 | return ( |
| 72 | <DropdownMenu onOpenChange={setOpen} open={open}> |
| 73 | <DropdownMenuTrigger asChild> |
| 74 | <Button |
| 75 | aria-expanded={open} |
| 76 | className="flex min-w-0 flex-1 items-center justify-start" |
| 77 | role="combobox" |
| 78 | size={'sm'} |
| 79 | variant="outline" |
| 80 | > |
| 81 | <Building2Icon className="shrink-0" size={16} /> |
| 82 | <span className="mx-2 truncate"> |
| 83 | {projectId |
| 84 | ? projects.find((p) => p.id === projectId)?.name |
| 85 | : organizationId |
| 86 | ? organizations?.find((o) => o.id === organizationId)?.name |
| 87 | : 'Select project'} |
| 88 | </span> |
nothing calls this directly
no test coverage detected