feat(ui): show child tasks as children in the merge-helper picker
MergeHelperSelectionModalViewModel now loads ParentTaskId and orders rows hierarchy-aware (parent immediately followed by its children, mirroring TasksIslandViewModel.Regroup). Children render indented with the same indent-track visual as the main task list; ticking a parent cascades selection to its children, while a child can still be deselected on its own. A child whose parent got filtered out (e.g. already Done) renders top-level with an explicit hint instead of disappearing. Confirm keeps returning parents ahead of their children.
This commit is contained in:
@@ -14,6 +14,16 @@ public sealed partial class MergeHelperTaskRowViewModel : ViewModelBase
|
||||
public required string Id { get; init; }
|
||||
public required string Title { get; init; }
|
||||
public required string StatusText { get; init; }
|
||||
public string? ParentTaskId { get; init; }
|
||||
|
||||
/// <summary>True when the parent is also a candidate and rendered directly above this row.</summary>
|
||||
public bool IsChild { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// True when <see cref="ParentTaskId"/> is set but the parent isn't a candidate itself
|
||||
/// (e.g. already Done/Cancelled) — the row still renders top-level, flagged with a hint.
|
||||
/// </summary>
|
||||
public bool IsOrphanChild { get; init; }
|
||||
|
||||
[ObservableProperty] private bool _isSelected;
|
||||
}
|
||||
@@ -28,6 +38,9 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private string _listId = "";
|
||||
|
||||
// Parent id -> its child rows, built after load; drives the tick-parent-ticks-children cascade.
|
||||
private Dictionary<string, List<MergeHelperTaskRowViewModel>> _childrenByParentId = new();
|
||||
|
||||
public ObservableCollection<MergeHelperTaskRowViewModel> Tasks { get; } = new();
|
||||
|
||||
[ObservableProperty] private string _scopeLabel = "";
|
||||
@@ -51,6 +64,7 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
{
|
||||
foreach (var row in Tasks) row.PropertyChanged -= OnRowChanged;
|
||||
Tasks.Clear();
|
||||
_childrenByParentId = new();
|
||||
|
||||
await using var ctx = await _dbFactory.CreateDbContextAsync(ct);
|
||||
var candidates = await ctx.Tasks.AsNoTracking()
|
||||
@@ -59,21 +73,56 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
// Manual tasks are reminders the user owns — never offer them to the handler.
|
||||
.Where(t => !t.IsManual)
|
||||
.OrderBy(t => t.SortOrder).ThenBy(t => t.CreatedAt)
|
||||
.Select(t => new { t.Id, t.Title, t.Status })
|
||||
.Select(t => new { t.Id, t.Title, t.Status, t.ParentTaskId })
|
||||
.ToListAsync(ct);
|
||||
|
||||
foreach (var c in candidates)
|
||||
var candidateIds = candidates.Select(c => c.Id).ToHashSet();
|
||||
bool ParentIsCandidate(string? parentId) =>
|
||||
!string.IsNullOrEmpty(parentId) && candidateIds.Contains(parentId);
|
||||
|
||||
var childrenByParent = candidates
|
||||
.Where(c => ParentIsCandidate(c.ParentTaskId))
|
||||
.GroupBy(c => c.ParentTaskId!)
|
||||
.ToDictionary(g => g.Key, g => g.ToList());
|
||||
|
||||
// Hierarchy-ordered walk, same idea as TasksIslandViewModel.Regroup: top-level rows
|
||||
// (including orphaned children whose parent isn't a candidate) interleaved with their
|
||||
// visible children, preserving the SortOrder/CreatedAt order within each level.
|
||||
var emitted = new HashSet<string>();
|
||||
var ordered = new List<(string Id, string Title, TaskStatus Status, string? ParentTaskId)>();
|
||||
void Emit(string id, string title, TaskStatus status, string? parentTaskId)
|
||||
{
|
||||
if (!emitted.Add(id)) return;
|
||||
ordered.Add((id, title, status, parentTaskId));
|
||||
if (childrenByParent.TryGetValue(id, out var kids))
|
||||
foreach (var kid in kids)
|
||||
Emit(kid.Id, kid.Title, kid.Status, kid.ParentTaskId);
|
||||
}
|
||||
foreach (var c in candidates.Where(c => !ParentIsCandidate(c.ParentTaskId)))
|
||||
Emit(c.Id, c.Title, c.Status, c.ParentTaskId);
|
||||
|
||||
foreach (var c in ordered)
|
||||
{
|
||||
var isChild = ParentIsCandidate(c.ParentTaskId);
|
||||
var row = new MergeHelperTaskRowViewModel
|
||||
{
|
||||
Id = c.Id,
|
||||
Title = c.Title,
|
||||
StatusText = c.Status.ToString(),
|
||||
ParentTaskId = c.ParentTaskId,
|
||||
IsChild = isChild,
|
||||
IsOrphanChild = !isChild && !string.IsNullOrEmpty(c.ParentTaskId),
|
||||
IsSelected = IsTickedByDefault(c.Status),
|
||||
};
|
||||
row.PropertyChanged += OnRowChanged;
|
||||
Tasks.Add(row);
|
||||
}
|
||||
|
||||
_childrenByParentId = Tasks
|
||||
.Where(r => r.IsChild)
|
||||
.GroupBy(r => r.ParentTaskId!)
|
||||
.ToDictionary(g => g.Key, g => g.ToList());
|
||||
|
||||
OnPropertyChanged(nameof(HasTasks));
|
||||
OnPropertyChanged(nameof(CanConfirm));
|
||||
}
|
||||
@@ -85,8 +134,18 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
|
||||
private void OnRowChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(MergeHelperTaskRowViewModel.IsSelected))
|
||||
OnPropertyChanged(nameof(CanConfirm));
|
||||
if (e.PropertyName != nameof(MergeHelperTaskRowViewModel.IsSelected)) return;
|
||||
|
||||
// Ticking/unticking a parent cascades to its children; a child can still be
|
||||
// deselected on its own afterwards without affecting the parent's checkbox —
|
||||
// ClaudeDo has no indeterminate/tri-state parent checkbox.
|
||||
if (sender is MergeHelperTaskRowViewModel row
|
||||
&& _childrenByParentId.TryGetValue(row.Id, out var children))
|
||||
{
|
||||
foreach (var child in children) child.IsSelected = row.IsSelected;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(CanConfirm));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
||||
Reference in New Issue
Block a user