-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delegate filter query by empty value to filters #6402
Delegate filter query by empty value to filters #6402
Conversation
I understand your point, that's not a bad idea. ping @sonata-project/contributors |
1e38aa1
to
20e6b90
Compare
src/Datagrid/Datagrid.php
Outdated
{ | ||
if (isset($this->values['_per_page'])) { | ||
if (isset($this->values['_per_page']['value'])) { | ||
return (int) $this->values['_per_page']['value']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that this data comes from a request and it contains a string with a number, not a integer. Therefore, i am doing explicit type casting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's never too safe
Could you please rebase your PR and fix merge conflicts? |
20e6b90
to
d783be4
Compare
An upgrade note seems nice to explain the (big) impact of this change. |
d783be4
to
8d13142
Compare
### Empty values in datagrid filters | ||
|
||
Now empty values are passed to datagrid filters. If you have custom datagrid filters, add empty string check to them. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VincentLanglet please review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an exemple could be helpful:
Something like
In the following exemple
->add('with_open_comments', CallbackFilter::class, [
'callback' => static function(ProxyQueryInterface $queryBuilder, string $alias, string $field, array $value): bool {
if (!$value['value']) {
return false;
}
$queryBuilder
->leftJoin(sprintf('%s.comments', $alias), 'c')
->andWhere('c.status = :status')
->setParameter('status', Comment::STATUS_MODERATE);
return true;
},
'field_type' => CheckboxType::class
]);
The !$value['value']
check is required to not filtering by ''
if you didn't used the filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add this
You requested changes, can you take a new look @core23 ? =) |
8d13142
to
bf068fd
Compare
src/Datagrid/Datagrid.php
Outdated
|
||
private function applySorting(): void | ||
{ | ||
if (isset($this->values['_sort_by'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you invert this check to fail fast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?
src/Datagrid/Datagrid.php
Outdated
|
||
private function getMaxPerPage(int $default): int | ||
{ | ||
if (isset($this->values['_per_page'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/Datagrid/Datagrid.php
Outdated
|
||
private function getPage(int $default): int | ||
{ | ||
if (isset($this->values['_page'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
bf068fd
to
398fa03
Compare
extract code from Datagrid::buildPager() into separate methods to improve readability add upgrade info add example invert check to fail fast fix text in UPGRADE
c90dd44
398fa03
to
c90dd44
Compare
Thanks ! @peter-gribanov |
Subject
If the filter value is empty, but the filtering type has been changed from the default value, then this is an indication that the user wants to search by empty value.
At this level, we cannot determine whether a search can be performed on an empty value and therefore delegate it to filters.
Part of fix for #3569.
Changelog