import { ChevronDown, Loader2 } from "lucide-react"; import { formatRecentTimestamp } from "@/components/pull-request-review/review-formatters"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { cn } from "@/lib/utils"; export type FileVersionSelectOption = { id: string; label: string; unread: boolean; latest: boolean; commitMessage?: string; commitDate?: string; state?: "loading" | "error"; }; function formatCommitDate(commitDate?: string) { if (!commitDate) return null; return formatRecentTimestamp(commitDate); } export function FileVersionSelect({ value, options, onValueChange, onOpenChange, }: { value: string; options: FileVersionSelectOption[]; onValueChange: (value: string) => void; onOpenChange?: (open: boolean) => void; }) { const selected = options.find((option) => option.id === value) ?? options[0]; if (!selected) return null; const isLoadingHistory = options.some((option) => option.state === "loading"); const selectedDate = formatCommitDate(selected.commitDate); return ( {options.map((option) => ( { if (option.state === "loading" || option.state === "error") { event.preventDefault(); return; } onValueChange(option.id); }} > {option.state === "loading" ? : null} {option.label} {option.latest && option.label !== "Latest" ? (latest) : null} {option.commitDate ? ( {formatCommitDate(option.commitDate)} ) : null} {option.commitMessage ? {option.commitMessage} : null} ))} ); }