- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Added NumericRange filter which gives the possibility of filtering … #146
Added NumericRange filter which gives the possibility of filtering … #146
Conversation
Hi @christopherhero and thank you for your PR. But I feel this one is a bit too complex for the value it should bring. |
3b8e339
to
cf854c9
Compare
@Roshyo Hi thanks :) I have lightly changed |
@Roshyo what you think now :) ? |
LGTM. Let's wait for another approval before merging |
@christopherhero Could you try to rebase on 1.13? |
cf854c9
to
b1f4e43
Compare
b1f4e43
to
89c8804
Compare
@Roshyo updated |
8595a1b
to
6222fd8
Compare
+1 for adding numeric filter, current list looks lonely without it 😃 I've a naming concern, it feels more like How about to synchronize naming and capabilities with api-platform? |
eb5262c
to
4d7c3c8
Compare
@diimpp Thanks for review :) |
@diimpp What else to change :) ? |
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.
Hi @christopherhero, sorry for late reply. 🙏
Please see the comments.
Filter should allow to specify comparison strictness, like lt|gt|lte|gte
, e.g. greater than
and greater than or equel
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class RangeNumericFilterType extends AbstractType |
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.
Either
final class RangeNumericFilterType extends AbstractType | |
final class NumericRangeFilterType extends AbstractType |
or
final class RangeNumericFilterType extends AbstractType | |
final class RangeFilterType extends AbstractType |
@loic425 Hi, wdyt?
->add('greaterThan', NumberType::class, [ | ||
'label' => 'sylius.ui.greater_than', | ||
'required' => false, | ||
'scale' => $options['scale'], |
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.
Scale depends on rounding mode, so it should be possible to configure as well.
https://symfony.com/doc/current/reference/forms/types/number.html#rounding-mode
->add('lessThan', NumberType::class, [ | ||
'label' => 'sylius.ui.less_than', | ||
'required' => false, | ||
'scale' => $options['scale'], |
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
@@ -67,6 +67,16 @@ | |||
</service> | |||
<service id="sylius.form.type.grid_filter.exists" alias="Sylius\Bundle\GridBundle\Form\Type\Filter\ExistsFilterType" /> | |||
|
|||
<service id="Sylius\Component\Grid\Filter\RangeNumericFilter"> | |||
<tag name="sylius.grid_filter" type="numeric" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType" /> |
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.
<tag name="sylius.grid_filter" type="numeric" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType" /> | |
<tag name="sylius.grid_filter" type="numeric_range" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\NumericRangeFilterType" /> |
<tag name="sylius.grid_filter" type="numeric" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType" /> | |
<tag name="sylius.grid_filter" type="range" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeFilterType" /> |
|
||
public function getBlockPrefix(): string | ||
{ | ||
return 'sylius_grid_filter_range_numeric'; |
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.
return 'sylius_grid_filter_range_numeric'; | |
return 'sylius_grid_filter_numeric_range'; |
return 'sylius_grid_filter_range_numeric'; | |
return 'sylius_grid_filter_range'; |
<service id="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType"> | ||
<tag name="form.type" /> | ||
</service> | ||
<service id="sylius.form.type.grid_filter.numeric" alias="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType" /> |
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.
<service id="sylius.form.type.grid_filter.numeric" alias="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType" /> | |
<service id="sylius.form.type.grid_filter.numeric_range" alias="Sylius\Bundle\GridBundle\Form\Type\Filter\NumericRangeFilterType" /> |
<service id="sylius.form.type.grid_filter.numeric" alias="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeNumericFilterType" /> | |
<service id="sylius.form.type.grid_filter.range" alias="Sylius\Bundle\GridBundle\Form\Type\Filter\RangeFilterType" /> |
return; | ||
} | ||
|
||
$field = $options['field'] ?? $name; |
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 if I will write field: 1
, then it would be int and we need string. Date
filter do this conversion as well.
$field = $options['field'] ?? $name; | |
$field = (string) $options['field'] ?? $name; |
|
||
final class RangeNumericFilter implements FilterInterface | ||
{ | ||
public const DEFAULT_SCALE = 0; |
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 wonder which default scale would be sensible.
@Sylius/development-team wdyt?
SF numeric form type uses 3
.
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 think 0 is the most sensible. I don't think filtering with decimal precision is more common than with whole numbers.
/** | ||
* @param string[] $data | ||
*/ |
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.
Since phpstan now understands more complex docblocks, something like this should be done.
/** | |
* @param string[] $data | |
*/ | |
/** @param array<array-key, string> $data */ |
4d7c3c8
to
15e5aee
Compare
15e5aee
to
2303bb4
Compare
2303bb4
to
f7bf422
Compare
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.
Only 2 more observations I missed in the previous review, but it can be merged even without addressing those.
…n the range (gt|gte|lt|lte) from to on numeric type fields.
f7bf422
to
7d669a1
Compare
Thank you, @christopherhero! |
Thank you @christopherhero, for having patience and finishing the work even after so much time passed! 🥇 |
While working on adding a custom filter, I thought that it could be in the bundle.
I add
range numerical
filter which can filter on numerical fields in range (from-to) Like existing DateFilter.Also in this pull request is a small change in two classes:
Doctrine\ORM\ExpressionBuilder
Doctrine\ORM\DataSource
.I suggested adding filtering capability also when using HAVING instead of WHERE in the query. For example, when we use
count (*)
. In current architecture is hard to distinguish the type of condition (WHERE or HAVING). Another way than suggested by me is to add pubilic methods e.ghavingLessThan
toORM\ExpressionBuilder
and new interface "HavingExpressionBuilder"Please give your opinion what do you think about it?
This idea also came while working on this filter because I had to filter in queries with the
HAVING
clause.