import { GitCompare } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import type { ReviewDiffScopeMode } from "@/lib/review-diff-scope"; import { cn } from "@/lib/utils"; type CommitOption = { hash: string; label: string; timestamp: string; message?: string; }; export function ReviewCommitScopeControl({ mode, commitOptions, selectedCommitHashes, isFetching, notice, onSetFullScope, onToggleCommitSelection, }: { mode: ReviewDiffScopeMode; commitOptions: CommitOption[]; selectedCommitHashes: string[]; isFetching: boolean; notice?: string | null; onSetFullScope: () => void; onToggleCommitSelection: (hash: string) => void; }) { const selectedSet = new Set(selectedCommitHashes); const selectedCount = selectedSet.size; const scopeLabel = mode === "full" ? "All Changes" : `Range (${selectedCount})`; const selectedIndices = commitOptions .map((option, index) => (selectedSet.has(option.hash) ? index : -1)) .filter((index) => index >= 0) .sort((a, b) => a - b); const rangeStart = selectedIndices[0] ?? -1; const rangeEnd = selectedIndices[selectedIndices.length - 1] ?? -1; return (
{ event.preventDefault(); onSetFullScope(); }} >
All Changes
{commitOptions.length > 0 ? (
{commitOptions.map((option, index) => { const selected = selectedSet.has(option.hash); const inRange = rangeStart >= 0 && rangeEnd >= 0 && index >= rangeStart && index <= rangeEnd; return ( { event.preventDefault(); onToggleCommitSelection(option.hash); }} >
{option.label} {option.timestamp}
{option.message || "(no message)"}
); })}
) : (
No commits available.
)}
{isFetching ? loading... : null} {notice ? {notice} : null}
); }