Skip to content

feat: remote view contract that pushes sort, filter, grouping and row windows to the server (#359) - #506

Open
michaelstonis wants to merge 2 commits into
mainfrom
feat/359-remote-view-contract
Open

michaelstonis wants to merge 2 commits into
mainfrom
feat/359-remote-view-contract

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Closes #359.

Changes

Adds one data-layer contract for server-side views: the grid's sort, filters, grouping and summaries are sent to an IKumikoRemoteSource, and the grid shows only the rows that come back. It is wired into KumikoSource and the view pipeline (ViewBuilder). Renderer, input controller and hit tester are not touched.

Query hook (works without a remote source too)

  • KumikoQuery (Sorts, Filters, Groups, IsEmpty, FindFilter, Empty) and KumikoSortDescriptor(PropertyName, Direction), with the names from Spec: paging and DataTable / dictionary / dynamic row sources #107 section 5.9. A column with no PropertyName sorts under its Key, since KumikoColumn has no Id.
  • KumikoSource.GetQuery() and KumikoSource.QueryChanged (KumikoQueryChangedEventArgs: Query, Changes as KumikoQueryChanges flags). It is raised once after a sort, filter or group change, after the *Changed events, and once per BeginUpdate batch. A canceled change or a no-op raises nothing.

Remote contract (KumikoUI.Core.Data)

  • IKumikoRemoteSource has Capabilities (KumikoRemoteCapabilities: Sort, Filter, Group, Summaries, TotalCount, DistinctValues) and QueryAsync(KumikoRemoteRequest, CancellationToken).
  • KumikoRemoteRequest carries:
    • Query
    • the row window: Skip and Take
    • the scope: GroupPath and GroupLevel
    • ReturnsGroups
    • Summaries and IncludeTotalCount
    • Reason (KumikoRemoteRequestReason)
  • KumikoRemoteResult has Items, TotalCount, Groups and Summaries. KumikoRemoteResult.SummaryKey(...) builds keys like "Amount:Sum", compared ignoring case. KumikoRemoteGroup(Key, ItemCount, Summaries) is one server group.
  • KumikoRemoteSource is a delegate implementation, with an optional distinct-values delegate. IKumikoDistinctValuesSource is the optional interface for a filter's value list.
  • KumikoRemoteView (KumikoSource.Remote) is the controller, built like KumikoIncrementalLoader. It exposes:
    • state: State (KumikoRemoteState: Idle, Loading, Failed), IsLoading, LastError, ErrorText, LastRequest
    • server results: TotalCount, Summaries
    • the row window: WindowStart, WindowSize (default DefaultWindowSize = 200), SetWindow(start, size)
    • methods: ReloadAsync(), WhenIdleAsync(), GetDistinctValuesAsync(column)
    • events: StateChanged, QueryFailed (KumikoRemoteQueryFailedEventArgs, with a settable ErrorText), ResultApplied
  • KumikoSource.RemoteSource turns remote mode on. While it is set:
    • The bound items are kept aside and restored when it is cleared, including items bound in the meantime.
    • Sort and filter changes still raise their events. The local rebuild skips the parts the server does, and one request goes out.
    • Requests are coalesced per batch and per turn of the UI thread (posted to the owner SynchronizationContext).
    • One query is in flight at a time. A newer request cancels the older one through its token, and a generation counter drops late results (the Spec: incremental / load-more data loading (ISupportIncrementalLoading, NearEnd hook, loading row) #104 pattern). Results are applied on the UI thread.
    • A failure keeps the old rows and raises QueryFailed.
    • Capabilities the source lacks are applied locally to the loaded rows.
    • SetFilter(predicate) throws under a source that filters, and a GroupDescription.KeySelector throws under a source that groups, both on the setter and on later calls.
    • Incremental loading (Scrolling: implement incremental "load more" on scroll with a drawn loading and retry row (spec #104) #318) is inactive, so the two modes are exclusive.
    • RemoveItems and ReorderRow report NotSupportedSource.
    • Background rebuilds stay off: a result is one window, built synchronously.
  • Stage 2 (totals and summaries): TotalCount is exposed. With Summaries, table, group and caption summaries show the server's values (SummaryText.BuildRowFromValues and BuildCaptionFromValues) instead of aggregating, and nothing updates in place.
  • Stage 3 (server grouping): with Group, the top-level request returns Groups. ViewBuilder.BuildRemoteGroups draws them as group headers with the server's counts and summaries, keyed by GroupKeyPath, so expand state and ToggleGroupExpansion work as before. A group's rows, or its child groups for nested levels, are requested with its GroupPath when it is first expanded. Collapsed groups load nothing. A failed group request is retried when the group is expanded again. Old groups stay on screen until a new grouped result arrives.
  • Room for hierarchical rows (Data: hierarchical row source #454): a request names a scope and a result returns one level (rows, or child groups), so the contract does not assume flat rows. A parent-item scope for hierarchical sources can be added to the request without breaking anything.

Hosts (MAUI and Uno, same names)

  • New members on both: RemoteSource, RemoteWindowSize (200), read-only RemoteState, RemoteQueryFailed (sender is the grid) and ReloadRemoteAsync().
  • Loading, the row count and failures are announced through the new KumikoAnnouncements.RemoteStateChanged. New strings: AnnounceRemoteLoading, AnnounceRemoteLoaded, RemoteLoadFailed and AnnounceRemoteLoadFailed.

Samples and docs

  • A Remote Data page in both sample apps, over a shared fake server (samples/Shared/RemoteQueryOrders.cs) that sorts, filters, groups and totals 5,000 orders. The page has latency, a forced failure, row-window paging, grouping by region and Reload.
  • A README section "Remote Data" with compiled snippets, plus the sample table row and a CHANGELOG entry.

Small edits to existing code:

  • KumikoIncrementalLoader returns early in remote mode.
  • KumikoSource.SetItems is split into SetItemsCore.
  • EndUpdate raises QueryChanged after the view notification.
  • CaptureBuildSettings leaves out what the server does.
  • ItemPropertyImpact no longer rebuilds for a server-side sort, filter or group key.

Acceptance criteria

  • Stages 1 to 3 merged; a source without IKumikoRemoteSource behaves exactly as today. All 4,398 existing and new Core tests pass, with no change to local behavior apart from the new QueryChanged event.
  • One coalesced request per sort, filter, group and window change; stale results ignored; failures keep the old rows and raise QueryFailed.
  • Server totals and summaries show in summary rows; server groups expand on demand. Table, group and caption summaries are covered. Expanding beyond the first window of a large group is Scrolling: virtualize data by fetching row windows on demand with placeholder rows #360 work.
  • Behavior tests in tests/KumikoUI.Core.Tests with a fake remote source. 37 tests in Remote/RemoteViewTests.cs cover latency, cancellation, failure, retry, coalescing, marshaling to the UI thread, grouping, summaries and a synchronous source. There are 3 host tests in KumikoUI.Maui.Tests.
  • Works on MAUI and Uno with the same members.
  • Sample page over a fake remote API (latency and a forced failure) on both sample apps. The Uno sample builds. The MAUI sample could not be restored on this machine (NU1605: the installed MAUI 10.0.41 is lower than the 10.0.110 that SkiaSharp.Views.Maui needs). That is unrelated to this change; the KumikoUI.Maui library builds.
  • XML docs on every new public member; PublicAPI.Unshipped.txt updated. Core, Maui and Uno are updated. On this machine eng/update-public-api.sh emptied the file instead of filling it, so the entries were added from the RS0016 diagnostics and kept sorted.
  • README data-binding section and a cookbook page; CHANGELOG entry. Partly done. The README "Remote Data" section has two recipes, and the CHANGELOG entry is in. There is no separate cookbook page because the repository has no cookbook folder yet (spec Spec: API reference site (DocFX) and cookbook for custom columns, renderers and editors #110 is not built).
  • Loading and failure states announced to screen readers.
  • No allocations added to the per-frame render path. The only per-frame addition is a null and bool check in the load-more loader. RenderAllocationTests pass.

Deferred to #360, as scoped: placeholder rows, scroll-driven window fetching, the page cache, IsRowLoaded, scrollbar extent from TotalCount, and windows beyond the first one inside a server group. Also deferred: the drawn filter popup does not call GetDistinctValuesAsync yet and still lists loaded values. That wiring belongs with #353. The visual loading indicator for remote loads is #327.

Verification

  • dotnet build src/KumikoUI.Core (Debug and Release): succeeded, 0 warnings.
  • dotnet build src/KumikoUI.SkiaSharp: succeeded.
  • dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: succeeded, 0 warnings.
  • dotnet build src/KumikoUI.Uno -f net10.0-desktop: succeeded. The only warnings are the existing Uno0001 ones in Editing.cs and Input.cs.
  • dotnet build samples/SampleApp.Uno -f net10.0-desktop: succeeded.
  • dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst: restore fails with NU1605 on this machine's MAUI workload (see above).
  • dotnet test tests/KumikoUI.Core.Tests: 4,398 passed, 5 skipped, 0 failed.
  • dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.
  • dotnet test tests/KumikoUI.Maui.Tests: 452 passed.
  • dotnet test tests/KumikoUI.Uno.Tests: 321 passed.
  • dotnet run --project eng/DocsSnippets -c Release, then dotnet build tests/KumikoUI.Docs.Snippets.Uno -c Release: succeeded, with the new README snippets included.
  • dotnet run --project eng/TypeNameCheck -c Release -- src/KumikoUI.Core/bin/Release/net10.0/KumikoUI.Core.dll: no public type name collides.
  • The four xUnit1031 warnings are gone: the tests that blocked on a task (Task.Run(...).Wait(), .Result, Wait(2000)) are async Task and await it (WaitAsync with the same 2 s limit). Core and MAUI test projects pass.

Comment on lines +497 to +498
foreach (var item in _items)
if (item != null) list.Add(item);
Comment on lines +519 to +524
foreach (var item in node.Items)
{
if (item == null) continue;
combined.Add(item);
count++;
}
Comment on lines +615 to +628
foreach (var group in groups)
{
if (group == null) continue;
nodes.Add(new RemoteGroupNode
{
Tree = this,
Key = group.Key,
ItemCount = Math.Max(0, group.ItemCount),
Summaries = group.Summaries,
Level = level,
Parent = parent,
KeyPath = new GroupKeyPath(parent?.KeyPath, property, group.Key),
});
}
Comment on lines +132 to +133
foreach (var column in columns)
if (keys.Add(KumikoRemoteResult.SummaryKey(column))) result.Add(column);
Comment on lines +37 to +40
if (texts.TryGetValue(displayText, out int seen))
texts[displayText] = ordinal = seen + 1;
else
texts[displayText] = 1;
Comment on lines +107 to +113
foreach (var row in _s.GroupSummaries)
{
if (row.Levels == GroupSummaryLevels.Innermost && !isInnermost) continue;
specs.Add(row);
rows.Add(SummaryText.BuildRowFromValues(row.Name, row.Title, row.Columns,
d => KumikoRemoteResult.Lookup(values, d), _s.Comparer.Culture, _s.Strings));
}

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.

Data: define a remote view contract that pushes sort, filter, grouping and row windows to the server

2 participants