ruvector/studio/components/layouts/AppLayout/ProjectDropdown.tsx
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

134 lines
4.8 KiB
TypeScript

import { Box, Check, ChevronsUpDown, Plus } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { ParsedUrlQuery } from 'querystring'
import { useState } from 'react'
import { useParams } from 'common'
import { OrganizationProjectSelector } from 'components/ui/OrganizationProjectSelector'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { IS_PLATFORM } from 'lib/constants'
import { Button, CommandGroup_Shadcn_, CommandItem_Shadcn_, cn } from 'ui'
export const sanitizeRoute = (route: string, routerQueries: ParsedUrlQuery) => {
const queryArray = Object.entries(routerQueries)
if (queryArray.length > 1) {
// [Joshen] Ideally we shouldn't use hard coded numbers, but temp workaround
// for storage bucket route since its longer
const isStorageBucketRoute = 'bucketId' in routerQueries
const isSecurityAdvisorRoute = 'preset' in routerQueries
return route
.split('/')
.slice(0, isStorageBucketRoute || isSecurityAdvisorRoute ? 5 : 4)
.join('/')
} else {
return route
}
}
export const ProjectDropdown = () => {
const router = useRouter()
const { ref } = useParams()
const { data: project, isLoading: isLoadingProject } = useSelectedProjectQuery()
const { data: selectedOrganization } = useSelectedOrganizationQuery()
const isBranch = project?.parentRef !== project?.ref
const { data: parentProject, isLoading: isLoadingParentProject } = useProjectDetailQuery(
{ ref: project?.parent_project_ref },
{ enabled: isBranch }
)
const selectedProject = parentProject ?? project
const projectCreationEnabled = useIsFeatureEnabled('projects:create')
const [open, setOpen] = useState(false)
if (isLoadingProject || (isBranch && isLoadingParentProject) || !selectedProject) {
return <ShimmeringLoader className="w-[90px]" />
}
return IS_PLATFORM ? (
<>
<Link
href={`/project/${project?.ref}`}
className="flex items-center gap-2 flex-shrink-0 text-sm"
>
<Box size={14} strokeWidth={1.5} className="text-foreground-lighter" />
<span className="text-foreground max-w-32 lg:max-w-none truncate">
{selectedProject?.name}
</span>
</Link>
<OrganizationProjectSelector
open={open}
setOpen={setOpen}
selectedRef={ref}
onSelect={(project) => {
const sanitizedRoute = sanitizeRoute(router.route, router.query)
const href = sanitizedRoute?.replace('[ref]', project.ref) ?? `/project/${project.ref}`
router.push(href)
}}
renderTrigger={() => (
<Button
type="text"
size="tiny"
className={cn('px-1.5 py-4 [&_svg]:w-5 [&_svg]:h-5 ml-1')}
iconRight={<ChevronsUpDown strokeWidth={1.5} />}
/>
)}
renderRow={(project) => {
// [Joshen] Temp while we're interim between v1 and v2 billing
const sanitizedRoute = sanitizeRoute(router.route, router.query)
const href = sanitizedRoute?.replace('[ref]', project.ref) ?? `/project/${project.ref}`
const isSelected = project.ref === ref
return (
<Link href={href} className="w-full flex items-center justify-between">
<span className={cn('truncate', isSelected ? 'max-w-60' : 'max-w-64')}>
{project.name}
</span>
{isSelected && <Check size={16} />}
</Link>
)
}}
renderActions={() => {
return (
projectCreationEnabled && (
<CommandGroup_Shadcn_>
<CommandItem_Shadcn_
className="cursor-pointer w-full"
onSelect={() => {
setOpen(false)
router.push(`/new/${selectedOrganization?.slug}`)
}}
onClick={() => setOpen(false)}
>
<Link
href={`/new/${selectedOrganization?.slug}`}
onClick={() => {
setOpen(false)
}}
className="w-full flex items-center gap-2"
>
<Plus size={14} strokeWidth={1.5} />
<p>New project</p>
</Link>
</CommandItem_Shadcn_>
</CommandGroup_Shadcn_>
)
)
}}
/>
</>
) : (
<Button type="text">
<span className="text-sm">{selectedProject?.name}</span>
</Button>
)
}