framework icon indicating copy to clipboard operation
framework copied to clipboard

Data grid/wrap complex filters

Open vvval opened this issue 3 years ago • 1 comments

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

vvval avatar Jan 15 '21 14:01 vvval

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.

codecov[bot] avatar Jan 15 '21 14:01 codecov[bot]