Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function handle(array $gridConfiguration): array
foreach ($gridConfiguration['sorting'] as $sorting => $order) {
Assert::keyExists($gridConfiguration['fields'] ?? [], $sorting);

if (isset($gridConfiguration['fields'][$sorting]['sortable'])) {
continue;
}

$gridConfiguration['fields'][$sorting]['sortable'] = true;
}
Comment on lines 26 to 34

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if using isset here is the right solution.

Looking at the tests, I had to update the line for the author because its sortable value was originally being changed from false to true. However, with these changes, that no longer happens.

Maybe the value should be set to true if it's either not set or currently false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe should we throw an error that indicates the field is not sortable.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ public function testHandle(): void
'title' => [],
'author' => ['sortable' => false],
'price' => ['sortable' => true],
'name' => ['sortable' => 'translation.name'],
],
'sorting' => [
'title' => 'asc',
'author' => 'asc',
'price' => 'asc',
'name' => 'asc',
],
];

$this->assertEquals([
$this->assertSame([
'fields' => [
'title' => ['sortable' => true],
'author' => ['sortable' => true],
'author' => ['sortable' => false],
'price' => ['sortable' => true],
'name' => ['sortable' => 'translation.name'],
],
'sorting' => [
'title' => 'asc',
'author' => 'asc',
'price' => 'asc',
'name' => 'asc',
],
], (new GridConfigurationSortingHandler())->handle($gridConfiguration));
}
Expand Down