Skip to content
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

[API][Order] Filtering on the Orders list #15477

Closed

Conversation

LGouttefange
Copy link

Q A
Branch? 1.13
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets partially #11250
License MIT

Included in this PR:

Filtering on the Orders list
All the features from features/order/managing_orders/order_filtration
12 scenarios, 3 files

As this is my first PR here, I am open to any feedback 🙏

@LGouttefange LGouttefange requested a review from a team as a code owner October 27, 2023 12:51
@probot-autolabeler probot-autolabeler bot added the API APIs related issues and PRs. label Oct 27, 2023
@github-actions
Copy link

github-actions bot commented Oct 27, 2023

Bunnyshell Preview Environment deleted

Available commands:

  • /bns:deploy to redeploy the environment

public function __construct(private ContextAwareFilterInterface $dateFilter, private array $properties)
{
}

Copy link
Member

Choose a reason for hiding this comment

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

Please remove second empty line

final class InclusiveDateRangeFilter implements ContextAwareFilterInterface
{
/**
* @param ContextAwareFilterInterface $dateFilter
Copy link
Member

Choose a reason for hiding this comment

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

This @param is unnecessary, docblocs should only be added to cover arguable cases for static analysis.

}

/**
* @param QueryBuilder $queryBuilder
Copy link
Member

Choose a reason for hiding this comment

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

I guess only

* @param class-string $resourceClass
* @param array<string, mixed> $context

are needed, And

--- * @param string $resourceClass
+++ * @param class-string $resourceClass


private function isExclusive(mixed $value): bool
{
if(!$value || !is_string($value)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(!$value || !is_string($value)) {
if (!$value || !is_string($value)) {

@@ -24,6 +24,13 @@
<attribute name="path">/admin/orders</attribute>
<attribute name="filters">
<attribute>sylius.api.order_number_filter</attribute>
<attribute>sylius.api.order_checkout_completed_at_filter</attribute>
Copy link
Member

Choose a reason for hiding this comment

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

Please sort them logically or alphabetically.

For example.

                    <attribute>sylius.api.order_number_filter</attribute>
                    <attribute>sylius.api.order_checkout_completed_at_filter</attribute>
                    <attribute>sylius.api.order_currency_code_filter</attribute>
                    <attribute>sylius.api.order_total_filter</attribute>
                    <attribute>sylius.api.order_channel_filter</attribute>
                    <attribute>sylius.api.order_shipping_method_filter</attribute>
                    <attribute>sylius.api.order_products_filter</attribute>
                    <attribute>sylius.api.order_variants_filter</attribute>

/**
* @When I specify filter total being greater than :total
*/
public function iSpecifyFilterTotalBeingGreaterThan($total)
Copy link
Member

Choose a reason for hiding this comment

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

float/string $total?

Suggested change
public function iSpecifyFilterTotalBeingGreaterThan($total)
public function iSpecifyFilterTotalBeingGreaterThan($total): void

*/
public function iSpecifyFilterTotalBeingGreaterThan($total)
{
$this->client->addFilter('total[gt]', $total* 100);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->client->addFilter('total[gt]', $total* 100);
$this->client->addFilter('total[gt]', $total * 100);

*/
public function iSpecifyFilterTotalBeingLessThan($total)
{
$this->client->addFilter('total[lt]', $total* 100);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->client->addFilter('total[lt]', $total* 100);
$this->client->addFilter('total[lt]', $total * 100);

/**
* @When I specify filter total being less than :total
*/
public function iSpecifyFilterTotalBeingLessThan($total)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function iSpecifyFilterTotalBeingLessThan($total)
public function iSpecifyFilterTotalBeingLessThan(float/string? $total): void


/**
* @When /^I filter by (variants "([^"]+)" and "([^"]+)")$/
* @param ProductVariantInterface $variants
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this line unless necessary by phpstan

@diimpp
Copy link
Member

diimpp commented Oct 31, 2023

@LGouttefange Hi, great filtering coverage. 👍 I've commented on a few minor points, please take a look.

Copy link
Author

@LGouttefange LGouttefange left a comment

Choose a reason for hiding this comment

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

Thank you @diimpp for the thorough review. I've updated & commented some points
I also fixed the coding standards issues, but - bit of a newbie question - please let me know if I should resolve them myself, or let you handle those 🙏 thanks !

private function isExclusive(mixed $value): bool
{
if(!$value || !is_string($value)) {
return false;
Copy link
Author

Choose a reason for hiding this comment

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

I've pushed a new version of the Filter class, taking inspiration of the mentioned filter.
In the case of a Filter decorator, I didn't want to overstep or reproduce the base DateFilter validation & error handling, hence why I am not actively validating the item and just returning it as such.

@jakubtobiasz
Copy link
Contributor

Closing as already done in #15566. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants