Skip to content

Commit 6b39a5f

Browse files
committed
fix nested filter pill values
1 parent a9471e2 commit 6b39a5f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Views/Filters/SelectFilter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public function validate($value)
4343

4444
public function getFilterPillValue($value): ?string
4545
{
46-
return $this->getCustomFilterPillValue($value) ?? $this->getOptions()[$value] ?? null;
46+
return $this->getCustomFilterPillValue($value)
47+
?? collect($this->getOptions())
48+
->mapWithKeys(fn ($options, $optgroupLabel) => is_iterable($options) ? $options : [$optgroupLabel => $options])[$value]
49+
?? null;
4750
}
4851

4952
public function isEmpty($value): bool

tests/Views/Traits/Helpers/FilterHelpersTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ public function can_get_filter_pill_value(): void
130130
$this->assertSame('baz', $filter->getFilterPillValue('foo'));
131131
}
132132

133+
/** @test */
134+
public function can_get_nested_filter_pill_value(): void
135+
{
136+
$filter = SelectFilter::make('Active')
137+
->options(['foo' => ['bar' => 'baz']]);
138+
139+
$this->assertSame('baz', $filter->getFilterPillValue('bar'));
140+
141+
$filter = SelectFilter::make('Active')
142+
->options(['foo' => ['bar' => 'baz']])
143+
->setFilterPillValues(['bar' => 'etc']);
144+
145+
$this->assertSame('etc', $filter->getFilterPillValue('bar'));
146+
}
147+
133148
/** @test */
134149
public function can_check_if_filter_has_configs(): void
135150
{

0 commit comments

Comments
 (0)