Skip to content

Commit eb22ddb

Browse files
committed
Filters type fix.
1 parent f8bc716 commit eb22ddb

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

src/Filters/Filter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public function __construct()
4747
}
4848

4949
if ($this instanceof SearchableFilter) {
50-
$this->type = SearchableFilter::TYPE;
50+
$this->type = $this->type ?? SearchableFilter::TYPE;
5151
}
5252

5353
if ($this instanceof SortableFilter) {
54-
$this->type = SortableFilter::TYPE;
54+
$this->type = $this->type ?? SortableFilter::TYPE;
5555
}
5656

5757
if ($this instanceof MatchFilter) {
58-
$this->type = MatchFilter::TYPE;
58+
$this->type = $this->type ?? MatchFilter::TYPE;
5959
}
6060

6161
$this->booted();

src/Traits/InteractWithSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static function collectFilters($type): Collection
109109
return $type instanceof Filter
110110
? tap($type, fn ($filter) => $filter->column = $filter->column ?? $column)
111111
: tap(new $base, function (Filter $filter) use ($column, $type) {
112-
$filter->type = $filter->type ?? $type;
112+
$filter->type = $type ? $type : 'value';
113113
$filter->column = $column;
114114
});
115115
})->values();

tests/Controllers/RepositoryFilterControllerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ public function test_available_filters_contains_matches_sortables_searches(): vo
2626
'title',
2727
];
2828

29+
$this->withoutExceptionHandling();
2930
$this->getJson('posts/filters?include=matches,sortables,searchables')
31+
->dump()
3032
// 5 custom filters
3133
// 1 match filter
3234
// 1 sort
3335
// 2 searchable
3436
->assertJson(
3537
fn (AssertableJson $json) => $json
3638
->where('data.0.rules.is_active', 'bool')
37-
->where('data.4.type', MatchFilter::TYPE)
39+
->where('data.4.type', 'text')
3840
->where('data.4.column', 'title')
39-
->where('data.5.type', SortableFilter::TYPE)
41+
->where('data.5.type', 'value')
4042
->where('data.5.column', 'title')
41-
->where('data.6.type', SearchableFilter::TYPE)
43+
->where('data.6.type', 'value')
4244
->where('data.6.column', 'id')
4345
->etc()
4446
)

tests/Feature/Filters/AdvancedFilterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public function test_the_boolean_filter_is_applied(): void
125125

126126
$this
127127
->getJson(PostRepository::uriKey().'/filters?include=matches')
128-
->dump()
129128
->assertOk()
130129
->assertJsonFragment($booleanFilter = [
131130
'key' => $key = 'active-booleans',

tests/Unit/AdvancedFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function test_advanced_filters_can_serialize(): void
1919

2020
public string $type = 'multiselect';
2121

22-
public string $title = 'Status filter';
22+
public ?string $title = 'Status filter';
2323

2424
public string $description = 'Short description';
2525

tests/Unit/MatchableFilterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public function test_matchable_filter_has_key(): void
1818
AssertableJson::fromArray($filter->jsonSerialize()),
1919
function (AssertableJson $json) {
2020
$json
21+
->dump()
2122
->where('key', 'matches')
2223
->where('title', 'Approved At')
2324
->where('column', 'approved_at')
25+
->etc()
2426
;
2527
}
2628
);

0 commit comments

Comments
 (0)