feat(ui): move a task to another list via drag & drop
Dragging a task row onto a user list in the Lists island now reassigns it to that list. The task drag holds the pointer capture, so the release is resolved geometrically (new case between the Mission Control and reorder cases) instead of going through the Lists island's own DragDrop path, which never sees a DragEventArgs during a task drag. TaskRepository.MoveToListAsync reassigns the task plus every descendant (a child must never sit in a different list than its parent) and appends the task at the end of the target list. Guards: running tasks and tasks holding an Active/Kept worktree are rejected to the footer error strip; a move that changes repo asks for confirmation naming both repos. The source repo is read from the task's own list rather than the island's current list, which is a smart/virtual list with no working dir of its own whenever one of those is shown.
This commit is contained in:
@@ -16,6 +16,9 @@ public sealed partial class ListNavItemViewModel : ViewModelBase
|
||||
[ObservableProperty] private bool _isManual;
|
||||
[ObservableProperty] private bool _dropHintAbove;
|
||||
[ObservableProperty] private bool _dropHintBelow;
|
||||
// Set while a dragged task hovers over this row as a move target — distinct from
|
||||
// DropHintAbove/Below, which mark an insertion point for list reordering.
|
||||
[ObservableProperty] private bool _isTaskDropTarget;
|
||||
public string? IconKey { get; init; }
|
||||
public string? DotColorKey { get; init; }
|
||||
}
|
||||
|
||||
@@ -471,6 +471,11 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
|
||||
}
|
||||
|
||||
public bool CanReorder => _currentList?.Kind == ListKind.User;
|
||||
public string? CurrentListId => _currentList?.Id;
|
||||
|
||||
/// <summary>Set by the shell (mirrors <see cref="ListsIslandViewModel.Dialogs"/>) so a
|
||||
/// cross-repo move can confirm via the shared modal seam.</summary>
|
||||
public IDialogService? Dialogs { get; set; }
|
||||
|
||||
public void ClearDropHints()
|
||||
{
|
||||
@@ -573,6 +578,76 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drag-drop move: reassigns a task (and every descendant) to <paramref name="targetList"/>.
|
||||
/// No-op for anything that isn't a user list the task doesn't already sit in.
|
||||
/// Rejects running tasks and tasks (or descendants) holding an Active/Kept worktree — the
|
||||
/// worktree would keep pointing at the source repo. A move across repos without a worktree
|
||||
/// is allowed but asks for confirmation first.
|
||||
/// </summary>
|
||||
public async Task MoveTaskToListAsync(TaskRowViewModel row, ListNavItemViewModel targetList)
|
||||
{
|
||||
if (targetList.Kind != ListKind.User) return;
|
||||
var targetListId = targetList.Id.StartsWith("user:", StringComparison.Ordinal)
|
||||
? targetList.Id["user:".Length..]
|
||||
: targetList.Id;
|
||||
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
// The row's own list, not _currentList — the task island also shows smart/virtual lists,
|
||||
// whose rows come from many lists and which carry no working dir of their own. Dropping a
|
||||
// task on the list it already sits in is a silent no-op.
|
||||
var sourceListId = await db.Tasks.AsNoTracking()
|
||||
.Where(t => t.Id == row.Id).Select(t => t.ListId).FirstOrDefaultAsync();
|
||||
if (sourceListId is null || sourceListId == targetListId) return;
|
||||
|
||||
if (row.IsRunning)
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.tasksIsland.moveRunningRejected"));
|
||||
return;
|
||||
}
|
||||
|
||||
var repo = new TaskRepository(db);
|
||||
|
||||
var descendantIds = await repo.GetDescendantIdsAsync(row.Id);
|
||||
var ownIds = new List<string> { row.Id };
|
||||
ownIds.AddRange(descendantIds);
|
||||
var hasBlockingWorktree = await db.Worktrees.AsNoTracking()
|
||||
.Where(w => ownIds.Contains(w.TaskId)
|
||||
&& (w.State == ClaudeDo.Data.Models.WorktreeState.Active
|
||||
|| w.State == ClaudeDo.Data.Models.WorktreeState.Kept))
|
||||
.AnyAsync();
|
||||
if (hasBlockingWorktree)
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.tasksIsland.moveWorktreeRejected"));
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceDir = await db.Lists.AsNoTracking()
|
||||
.Where(l => l.Id == sourceListId).Select(l => l.WorkingDir).FirstOrDefaultAsync();
|
||||
var targetDir = targetList.WorkingDir;
|
||||
var repoChanges = !string.Equals(sourceDir, targetDir, StringComparison.OrdinalIgnoreCase);
|
||||
if (repoChanges)
|
||||
{
|
||||
if (Dialogs is null)
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.tasksIsland.moveConfirmUnavailable"));
|
||||
return;
|
||||
}
|
||||
var ok = await Dialogs.ConfirmAsync(Loc.T("vm.tasksIsland.moveRepoConfirm",
|
||||
string.IsNullOrWhiteSpace(sourceDir) ? "—" : sourceDir,
|
||||
string.IsNullOrWhiteSpace(targetDir) ? "—" : targetDir));
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
await repo.MoveToListAsync(row.Id, targetListId);
|
||||
|
||||
Items.Remove(row);
|
||||
Regroup();
|
||||
UpdateSubtitle();
|
||||
TasksChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ToggleDoneAsync(TaskRowViewModel row)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user