Skip to content

Commit

Permalink
feat: AutoFilter converts lists to In
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Mar 7, 2024
1 parent a685c02 commit 72c8e48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Collection/Grid/Filter/AutoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function __construct(private string $field)

public function apply(mixed $value): ?object
{
if (\is_array($value) && \array_is_list($value)) {
return new In($this->field, $value);
}

if (!\is_string($value) || !$value) {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Grid/Filter/AutoFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public static function applyProvider(): iterable
yield ['[bar...baz)', new Between('foo', 'bar', 'baz', Between::EXCLUSIVE_END)];
yield ['~', new IsNull('foo')];
yield ['!~', new Not(new IsNull('foo'))];
yield [[1, 2], new In('foo', [1, 2])];
yield ['', null];
yield [null, null];
yield [['array'], null];
yield [['assoc' => 'array'], null];
}
}

0 comments on commit 72c8e48

Please sign in to comment.