Repository navigation
feat: save and restore expanded groups, selection, scroll position and summary rows in the layout state (#354) - #505
Open
michaelstonis wants to merge 2 commits into
Open
michaelstonis wants to merge 2 commits into
michaelstonis wants to merge 2 commits into
Conversation
…d summary rows in the layout state (#354)
8 tasks done
Comment on lines
+187
to
+192
| foreach (int row in selection.SelectedRows.OrderBy(r => r)) | ||
| { | ||
| if (source.IsNonDataRow(row)) continue; | ||
| string? key = selector(source.GetItem(row)); | ||
| if (key != null) state.SelectedKeys.Add(key); | ||
| } |
Comment on lines
+84
to
+115
| foreach (var entry in saved) | ||
| { | ||
| if (entry?.Path is not { Count: > 0 } path || path.Count > _groupDescriptions.Count) continue; | ||
| var node = root; | ||
| bool valid = true; | ||
| for (int level = 0; level < path.Count && valid; level++) | ||
| { | ||
| var segment = path[level]; | ||
| valid = segment != null | ||
| && string.Equals(segment.PropertyName, _groupDescriptions[level].PropertyName, StringComparison.Ordinal); | ||
| if (!valid) break; | ||
|
|
||
| GroupPathNode? child = null; | ||
| foreach (var existing in node.Children) | ||
| { | ||
| if (existing.Kind == segment!.ValueKind && string.Equals(existing.Text, segment.Value, StringComparison.Ordinal)) | ||
| { | ||
| child = existing.Node; | ||
| break; | ||
| } | ||
| } | ||
| if (child == null) | ||
| { | ||
| child = new GroupPathNode(); | ||
| node.Children.Add((segment!.ValueKind, segment.Value, child)); | ||
| } | ||
| node = child; | ||
| } | ||
| if (!valid) continue; | ||
| if (node.Expanded == null) wanted++; | ||
| node.Expanded = entry.IsExpanded; | ||
| } |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #354.
Changes
KumikoLayoutState(format version 2) can now also hold the expanded groups, the selection, the scroll position and the summary rows. The parts are opt-in, so existing callers and version 1 documents behave as before.KumikoLayoutParts(Columns,Grouping,GroupExpansion,Selection,Scroll,Summaries,Default= Columns | Grouping,All) andKumikoLayoutCaptureOptions(Parts,ItemKeySelector). A part is applied only when the options ask for it and the layout holds it (the new properties are null when not captured).ExpandedGroups(each group that differs from the default, named by the keys of its path:KumikoGroupExpansionLayoutState,KumikoGroupKeyLayoutState; key values reuse the filter value encoding, now shared through an internalKumikoLayoutValue) andDefaultGroupExpanded. Restore runs in the sameBeginUpdateas the grouping, so there is one rebuild; background rebuilds snapshot the restored state. Saved keys are matched to the live keys by their invariant text (one pass over the items, each distinct key matched once, early exit), so int, enum, date, bool and text keys come back as the real key objects and unknown keys are ignored.Selection(KumikoSelectionLayoutState: selected keys, current key, current column key), named byItemKeySelector. Without a selector the part is skipped with one trace warning. Restore usesSetSelectedItemsandSetCurrentCell; while a background rebuild is pending it waits for the view to be published (internalKumikoLayoutRestore, driven byViewUpdatePendingChanged), and a newer restore replaces a waiting one.Scroll(KumikoScrollLayoutState: offsets and, with a selector, the first visible data row's key).KumikoScrollLayoutState.ApplyTo(ScrollState, KumikoSource, KumikoStyle, options)goes throughKumikoScroller(RefreshContentExtents,ScrollToItem(..., Start, expandGroups: false), thenScrollTo), falling back to the offsets and clamping to the content. No input-controller or renderer code is involved.TableSummaryRows/GroupSummaryRows(KumikoSummaryRowLayoutState,KumikoSummaryColumnLayoutState). Rows are replaced; code that cannot be saved (CustomAggregate,CustomCellRenderer) is carried over from the grid's row of the same name with the same property and type, and aCustomaggregate with no such row is left out.GetLayoutState(KumikoLayoutCaptureOptions?)andApplyLayoutState(KumikoLayoutState, KumikoLayoutCaptureOptions?); the existing overloads delegate with null options.TableSummaryRowsandGroupSummaryRowsfollow a restore (guarded against the collection-changed handlers rebuilding twice), asGroupDescriptionsalready did.ShowcaseData.LayoutOptionsis shared.Public API added (
PublicAPI.Unshipped.txt)KumikoLayoutParts,KumikoLayoutCaptureOptions,KumikoGroupExpansionLayoutState,KumikoGroupKeyLayoutState,KumikoSelectionLayoutState,KumikoScrollLayoutState(withApplyTo),KumikoSummaryRowLayoutState,KumikoSummaryColumnLayoutState; onKumikoLayoutState:LatestVersion,ExpandedGroups,DefaultGroupExpanded,Selection,Scroll,TableSummaryRows,GroupSummaryRows,Capture(source, options),Capture(source, selection, scroll, style, options),ApplyTo(source, options),ApplyTo(source, selection, options).KumikoDataGrid:GetLayoutState(options),ApplyLayoutState(state, options).Deviation from the issue text
The issue proposes
CurrentVersion = 2.KumikoLayoutState.CurrentVersionis a shipped constant (= 1), and the frozen 1.0.0 API cannot change it, so it stays 1 and a newLatestVersion = 2is whatCapturewrites and whatVersiondefaults to.Acceptance criteria
Version(tests:Version1Json_*,DefaultCapture_IsTheOldShape_PlusVersion2, the existing JSON-shape tests).BackgroundRebuildThreshold(BackgroundRebuild_SelectionIsRestoredWhenTheViewIsPublished_ExpansionBuildsStraightIn).tests/KumikoUI.Core.Tests/KumikoLayoutStateTests.cs(plus two host tests inKumikoDataGridMappingTests.cs).PublicAPI.Unshipped.txtupdated for Core, Maui and Uno.Verification
dotnet build src/KumikoUI.Core --no-incremental: 0 warnings, 0 errors.dotnet build src/KumikoUI.SkiaSharp --no-incremental: 0 warnings, 0 errors.dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst --no-incremental: 0 warnings, 0 errors.dotnet build src/KumikoUI.Uno -f net10.0-desktop --no-incremental: 0 errors; the only 2 warnings are existingUno0001ones in files this change does not touch.dotnet build samples/SampleApp.Uno -f net10.0-desktop: succeeded, 0 warnings.dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst: fails at restore with NU1605 (Microsoft.Maui.Controls 10.0.41 vs 10.0.110 package downgrade), unrelated to this change; not built here.dotnet test tests/KumikoUI.Core.Tests: 4384 passed, 5 skipped (the 41 layout-state tests included, run several times for the background test).dotnet test tests/KumikoUI.Maui.Tests: 451 passed.dotnet test tests/KumikoUI.Uno.Tests: 321 passed.dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.eng/update-public-api.shdid not write anything on this machine (the RS0016 code fix ofdotnet format analyzersmade no changes), so thePublicAPI.Unshipped.txtlines were taken from the RS0016 build diagnostics and merged in sorted order; the Core, Maui and Uno builds are clean against them.Employeeand declareslayoutPath, so both documentation snippet projects build with 0 errors.