BranchLink.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Check, Shield } from 'lucide-react'
  2. import Link from 'next/link'
  3. import { useRouter } from 'next/router'
  4. import { CommandItem } from 'ui'
  5. import { sanitizeRoute } from './ProjectDropdown.utils'
  6. import type { Branch } from '@/data/branches/branches-query'
  7. import { useTrack } from '@/lib/telemetry/track'
  8. export interface BranchLinkProps {
  9. branch: Branch
  10. isSelected: boolean
  11. onClose: () => void
  12. }
  13. export function BranchLink({ branch, isSelected, onClose }: BranchLinkProps) {
  14. const track = useTrack()
  15. const router = useRouter()
  16. const sanitizedRoute = sanitizeRoute(router.route, router.query)
  17. const href =
  18. sanitizedRoute?.replace('[ref]', branch.project_ref) ?? `/project/${branch.project_ref}`
  19. return (
  20. <Link passHref href={href}>
  21. <CommandItem
  22. value={branch.name.replaceAll('"', '')}
  23. className="cursor-pointer w-full flex items-center justify-between text-sm md:text-xs p-2 md:py-1.5 md:px-2"
  24. onSelect={() => {
  25. track('branch_selector_branch_clicked', {
  26. branchId: branch.id,
  27. branchName: branch.name,
  28. })
  29. onClose()
  30. }}
  31. >
  32. <p className="truncate w-60 flex items-center gap-1" title={branch.name}>
  33. {branch.is_default && <Shield size={14} className="text-amber-900" />}
  34. {branch.name}
  35. </p>
  36. {isSelected && <Check size={14} strokeWidth={1.5} />}
  37. </CommandItem>
  38. </Link>
  39. )
  40. }