mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
- Added new RadioGroup and Switch components for better UI interaction. - Introduced BranchSelector for improved branch selection in feature dialogs. - Updated Autocomplete and BranchAutocomplete components to handle error states. - Refactored feature management to archive verified features instead of deleting them. - Enhanced worktree handling by removing worktreePath from features, relying on branchName instead. - Improved auto mode functionality by integrating branch management and worktree updates. - Cleaned up unused code and optimized existing logic for better performance.
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
import { BranchAutocomplete } from "@/components/ui/branch-autocomplete";
|
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface BranchSelectorProps {
|
|
useCurrentBranch: boolean;
|
|
onUseCurrentBranchChange: (useCurrent: boolean) => void;
|
|
branchName: string;
|
|
onBranchNameChange: (branchName: string) => void;
|
|
branchSuggestions: string[];
|
|
currentBranch?: string;
|
|
disabled?: boolean;
|
|
testIdPrefix?: string;
|
|
}
|
|
|
|
export function BranchSelector({
|
|
useCurrentBranch,
|
|
onUseCurrentBranchChange,
|
|
branchName,
|
|
onBranchNameChange,
|
|
branchSuggestions,
|
|
currentBranch,
|
|
disabled = false,
|
|
testIdPrefix = "branch",
|
|
}: BranchSelectorProps) {
|
|
// Validate: if "other branch" is selected, branch name is required
|
|
const isBranchRequired = !useCurrentBranch;
|
|
const hasError = isBranchRequired && !branchName.trim();
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<Label htmlFor={`${testIdPrefix}-selector`}>Target Branch</Label>
|
|
<RadioGroup
|
|
value={useCurrentBranch ? "current" : "other"}
|
|
onValueChange={(value) => onUseCurrentBranchChange(value === "current")}
|
|
disabled={disabled}
|
|
data-testid={`${testIdPrefix}-radio-group`}
|
|
>
|
|
<div className="flex items-center space-x-2">
|
|
<RadioGroupItem value="current" id={`${testIdPrefix}-current`} />
|
|
<Label
|
|
htmlFor={`${testIdPrefix}-current`}
|
|
className="font-normal cursor-pointer"
|
|
>
|
|
Use current selected branch
|
|
{currentBranch && (
|
|
<span className="text-muted-foreground ml-1">
|
|
({currentBranch})
|
|
</span>
|
|
)}
|
|
</Label>
|
|
</div>
|
|
<div className="flex items-center space-x-2">
|
|
<RadioGroupItem value="other" id={`${testIdPrefix}-other`} />
|
|
<Label
|
|
htmlFor={`${testIdPrefix}-other`}
|
|
className="font-normal cursor-pointer"
|
|
>
|
|
Other branch
|
|
</Label>
|
|
</div>
|
|
</RadioGroup>
|
|
{!useCurrentBranch && (
|
|
<div className="ml-6 space-y-1">
|
|
<BranchAutocomplete
|
|
value={branchName}
|
|
onChange={onBranchNameChange}
|
|
branches={branchSuggestions}
|
|
placeholder="Select or create branch..."
|
|
data-testid={`${testIdPrefix}-input`}
|
|
disabled={disabled}
|
|
error={hasError}
|
|
/>
|
|
{hasError && (
|
|
<p className="text-xs text-destructive">
|
|
Branch name is required when "Other branch" is selected.
|
|
</p>
|
|
)}
|
|
</div>
|
|
)}
|
|
{disabled ? (
|
|
<p className="text-xs text-muted-foreground">
|
|
Branch cannot be changed after work has started.
|
|
</p>
|
|
) : (
|
|
<p className="text-xs text-muted-foreground">
|
|
{useCurrentBranch
|
|
? "Work will be done in the currently selected branch. A worktree will be created if needed."
|
|
: "Work will be done in this branch. A worktree will be created if needed."}
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|