mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
106 lines
3.5 KiB
TypeScript
106 lines
3.5 KiB
TypeScript
import { CheckIcon, GitMergeIcon, ShieldIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import {
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
ScrollArea,
|
|
} from 'ui'
|
|
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { Branch } from '@/data/branches/branches-query'
|
|
|
|
interface BranchSelectorProps {
|
|
branches: Branch[]
|
|
onBranchSelected?: (branch: Branch) => void
|
|
disabled?: boolean
|
|
isUpdating?: boolean
|
|
variant?: 'primary' | 'outline'
|
|
align?: 'end' | 'center'
|
|
}
|
|
|
|
export const BranchSelector = ({
|
|
branches,
|
|
onBranchSelected,
|
|
disabled = false,
|
|
isUpdating = false,
|
|
variant = 'primary',
|
|
align = 'end',
|
|
}: BranchSelectorProps) => {
|
|
const [open, setOpen] = useState(false)
|
|
const [selectedBranch, setSelectedBranch] = useState<Branch | null>(null)
|
|
|
|
const availableBranches = branches.filter((branch) => !branch.is_default)
|
|
|
|
const handleBranchSelect = (branch: Branch) => {
|
|
setSelectedBranch(branch)
|
|
setOpen(false)
|
|
onBranchSelected?.(branch)
|
|
}
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen} modal={false}>
|
|
<PopoverTrigger asChild>
|
|
<ButtonTooltip
|
|
icon={<GitMergeIcon size={14} strokeWidth={1.5} />}
|
|
variant={variant}
|
|
disabled={
|
|
disabled || isUpdating || branches.length === 0 || availableBranches.length === 0
|
|
}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
align,
|
|
text:
|
|
branches.length === 0 || availableBranches.length === 0
|
|
? 'Create a branch first to start a merge request'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
{isUpdating ? 'Creating...' : 'New merge request'}
|
|
</ButtonTooltip>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="p-0 w-80" side="bottom" align="end">
|
|
<Command>
|
|
<CommandInput placeholder="Find branch to review..." />
|
|
<CommandList>
|
|
<CommandEmpty>No available branches found</CommandEmpty>
|
|
<CommandGroup>
|
|
<ScrollArea className="max-h-[210px] overflow-y-auto">
|
|
{availableBranches.map((branch) => (
|
|
<CommandItem
|
|
key={branch.id}
|
|
value={branch.name.replaceAll('"', '')}
|
|
className="cursor-pointer w-full flex items-center justify-between"
|
|
onSelect={() => handleBranchSelect(branch)}
|
|
disabled={isUpdating || !!branch.git_branch || !!branch.review_requested_at}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
{branch.is_default && <ShieldIcon size={14} className="text-amber-900" />}
|
|
<span className="truncate" title={branch.name}>
|
|
{branch.name}
|
|
</span>
|
|
</div>
|
|
{selectedBranch?.id === branch.id && (
|
|
<CheckIcon size={14} strokeWidth={1.5} className="text-primary" />
|
|
)}
|
|
{branch.git_branch && <span>Synced to a Git branch</span>}
|
|
{branch.review_requested_at && <span>Merge request opened</span>}
|
|
</CommandItem>
|
|
))}
|
|
</ScrollArea>
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|