From 0dd59a1e7b0fca36950313c4216fbb7f403cbbbf Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Thu, 21 Jan 2021 13:47:40 +1300 Subject: [PATCH] BUG Reset GridFieldFilterHeader grid state when search is cleared (#9829) --- src/Forms/GridField/GridFieldFilterHeader.php | 1 + .../GridField/GridFieldFilterHeaderTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Forms/GridField/GridFieldFilterHeader.php b/src/Forms/GridField/GridFieldFilterHeader.php index 6efe105d9..3d5888212 100755 --- a/src/Forms/GridField/GridFieldFilterHeader.php +++ b/src/Forms/GridField/GridFieldFilterHeader.php @@ -176,6 +176,7 @@ class GridFieldFilterHeader implements GridField_URLHandler, GridField_HTMLProvi } $state = $this->getState($gridField); + $state->Columns = []; if ($actionName === 'filter') { if (isset($data['filter'][$gridField->getName()])) { diff --git a/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php b/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php index 41dd7b725..91e1a14f3 100644 --- a/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php +++ b/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php @@ -118,4 +118,25 @@ class GridFieldFilterHeaderTest extends SapphireTest $this->assertEquals('place', $searchSchema->filters->Search__City); $this->assertEquals('testfield', $searchSchema->gridfield); } + + public function testHandleActionReset() + { + // Init Grid state with some pre-existing filters + $state = $this->gridField->State; + $state->GridFieldFilterHeader = []; + $state->GridFieldFilterHeader->Columns = []; + $state->GridFieldFilterHeader->Columns->Name = 'test'; + + $this->component->handleAction( + $this->gridField, + 'reset', + [], + '{"GridFieldFilterHeader":{"Columns":{"Name":"test"}}}' + ); + + $this->assertEmpty( + $state->GridFieldFilterHeader->Columns->toArray(), + 'GridFieldFilterHeader::handleAction resets the gridstate filter when the user resets the search.' + ); + } }