Skip to content

fix: Remove a grid filter from the state when its value is cleared - #21

Merged
jissereitsma merged 1 commit into
LokiExtensions:masterfrom
lbajsarowicz:fix/19-clear-grid-filters
Nov 16, 2026
Merged

jissereitsma merged 1 commit into
LokiExtensions:masterfrom
lbajsarowicz:fix/19-clear-grid-filters

Conversation

@lbajsarowicz

@lbajsarowicz lbajsarowicz commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • bin/magento setup:di:compile and setup:static-content:deploy -f en_US on Magento Open Source 2.4.9 / PHP 8.5 with this branch installed: both pass.

Refs #19. After the bookmark merge, clearing a filter still leaves the old behaviour in place. Filter::isEmpty() only treats null as empty, so a cleared select ('') or an empty multiselect ([]) is stored and applied as a real condition. FilterAction also does continue for an empty value, so the previously stored filter is never removed and a cleared text filter keeps its old value.

Fix

  • Filter::isEmpty() now also returns true for '' and []. '0' and 0 stay real values.
  • FilterAction calls the new State::removeFilter() for an empty submitted value, which drops the filter from the session state and clears its entry in the bookmark's applied filters.

Why this approach

The empty check stays in Filter::isEmpty(), so custom filter implementations keep control of what counts as empty, and the action only decides what to do with the answer.

Test plan

  • Added Test/Unit/Grid/Filter/FilterTest.php and Test/Unit/Grid/Action/FilterActionTest.php.
  • Ran phpunit Test/Unit against a Magento 2.4.9 checkout: 146 tests, all pass. With the three Grid/ changes stashed, 2 errors and 2 failures in the new tests.
  • The integration tests were not run locally.

@jissereitsma

Copy link
Copy Markdown
Contributor

Nice, I didn't catch this yet. Merging :)

@jissereitsma
jissereitsma merged commit 8316858 into LokiExtensions:master Nov 16, 2026
5 of 12 checks passed
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.

2 participants