adding a worktree switch feature

This commit is contained in:
Cody Seibert
2025-12-16 02:39:11 -05:00
parent b95c54a539
commit 166679cd36
9 changed files with 119 additions and 15 deletions

View File

@@ -7,12 +7,16 @@ interface UseBoardColumnFeaturesProps {
features: Feature[];
runningAutoTasks: string[];
searchQuery: string;
currentWorktreePath: string | null; // Currently selected worktree path
projectPath: string | null; // Main project path (for main worktree)
}
export function useBoardColumnFeatures({
features,
runningAutoTasks,
searchQuery,
currentWorktreePath,
projectPath,
}: UseBoardColumnFeaturesProps) {
// Memoize column features to prevent unnecessary re-renders
const columnFeaturesMap = useMemo(() => {
@@ -34,16 +38,37 @@ export function useBoardColumnFeatures({
)
: features;
// Determine the effective worktree path for filtering
// If currentWorktreePath is null, we're on the main worktree (use projectPath)
const effectiveWorktreePath = currentWorktreePath || projectPath;
filteredFeatures.forEach((f) => {
// If feature has a running agent, always show it in "in_progress"
const isRunning = runningAutoTasks.includes(f.id);
// Check if feature matches the current worktree
// Features without a worktreePath are considered unassigned (backlog items)
// Features with a worktreePath should only show if it matches the selected worktree
const matchesWorktree = !f.worktreePath || f.worktreePath === effectiveWorktreePath;
if (isRunning) {
map.in_progress.push(f);
// Only show running tasks if they match the current worktree
if (matchesWorktree) {
map.in_progress.push(f);
}
} else {
// Otherwise, use the feature's status (fallback to backlog for unknown statuses)
const status = f.status as ColumnId;
if (map[status]) {
map[status].push(f);
// Backlog items are always visible (they have no worktree assigned)
// For other statuses, filter by worktree
if (status === "backlog") {
map.backlog.push(f);
} else if (map[status]) {
// Only show if matches current worktree or has no worktree assigned
if (matchesWorktree) {
map[status].push(f);
}
} else {
// Unknown status, default to backlog
map.backlog.push(f);
@@ -59,7 +84,7 @@ export function useBoardColumnFeatures({
});
return map;
}, [features, runningAutoTasks, searchQuery]);
}, [features, runningAutoTasks, searchQuery, currentWorktreePath, projectPath]);
const getColumnFeatures = useCallback(
(columnId: ColumnId) => {

View File

@@ -14,6 +14,8 @@ interface UseBoardDragDropProps {
updates: Partial<Feature>
) => Promise<void>;
handleStartImplementation: (feature: Feature) => Promise<boolean>;
currentWorktreePath: string | null; // Currently selected worktree path
projectPath: string | null; // Main project path
}
export function useBoardDragDrop({
@@ -22,10 +24,15 @@ export function useBoardDragDrop({
runningAutoTasks,
persistFeatureUpdate,
handleStartImplementation,
currentWorktreePath,
projectPath,
}: UseBoardDragDropProps) {
const [activeFeature, setActiveFeature] = useState<Feature | null>(null);
const { moveFeature } = useAppStore();
// Determine the effective worktree path for assigning to features
const effectiveWorktreePath = currentWorktreePath || projectPath;
const handleDragStart = useCallback(
(event: DragStartEvent) => {
const { active } = event;
@@ -97,6 +104,10 @@ export function useBoardDragDrop({
if (draggedFeature.status === "backlog") {
// From backlog
if (targetStatus === "in_progress") {
// Assign the current worktree to this feature when moving to in_progress
if (effectiveWorktreePath) {
await persistFeatureUpdate(featureId, { worktreePath: effectiveWorktreePath });
}
// Use helper function to handle concurrency check and start implementation
await handleStartImplementation(draggedFeature);
} else {
@@ -123,10 +134,11 @@ export function useBoardDragDrop({
} else if (targetStatus === "backlog") {
// Allow moving waiting_approval cards back to backlog
moveFeature(featureId, "backlog");
// Clear justFinishedAt timestamp when moving back to backlog
// Clear justFinishedAt timestamp and worktreePath when moving back to backlog
persistFeatureUpdate(featureId, {
status: "backlog",
justFinishedAt: undefined,
worktreePath: undefined,
});
toast.info("Feature moved to backlog", {
description: `Moved to Backlog: ${draggedFeature.description.slice(
@@ -166,7 +178,8 @@ export function useBoardDragDrop({
} else if (targetStatus === "backlog") {
// Allow moving skipTests cards back to backlog
moveFeature(featureId, "backlog");
persistFeatureUpdate(featureId, { status: "backlog" });
// Clear worktreePath when moving back to backlog
persistFeatureUpdate(featureId, { status: "backlog", worktreePath: undefined });
toast.info("Feature moved to backlog", {
description: `Moved to Backlog: ${draggedFeature.description.slice(
0,
@@ -189,7 +202,8 @@ export function useBoardDragDrop({
} else if (targetStatus === "backlog") {
// Allow moving verified cards back to backlog
moveFeature(featureId, "backlog");
persistFeatureUpdate(featureId, { status: "backlog" });
// Clear worktreePath when moving back to backlog
persistFeatureUpdate(featureId, { status: "backlog", worktreePath: undefined });
toast.info("Feature moved to backlog", {
description: `Moved to Backlog: ${draggedFeature.description.slice(
0,
@@ -205,6 +219,7 @@ export function useBoardDragDrop({
moveFeature,
persistFeatureUpdate,
handleStartImplementation,
effectiveWorktreePath,
]
);