fix(ui): stop ClearCompletedAsync from mutating chain-display fields
ClassifyItems() layers ApplyChainGrouping on top of partitioning, which writes ShowAsChainMember/ChainStep/ChainAfterLabel on every row. ClearCompletedAsync only needed the completed-section count/rows, so it got that mutation as an unwanted side effect of counting. Split the pure overdue/open/completed partition into PartitionItems(); ClassifyItems() now composes it with the chain-grouping mutation for Regroup's actual render path. ClearCompletedAsync uses PartitionItems directly. Regroup's behavior is unchanged.
This commit is contained in:
@@ -529,10 +529,11 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
|
||||
}
|
||||
|
||||
// Builds the hierarchy-aware flat ordering (top-level rows interleaved with visible children,
|
||||
// orphans flagged so they render flat) and classifies it into Overdue/Open/Completed, exactly
|
||||
// as Regroup renders it. Shared with callers that need "every completed row" independent of
|
||||
// Rows/IsShowingCompleted (e.g. ClearCompletedAsync).
|
||||
private (List<TaskRowViewModel> Overdue, List<TaskRowViewModel> Open, List<TaskRowViewModel> Completed) ClassifyItems()
|
||||
// orphans flagged so they render flat) and partitions it into Overdue/Open/Completed. Pure
|
||||
// with respect to chain state (ShowAsChainMember/ChainStep/ChainAfterLabel) — callers that
|
||||
// only need section membership/counts (e.g. ClearCompletedAsync) should use this directly
|
||||
// rather than ClassifyItems, which additionally mutates every row via ApplyChainGrouping.
|
||||
private (List<TaskRowViewModel> Overdue, List<TaskRowViewModel> Open, List<TaskRowViewModel> Completed) PartitionItems()
|
||||
{
|
||||
// Items is already ordered by SortOrder from the DB query.
|
||||
// Treat rows whose ParentTaskId is not in the current view as orphans -> top-level.
|
||||
@@ -580,6 +581,17 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
|
||||
open.Add(r);
|
||||
}
|
||||
|
||||
return (overdue, open, completed);
|
||||
}
|
||||
|
||||
// ClassifyItems layers the chain-grouping mutation on top of PartitionItems, exactly as
|
||||
// Regroup renders it — every row in the result has ShowAsChainMember/ChainStep/ChainAfterLabel
|
||||
// written. Only call this from a path that actually renders the result; a caller that just
|
||||
// needs section membership (e.g. a count) should call PartitionItems instead.
|
||||
private (List<TaskRowViewModel> Overdue, List<TaskRowViewModel> Open, List<TaskRowViewModel> Completed) ClassifyItems()
|
||||
{
|
||||
var (overdue, open, completed) = PartitionItems();
|
||||
|
||||
// Dependency chains are resolved and pulled together per section (not on the
|
||||
// pre-split `flat` list): a chain head might land in a different section than its
|
||||
// dependent (e.g. a Done head in Completed, an open dependent in Open) — in that case
|
||||
@@ -965,7 +977,7 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
|
||||
[RelayCommand]
|
||||
private async Task ClearCompletedAsync()
|
||||
{
|
||||
var (_, _, completed) = ClassifyItems();
|
||||
var (_, _, completed) = PartitionItems();
|
||||
if (completed.Count == 0) return;
|
||||
|
||||
// Delete children before parents so the parent-child FK (Restrict) doesn't
|
||||
|
||||
Reference in New Issue
Block a user