import { Check, GitMerge, Shield } from 'lucide-react' import { useState } from 'react' import { ButtonTooltip } from 'components/ui/ButtonTooltip' import { Branch } from 'data/branches/branches-query' import { CommandEmpty_Shadcn_, CommandGroup_Shadcn_, CommandInput_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, Command_Shadcn_, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_, ScrollArea, } from 'ui' interface BranchSelectorProps { branches: Branch[] onBranchSelected?: (branch: Branch) => void disabled?: boolean isUpdating?: boolean type?: 'primary' | 'outline' } export const BranchSelector = ({ branches, onBranchSelected, disabled = false, isUpdating = false, type = 'primary', }: BranchSelectorProps) => { const [open, setOpen] = useState(false) const [selectedBranch, setSelectedBranch] = useState(null) // Filter out branches that are already ready for review and the main branch const availableBranches = branches.filter( (branch) => !branch.is_default && !branch.review_requested_at ) const handleBranchSelect = (branch: Branch) => { setSelectedBranch(branch) setOpen(false) onBranchSelected?.(branch) } return ( } type={type} disabled={disabled || availableBranches.length === 0 || isUpdating} tooltip={{ content: { side: 'bottom', text: branches.length === 0 ? 'Create a branch first to start a merge request' : availableBranches.length === 0 ? 'All branches currently have merge requests' : undefined, }, }} > {isUpdating ? 'Creating...' : 'New merge request'} No available branches found {availableBranches.map((branch) => ( handleBranchSelect(branch)} disabled={isUpdating} >
{branch.is_default && } {branch.name}
{selectedBranch?.id === branch.id && ( )}
))}
) }