feat(ui): show dequeue affordance on planning parents with queued children

Planning parents stay in Planning/Planned status while their children are
Queued/Waiting, so the existing IsQueued-only visibility rule hid the dequeue
button. Add HasQueuedSubtasks tracking and a CanRemoveFromQueue helper; the
parent-row dequeue cascades to all queued/waiting children. Also attach the
'agent' tag on explicit enqueue so the queue picker accepts the task.
This commit is contained in:
Mika Kuns
2026-04-27 10:16:40 +02:00
parent 2d7f825ff3
commit bdb709b264
3 changed files with 59 additions and 7 deletions

View File

@@ -100,6 +100,15 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
else return;
}
// Keep the parent's HasQueuedSubtasks flag in sync when a child's status flips.
if (entity is not null && !string.IsNullOrEmpty(entity.ParentTaskId))
{
var parent = Items.FirstOrDefault(r => r.Id == entity.ParentTaskId);
if (parent is not null)
parent.HasQueuedSubtasks = Items.Any(r =>
r.ParentTaskId == parent.Id && (r.IsQueued || r.IsWaiting));
}
Regroup();
UpdateSubtitle();
}
@@ -207,6 +216,16 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
if (parentsWithChildren.Contains(r.Id))
r.HasPlanningChildren = true;
// Mark planning parents whose children are currently queued/waiting,
// so the dequeue affordance is visible on the parent row.
var parentsWithQueuedKids = Items
.Where(r => r.IsChild && !string.IsNullOrEmpty(r.ParentTaskId)
&& (r.IsQueued || r.IsWaiting))
.Select(r => r.ParentTaskId!)
.ToHashSet();
foreach (var r in Items)
r.HasQueuedSubtasks = parentsWithQueuedKids.Contains(r.Id);
Regroup();
UpdateSubtitle();
}
@@ -446,9 +465,15 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
{
if (row is null || row.IsRunning) return;
await using var db = await _dbFactory.CreateDbContextAsync();
var entity = await db.Tasks.FirstOrDefaultAsync(t => t.Id == row.Id);
var entity = await db.Tasks.Include(t => t.Tags).FirstOrDefaultAsync(t => t.Id == row.Id);
if (entity is null) return;
entity.Status = TaskStatus.Queued;
// Worker queue picker requires the "agent" tag — attach it on explicit enqueue.
if (!entity.Tags.Any(t => t.Name == "agent"))
{
var agentTag = await db.Tags.FirstOrDefaultAsync(t => t.Name == "agent");
if (agentTag is not null) entity.Tags.Add(agentTag);
}
await db.SaveChangesAsync();
row.Status = TaskStatus.Queued;
if (_worker is not null)
@@ -467,9 +492,30 @@ public sealed partial class TasksIslandViewModel : ViewModelBase
await using var db = await _dbFactory.CreateDbContextAsync();
var entity = await db.Tasks.FirstOrDefaultAsync(t => t.Id == row.Id);
if (entity is null) return;
entity.Status = TaskStatus.Manual;
await db.SaveChangesAsync();
row.Status = TaskStatus.Manual;
// For a planning parent the dequeue button targets queued/waiting children,
// not the parent itself (whose Status is Planning/Planned).
if (entity.Status == TaskStatus.Planning || entity.Status == TaskStatus.Planned)
{
var children = await db.Tasks
.Where(t => t.ParentTaskId == row.Id
&& (t.Status == TaskStatus.Queued || t.Status == TaskStatus.Waiting))
.ToListAsync();
foreach (var c in children) c.Status = TaskStatus.Manual;
await db.SaveChangesAsync();
foreach (var c in children)
{
var childRow = Items.FirstOrDefault(r => r.Id == c.Id);
if (childRow is not null) childRow.Status = TaskStatus.Manual;
}
row.HasQueuedSubtasks = false;
}
else
{
entity.Status = TaskStatus.Manual;
await db.SaveChangesAsync();
row.Status = TaskStatus.Manual;
}
Regroup();
UpdateSubtitle();
TasksChanged?.Invoke(this, EventArgs.Empty);