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

Data grid/wrap complex filters #383

Closed
wants to merge 4 commits into from
Closed

Conversation

vvval
Copy link
Member

@vvval vvval commented Jan 15, 2021

Allows wrapping standalone filters into a complex construction under the hood:
?filters[size]=xl&filters[color]=red
to mean

new Filter\Any(
    new Filter\Equals('size', 'xl'),
    new Filter\Equals('color', 'red')
)

A user should add a custom wrapper explicitly with the exact logic of wrapping:

$input = new ArrayInput([GridFactory::KEY_FILTER => ['size' => 'xl', 'color' => 'red', 'price' => 1]]);

$schema->addFilterWrapper(
    function (array $filters): array {
        $size = $filters['size'] ?? null;
        $color = $filters['color'] ?? null;
        if ($size && $color) {
            unset($filters['size'], $filters['color']);
            $filters[] = new Any($size, $color);
        }
        return $filters;
    }
);

This means that only if both size and color filters presented, group them with any and delete from the original list of filters

vintsukevich and others added 2 commits January 15, 2021 17:37
@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #383 (ebf8c13) into master (8c1e013) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #383      +/-   ##
============================================
+ Coverage     86.75%   86.78%   +0.03%     
- Complexity     7955     7964       +9     
============================================
  Files          1101     1102       +1     
  Lines         27330    27385      +55     
============================================
+ Hits          23709    23767      +58     
+ Misses         3621     3618       -3     
Impacted Files Coverage Δ Complexity Δ
src/DataGrid/src/GridFactory.php 98.78% <100.00%> (+0.04%) 29.00 <0.00> (+1.00)
src/DataGrid/src/GridSchema.php 100.00% <100.00%> (ø) 18.00 <3.00> (+3.00)
src/DataGrid/tests/Fixture/WrapWriter.php 100.00% <100.00%> (ø) 2.00 <2.00> (?)
src/DataGrid/tests/GridFactoryTest.php 59.60% <100.00%> (+15.05%) 22.00 <3.00> (+3.00)
src/Tokenizer/src/AbstractLocator.php 97.36% <0.00%> (-2.64%) 12.00% <0.00%> (ø%)
...rc/DataGrid/src/Specification/Value/FloatValue.php 100.00% <0.00%> (+100.00%) 4.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c1e013...ebf8c13. Read the comment docs.

@vvval vvval marked this pull request as draft January 15, 2021 14:44
…into data-grid/wrap-complex-filters

# Conflicts:
#	src/DataGrid/src/Specification/Filter/NullFilter.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants