Skip to content

feat: add cross-column filter expressions with nested AND/OR groups (#408) - #519

Open
michaelstonis wants to merge 1 commit into
mainfrom
feat/408-filter-expression
Open

michaelstonis wants to merge 1 commit into
mainfrom
feat/408-filter-expression

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Part of #408.

Changes

Stage 1 of the issue, the model and its evaluation, plus host properties, layout state, docs and tests. The drawn builder popup (DrawnFilterBuilder, ShowFilterBuilder/CloseFilterBuilder, FilterBuilderOpened/Closed) is held until Foundations #446/#448 land, because it is hosted by the input controller. Nothing under src/KumikoUI.Core/Input/ and no KumikoRenderer*.cs file is touched.

  • KumikoFilterExpression (new, Models/KumikoFilterExpression.cs): one node type. It is a group (Combination And/Or, IsNegated, Children) or, when Condition is set, a condition on ColumnKey (a FilterCondition). IsGroup tells them apart. IsNegated works on a condition too. Factories: And(...), Or(...), Not(child), Where(columnKey, condition). Clone() makes a deep, editable copy. IsReadOnly is true for the copy a source keeps: its setters and Children throw on change. Null children are rejected. MaxDepth (16) is the depth limit and also catches a tree that contains itself.
  • KumikoSource (new partial KumikoSource.FilterExpression.cs): FilterExpression (the read-only copy), SetFilterExpression(expression) (copies the tree, rebuilds once, raises FilterExpressionChanged) and FilterExpressionChanged with KumikoFilterExpressionChangedEventArgs (OldExpression, NewExpression).
  • Evaluation: every view build captures an immutable FilterExpressionSpec tree. Columns are resolved by Key, else PropertyName, as layout state does, and each referenced column gets one ItemReader that its conditions share. A worker build copies the conditions, so background builds never read the live tree or the columns. Each condition is evaluated by its column's ColumnType, the same way a column filter's conditions are. A Boolean condition matches cells equal to its Value (the column filter's Boolean condition passes every row, so it could not be reused). A condition on an unknown column is inactive, and so is a group with no active children; inactive nodes are dropped from their group, so an empty group passes every row, negated or not. The expression is ANDed in ViewBuilder.Passes (new optional parameter), which covers the foreground and background rebuilds, the incremental insert path and GetUniqueColumnValues.
  • Rebuild triggers: ItemPropertyImpact treats properties read by referenced columns as row-affecting. A referenced column's ValueAccessor or ColumnType change rebuilds, and so does any column's Key or PropertyName change while an expression is set. Columns are matched at every rebuild, so an expression set before its columns exist (for example generated ones) applies once they appear.
  • ClearAllFilters clears the expression too and raises FilterExpressionChanged. IsFiltered counts an expression that has an active condition.
  • Layout state: KumikoLayoutState.FilterExpression (KumikoFilterExpressionLayoutState) is one class for both node kinds (Combination, IsNegated, Children, ColumnKey, Condition as KumikoFilterConditionLayoutState), so the existing source-generated KumikoLayoutJsonContext handles it with no polymorphism. The type is reached through the property graph, so no registration line was needed. CurrentVersion stays 1. Capture writes an empty group when the source has no expression, so applying a captured layout clears one; null (a layout saved before this change) leaves the current expression in place.
  • Hosts: a two-way FilterExpression bindable property on MAUI and a dependency property on Uno, plus a FilterExpressionChanged event on both (KumikoDataGrid.FilterExpression.cs). The property holds the source's read-only copy and follows the source (ClearAllFilters, ApplyLayoutState).
  • Compatibility with Filtering: per-column allowed operators, default operator and case sensitivity #373 (per-column comparers): every condition in the captured tree carries its own KumikoComparer, chosen in one seam, FilterExpressionSpec.ConditionComparer(column, comparer), which returns the build's comparer for now. When Filtering: per-column allowed operators, default operator and case sensitivity #373 merges, that line becomes the column's filter comparer (the one Filtering: per-column allowed operators, default operator and case sensitivity #373 caches per culture and options), and expression conditions then follow the column's case sensitivity in both build paths. Both branches add an argument to ViewBuilder.Passes and touch PrepareFilters callers, so expect a small textual merge there.
  • Public API added: 40 lines in Core, 4 in each host (PublicAPI.Unshipped.txt). eng/update-public-api.sh empties the Core file in this environment, so the lines were added by hand from the RS0016 list, in sorted order.
  • Docs: the README "Filtering" section has a new "Filter expressions across columns" subsection, and "Saving and restoring the layout" is updated. There is a CHANGELOG entry under Unreleased.

Acceptance criteria

Verification

  • dotnet build src/KumikoUI.Core: Build succeeded, no warnings
  • dotnet build src/KumikoUI.SkiaSharp: Build succeeded
  • dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: Build succeeded
  • dotnet build src/KumikoUI.Uno -f net10.0-desktop: Build succeeded (only the existing Uno0001 warnings in other files)
  • dotnet test tests/KumikoUI.Core.Tests: 4388 passed, 5 skipped, 0 failed
  • dotnet test tests/KumikoUI.Maui.Tests: 451 passed
  • dotnet test tests/KumikoUI.Uno.Tests: 321 passed
  • dotnet run --project eng/DocsSnippets -c Release, then dotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Release and dotnet build tests/KumikoUI.Docs.Snippets.Maui -f net10.0-maccatalyst -c Release: both succeeded (the new README snippet compiles on both hosts)

…408)

KumikoFilterExpression trees of groups and column conditions, evaluated with the column filters and the predicate in synchronous and background builds, cleared by ClearAllFilters, saved in KumikoLayoutState, and exposed as FilterExpression on the MAUI and Uno grids. The drawn filter builder is not part of this change.
};
if (copy._condition == null)
{
var children = (ChildCollection)copy.Children;

source.SetFilterExpression(expression);
expression.Children.Add(Text(nameof(Row.Region), TextFilterOperator.Equals, "East")); // not seen by the source
((FilterCondition)expression.Children[0].Condition!).Value = "North";
Comment on lines +75 to +76
foreach (var child in state.Children)
if (child != null) node.Children.Add(ToNode(child, depth + 1));
Comment on lines +95 to +102
foreach (var col in _columns)
{
if (!_filterExpressionKeys.Contains(col.LayoutKey)) continue;
// A value accessor or the item itself (empty path) may depend on any property.
if (col.ValueAccessor != null || string.IsNullOrEmpty(col.PropertyName) ||
PropertyPathAffected(col.PropertyName, propName))
return true;
}
Comment on lines +185 to +189
foreach (var child in node.Children)
{
if (Capture(child, columns, readers, comparer, forWorker) is { } spec)
(children ??= new()).Add(spec);
}
Comment on lines +224 to +227
foreach (var child in _children)
{
if (!child.Evaluate(item)) { result = false; break; }
}

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.

2 participants