BUG Reset GridFieldFilterHeader grid state when search is cleared (#9829)

This commit is contained in:
Maxime Rainville 2021-01-21 13:47:40 +13:00 committed by GitHub
parent 54bdabd203
commit 0dd59a1e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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()])) {

View File

@ -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.'
);
}
}