Files
supabase/apps/studio/components/layouts/AppLayout/BranchLink.tsx
Francesco Sansalvadore b997b7fb13 feat(studio): org project branch mobile selector (#43238)
- add new
[OrgSelector](https://github.com/supabase/supabase/pull/43238/changes#diff-214b339101a9c06864ea2755ac7246eb4c971ce74c5d3169b1385a28ee1d4227)
and
[ProjectBranchSelector](https://github.com/supabase/supabase/pull/43238/changes#diff-82d25c128c306b61bea7481026f58f670a229874f23ca3a1a1d78ddeabde21e0)
components to the mobile navigation, replacing the previous which took
up a lot of horizontal space
- org/project/branch dropdowns now open up in the bottom MobileSheetNav
for a better mobile ux
- desktop nav remains unchanged
2026-03-11 16:25:22 +01:00

45 lines
1.4 KiB
TypeScript

import type { Branch } from 'data/branches/branches-query'
import { useTrack } from 'lib/telemetry/track'
import { Check, Shield } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { CommandItem_Shadcn_ } from 'ui'
import { sanitizeRoute } from './ProjectDropdown.utils'
export interface BranchLinkProps {
branch: Branch
isSelected: boolean
onClose: () => void
}
export function BranchLink({ branch, isSelected, onClose }: BranchLinkProps) {
const track = useTrack()
const router = useRouter()
const sanitizedRoute = sanitizeRoute(router.route, router.query)
const href =
sanitizedRoute?.replace('[ref]', branch.project_ref) ?? `/project/${branch.project_ref}`
return (
<Link passHref href={href}>
<CommandItem_Shadcn_
value={branch.name.replaceAll('"', '')}
className="cursor-pointer w-full flex items-center justify-between text-sm md:text-xs p-2 md:py-1.5 md:px-2"
onSelect={() => {
track('branch_selector_branch_clicked', {
branchId: branch.id,
branchName: branch.name,
})
onClose()
}}
>
<p className="truncate w-60 flex items-center gap-1" title={branch.name}>
{branch.is_default && <Shield size={14} className="text-amber-900" />}
{branch.name}
</p>
{isSelected && <Check size={14} strokeWidth={1.5} />}
</CommandItem_Shadcn_>
</Link>
)
}