Skip to content

fix: expression property setters replace state instead of being additive#60

Merged
rkaraivanov merged 4 commits intomasterfrom
copilot/fix-sorting-filtering-expressions
Apr 1, 2026
Merged

fix: expression property setters replace state instead of being additive#60
rkaraivanov merged 4 commits intomasterfrom
copilot/fix-sorting-filtering-expressions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Setting sortingExpressions or filterExpressions after initialization delegated to the additive sort()/filter() methods, causing new assignments to merge with existing state rather than replace it. Empty array assignment was also a no-op due to an expressions.length guard.

Changes

  • sortingExpressions / filterExpressions setters: Clear existing state via reset() before applying new expressions when the component has already rendered
  • Empty array handling: Properly clears all active expressions and triggers a pipeline update
// Before: additive — priority sort is preserved
grid.sortingExpressions = [{ key: 'priority', direction: 'descending' }];
grid.sortingExpressions = [{ key: 'name', direction: 'ascending' }];
grid.sortingExpressions; // [{key: 'priority', …}, {key: 'name', …}]

// After: replaces state
grid.sortingExpressions = [{ key: 'priority', direction: 'descending' }];
grid.sortingExpressions = [{ key: 'name', direction: 'ascending' }];
grid.sortingExpressions; // [{key: 'name', …}]

// Clearing now works
grid.sortingExpressions = [];
grid.sortingExpressions; // []

Tests

Added 4 tests covering replacement and clearing behavior for both sorting and filtering expression setters.

Copilot AI changed the title [WIP] Fix filtering and sorting expressions not removing previous state fix: expression property setters replace state instead of being additive Mar 31, 2026
Copilot AI requested a review from damyanpetev March 31, 2026 09:14
@damyanpetev damyanpetev requested a review from Copilot April 1, 2026 10:18
@damyanpetev damyanpetev marked this pull request as ready for review April 1, 2026 10:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes sortingExpressions / filterExpressions property setters so late-bound assignments replace existing sort/filter state (including correct clearing behavior when assigning an empty array), rather than merging with prior state.

Changes:

  • Update sortingExpressions and filterExpressions setters to clear existing state before applying new expressions after initial render.
  • Ensure empty-array assignments clear all active expressions and still trigger the data pipeline update.
  • Add tests covering replacement and clearing behavior for both sorting and filtering setters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/components/grid.ts Resets sort/filter state inside expression setters; removes empty-array guard in filter() to ensure pipeline updates on clears.
test/grid.properties.test.ts Adds 4 tests validating late-bound replacement and clearing for sort/filter expression setters.
Comments suppressed due to low confidence (1)

src/components/grid.ts:252

  • In the pre-render path (!hasUpdated), the setter writes expressions directly into sorting.state without applying the SortController rule that direction: 'none' should remove the expression. Since SortDataOperation.orderBy has no entry for 'none', allowing 'none' into the sort state can cause a runtime error during pipeline sorting (orderBy.get(direction)! becomes undefined). Consider mirroring SortController.#setExpression here (delete when direction is 'none') or routing through controller logic that enforces this invariant.
    } else {
      for (const expr of expressions) {
        this._stateController.sorting.state.set(expr.key, { ...expr });
      }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@damyanpetev damyanpetev requested a review from rkaraivanov April 1, 2026 10:23
@rkaraivanov rkaraivanov merged commit 823cfd6 into master Apr 1, 2026
9 checks passed
@rkaraivanov rkaraivanov deleted the copilot/fix-sorting-filtering-expressions branch April 1, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filtering & sorting expressions do not remove previous state

4 participants