Skip to content

feat: sort groups by a summary value such as the group's sum or count (#405) - #518

Open
michaelstonis wants to merge 2 commits into
mainfrom
feat/405-group-sort-by-summary
Open

michaelstonis wants to merge 2 commits into
mainfrom
feat/405-group-sort-by-summary

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Closes #405.

Changes

Groups can now be ordered by an aggregate over each group's rows instead of by key.

  • GroupDescription.SortBySummary (SummaryColumnDescription?, default null = key order). Only PropertyName, SummaryType and, for Custom, CustomAggregate are used; Count counts the group's rows and ignores the property. The existing SummaryColumnDescription is reused (the issue's open question); no new type.
  • ViewBuilder: GroupSpec captures a GroupSortSummarySpec (an ItemReader for the property plus a private copy of the description, so worker builds never read live objects). In the grouping loop, one PropertyAggregate per bucket is fed while rows are assigned to buckets (same accumulators as visible summaries, so null handling and numeric conversion match; no extra pass, one extra read per row per level that uses it). Buckets then sort by aggregate (KumikoComparer: numbers numerically, dates chronologically), then by key, then display text, then first appearance. The direction is GroupSortDirection and applies to the key tie-break too. Same code path for synchronous and background builds.
  • KumikoSource.ItemPropertyImpact returns PropertyImpact.Rows for a change to a property a level sorts by (not for Count, which does not read it), so the groups reorder; expanded state is keyed by GroupKeyPath and survives.
  • KumikoGroupLayoutState gains SortSummaryPropertyName and SortSummaryType (nullable, additive; CurrentVersion stays 1). CustomAggregate is not saved. Applying a layout that saved no summary clears a non-custom SortBySummary and keeps a code-set custom one. This edit is two properties at the end of the class, to keep it small for the Layout state: save and restore expanded groups, selection, scroll position and summary rows #354 branch.
  • No input handling change: a grouping-panel chip tap still flips GroupSortDirection, which now flips the summary order as well (documented in the XML docs and README).
  • No renderer, input controller or hit tester changes. The header-menu entry point (Columns: add a drawn popup-menu component and a default column header menu (sort, filter, group, hide, auto-fit) #319) is out of scope.
  • Samples: "Largest Departments First" button on the Grouping page of both sample apps.
  • Docs: README "Sort groups by a summary" section (code and XAML) and a pointer in the Grouping intro; CHANGELOG entry.

Public API added (in PublicAPI.Unshipped.txt): GroupDescription.SortBySummary (get, set), KumikoGroupLayoutState.SortSummaryPropertyName (get, set), KumikoGroupLayoutState.SortSummaryType (get, set).

Acceptance criteria

  • Behavior tests in tests/KumikoUI.Core.Tests/KumikoSourceGroupingTests.cs: Sum, Average, Count, Min, Max and Custom in both directions; ties by key; Count ignores the property; filter applies; nested levels independent; item change reorders; layout state round trip (plus no-summary and apply-without-summary cases). The synchronous-versus-background comparison is in BackgroundRebuildTests.cs next to the other background-equals-synchronous tests (it needs that file's worker harness).
  • Works on MAUI and Uno, from code and XAML. GroupDescriptions is already settable on both hosts, so there is no host code. The nested SummaryColumnDescription element (GroupDescription.SortBySummary property element) was verified to compile in the Uno sample XAML. The MAUI sample project does not restore on this machine (NU1605 package conflict between SkiaSharp.Views.Maui and Microsoft.Maui.Controls, unrelated to this change), so MAUI XAML parsing of the nested element was not compiled here; the MAUI library builds.
  • Grouping page in both sample apps offers "largest groups first" ("Largest Departments First").
  • XML docs on every new public member.
  • PublicAPI.Unshipped.txt updated. eng/update-public-api.sh Core emptied the file without regenerating it in this environment, so the six new lines were added by hand (the file was restored first); the build reports no RS0016.
  • README "Grouping" section updated.
  • CHANGELOG entry under Unreleased.
  • Keyboard group navigation and screen-reader behavior unchanged (no input, renderer or accessibility code touched).
  • No allocations added to the per-frame render path (grouping runs at build time only; nothing in rendering touched).

Verification

  • dotnet test tests/KumikoUI.Core.Tests: Passed 4383, Failed 0, Skipped 5 (the skips are pre-existing).
  • dotnet build src/KumikoUI.Core, src/KumikoUI.SkiaSharp: 0 warnings, 0 errors.
  • dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst, dotnet build src/KumikoUI.Uno -f net10.0-desktop: 0 errors (no new warnings; the existing Uno0001 notice remains).
  • dotnet build samples/SampleApp.Uno -f net10.0-desktop: 0 errors, with and without a temporary nested SortBySummary XAML element on the page.
  • dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst: fails at restore (NU1605), not caused by this change.
  • The README group-sort XAML snippet sits inside KumikoDataGrid.GroupDescriptions, so both documentation snippet projects build with 0 errors (a bare core: element is wrapped as a column).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Grouping: sort groups by a summary value such as the group's sum or count

1 participant