From 72c8e48858c7c1d7e8abaded7d6ef93a995b03af Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 6 Mar 2024 22:42:51 -0500 Subject: [PATCH] feat: AutoFilter converts lists to `In` --- src/Collection/Grid/Filter/AutoFilter.php | 4 ++++ tests/Grid/Filter/AutoFilterTest.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Collection/Grid/Filter/AutoFilter.php b/src/Collection/Grid/Filter/AutoFilter.php index 9df6bfa..54990de 100644 --- a/src/Collection/Grid/Filter/AutoFilter.php +++ b/src/Collection/Grid/Filter/AutoFilter.php @@ -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; } diff --git a/tests/Grid/Filter/AutoFilterTest.php b/tests/Grid/Filter/AutoFilterTest.php index c0f73ab..5b9563a 100644 --- a/tests/Grid/Filter/AutoFilterTest.php +++ b/tests/Grid/Filter/AutoFilterTest.php @@ -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]; } }