Skip to content

fix(widget-plugin-grid): Clear Selection action wins over Keep selection [WC-3461]#2349

Draft
iobuhov wants to merge 1 commit into
mainfrom
fix/WC-3461-js-action-clear-selection
Draft

fix(widget-plugin-grid): Clear Selection action wins over Keep selection [WC-3461]#2349
iobuhov wants to merge 1 commit into
mainfrom
fix/WC-3461-js-action-clear-selection

Conversation

@iobuhov

@iobuhov iobuhov commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Why

The Clear Selection JavaScript action (used by Data Grid 2 and Gallery) did not clear the selection when the widget's Keep selection property was enabled — keep selection always won. createSelectionHelper installed an unconditional setKeepSelection(() => true) predicate, which the Mendix runtime re-evaluates on every datasource reconciliation, so the clear's setSelection([]) was undone on the next reconciliation.

Ticket: WC-3461

What changed

Scope: packages/shared/widget-plugin-grid only. Both widgets inherit the fix through the shared createSelectionHelper — no per-widget source changes.

  • The keep predicate is now backed by a transient keepActive observable read live: setKeepSelection(() => keepActive.get()), installed via the setup() lifecycle instead of eagerly.
  • On a clear (MultiSelectionHelper.clearSelection, SingleSelectionHelper.remove), beforeClear() snapshots the current selection ref, drops keepActive to false (so the runtime does not restore during the clear's reconciliation), then re-arms via when(() => selectionValue !== clearedRef, () => keepActive.set(true)).
  • Re-arm keys off a ref change (the reconciliation signal), not emptiness — so keep also re-arms correctly when the user re-selects a different item before the empty selection lands. An emptiness-based guard would strand keep off in that case.
  • Keep logic is inlined into each helper (no separate class); the when self-disposes after firing, is disposed on re-entrant/double clears, and is cancelled on teardown.
  • widget-plugin-test-utils builders capture the predicate so the keep-vs-clear interaction is testable.

Testing

  • widget-plugin-grid: 18 suites / 146 tests pass, including new keep-vs-clear cases (clear-beats-keep, keep-resumes-after-clear, rearm-on-reselect, double-clear-reentrancy, clear-without-keep, dispose-mid-clear, predicate-installed-via-setup).
  • datagrid-web / gallery-web: all selection-touching suites pass. Remaining failing suites fail identically on clean main (pre-existing dual-mendix-version type conflict in test helpers, unrelated to this change).

Still open (why this is a draft)

  • Manual/E2E verification pending: drive the Clear_Selection JS action with Keep selection enabled in a real widget and confirm the selection clears and keep resumes on the next page change. The approach assumes the runtime evaluates the keep predicate during reconciliation (before delivering the new ref that re-arms) — an ordering not provable from unit tests.

🤖 Generated with Claude Code

…ext reconciliation

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant