Skip to content

Commit 29873a0

Browse files
authored
3.5.1 Release (rappasoft#2036)
## [v3.5.1] - 2024-11-09 ### Bug Fixes - Fix NumberFilter bug for string values by @lrljoe in rappasoft#2034 - Fixes for Filter Pills - Split blades, and ensure invalid filter alues are removed by @lrljoe in rappasoft#2035
1 parent 8c6d074 commit 29873a0

File tree

13 files changed

+165
-101
lines changed

13 files changed

+165
-101
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
All notable changes to `laravel-livewire-tables` will be documented in this file
44

5-
## [v3.5.0] - 2024-11-06
5+
## [v3.5.1] - 2024-11-09
6+
### Bug Fixes
7+
- Fix NumberFilter bug for string values by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2034
8+
- Fixes for Filter Pills - Split blades, and ensure invalid filter alues are removed by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2035
69

10+
## [v3.5.0] - 2024-11-06
711
### Bug Fixes
812
- Issue in multiple places where there is incorrect brackets in conjunction with coalescing operator (??) by @mrl22 in https://github.com/rappasoft/laravel-livewire-tables/pull/2021
913
- Add Value to BooleanColumn custom view by @lrjoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2010
@@ -22,8 +26,6 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
2226
- Fix missing i18n keys for FR, IT, EN, DE by @khwadj in https://github.com/rappasoft/laravel-livewire-tables/pull/1993
2327
- Add lang Norwegian and Albanian by @channor in https://github.com/rappasoft/laravel-livewire-tables/pull/1988
2428

25-
26-
2729
## [v3.4.22] - 2024-09-29
2830
### Bug Fixes
2931
- Fix Loading Placeholder Bug - Breaking Table by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1969

CONTRIBUTORS.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Localisation Contributors
66
| Language | Contributor(s) |
77
| --- | --- |
8+
| Albanian (SQ) | [channor] (https://github.com/channor) |
89
| Arabic (AR) | None |
910
| Catalan (CA) | None |
1011
| Brazilian (pt_BR) | [irineujunior](https://github.com/irineujunior)|
@@ -13,15 +14,17 @@
1314
| Dutch (NL) | [siebsie23](https://github.com/siebsie23), [spekkie2002](https://github.com/spekkie2002), [Jerimu](https://github.com/Jerimu) |
1415
| English (EN) | Core Team |
1516
| Finnish (FI) | [devmikromike](https://github.com/devmikromike) |
16-
| French (FR) | [dgillier](https://github.com/dgillier) |
17-
| German (DE) | None |
17+
| French (FR) | [dgillier](https://github.com/dgillier), [khwadj](https://github.com/khwadj)|
18+
| German (DE) | [khwadj](https://github.com/khwadj) |
1819
| Indonesian (ID) | None |
19-
| Italian (IT) | Core Team |
20+
| Italian (IT) | Core Team, [khwadj](https://github.com/khwadj) |
2021
| Malay (MS) | [wanadri](https://github.com/wanadri) |
22+
| Norwegian (NB) | [channor] (https://github.com/channor) |
2123
| Polish (PL) | [meavric](https://github.com/meavric) |
2224
| Portugese (PT) | None |
2325
| Russian (RU) | None |
2426
| Spanish (ES) | [CristhoferMF](https://github.com/CristhoferMF) |
27+
| Swedish (SV) | [Aiiion](https://github.com/Aiiion) |
2528
| Thai (TH) | None |
2629
| Turkish (TK) | None |
2730
| Ukrainian (UK) | [Oleksandr-Moik](https://github.com/Oleksandr-Moik) |

resources/views/components/tools/filter-pills.blade.php

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,84 +15,19 @@
1515

1616
@foreach($this->getAppliedFiltersWithValues() as $filterSelectName => $value)
1717
@php($filter = $this->getFilterByKey($filterSelectName))
18-
19-
@continue(is_null($filter))
20-
@continue($filter->isHiddenFromPills())
18+
@continue(is_null($filter) || $filter->isHiddenFromPills())
19+
@php( $filterPillTitle = $filter->getFilterPillTitle())
20+
@php( $filterPillValue = $filter->getFilterPillValue($value))
21+
@php( $separator = method_exists($filter, 'getPillsSeparator') ? $filter->getPillsSeparator() : ', ')
22+
@continue((is_array($filterPillValue) && empty($filterPillValue)))
2123

2224
@if ($filter->hasCustomPillBlade())
2325
@include($filter->getCustomPillBlade(), ['filter' => $filter])
2426
@else
25-
<span
26-
wire:key="{{ $tableName }}-filter-pill-{{ $filter->getKey() }}"
27-
@class([
28-
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 bg-indigo-100 text-indigo-800 capitalize dark:bg-indigo-200 dark:text-indigo-900' => $isTailwind,
29-
'badge badge-pill badge-info d-inline-flex align-items-center' => $isBootstrap4,
30-
'badge rounded-pill bg-info d-inline-flex align-items-center' => $isBootstrap5,
31-
])
32-
>
33-
{{ $filter->getFilterPillTitle() }}:
34-
@php( $filterPillValue = $filter->getFilterPillValue($value))
35-
@php( $separator = method_exists($filter, 'getPillsSeparator') ? $filter->getPillsSeparator() : ', ')
36-
37-
@if(is_array($filterPillValue) && !empty($filterPillValue))
38-
@foreach($filterPillValue as $filterPillArrayValue)
39-
{{ $filterPillArrayValue }}{!! $separator !!}
40-
@endforeach
41-
@else
42-
{{ $filterPillValue }}
43-
@endif
44-
45-
@if ($isTailwind)
46-
<button
47-
wire:click="resetFilter('{{ $filter->getKey() }}')"
48-
type="button"
49-
class="flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:outline-none focus:bg-indigo-500 focus:text-white"
50-
>
51-
<span class="sr-only">@lang('livewire-tables::Remove filter option')</span>
52-
<x-heroicon-m-x-mark class="h-full" />
53-
</button>
54-
@else
55-
<a
56-
href="#"
57-
wire:click="resetFilter('{{ $filter->getKey() }}')"
58-
@class([
59-
'text-white ml-2' => ($isBootstrap),
60-
])
61-
>
62-
<span @class([
63-
'sr-only' => $isBootstrap4,
64-
'visually-hidden' => $isBootstrap5,
65-
])>
66-
@lang('livewire-tables::Remove filter option')
67-
</span>
68-
<x-heroicon-m-x-mark class="laravel-livewire-tables-btn-tiny" />
69-
</a>
70-
@endif
71-
</span>
27+
<x-livewire-tables::tools.filter-pills.item :$filterPillTitle :$filterPillValue :$filterSelectName :$separator/>
7228
@endif
7329
@endforeach
74-
75-
@if ($isTailwind)
76-
<button
77-
wire:click.prevent="setFilterDefaults"
78-
class="focus:outline-none active:outline-none"
79-
>
80-
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900">
81-
@lang('livewire-tables::Clear')
82-
</span>
83-
</button>
84-
@else
85-
<a
86-
href="#"
87-
wire:click.prevent="setFilterDefaults"
88-
@class([
89-
'badge badge-pill badge-light' => $isBootstrap4,
90-
'badge rounded-pill bg-light text-dark text-decoration-none' => $isBootstrap5,
91-
])
92-
>
93-
@lang('livewire-tables::Clear')
94-
</a>
95-
@endif
30+
<x-livewire-tables::tools.filter-pills.buttons.reset-all />
9631
</div>
9732
</div>
9833
@endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@aware(['isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
2+
@if ($isTailwind)
3+
<button
4+
wire:click.prevent="setFilterDefaults"
5+
@class([
6+
"focus:outline-none active:outline-none"
7+
])>
8+
<span @class([
9+
"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",
10+
"bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900"
11+
])>
12+
@lang('livewire-tables::Clear')
13+
</span>
14+
</button>
15+
@else
16+
<a
17+
href="#"
18+
wire:click.prevent="setFilterDefaults"
19+
@class([
20+
'badge badge-pill badge-light' => $isBootstrap4,
21+
'badge rounded-pill bg-light text-dark text-decoration-none' => $isBootstrap5,
22+
])>
23+
@lang('livewire-tables::Clear')
24+
</a>
25+
@endif
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@aware(['tableName','isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
2+
@props(['filterKey'])
3+
@if ($isTailwind)
4+
<button
5+
wire:click="resetFilter('{{ $filterKey }}')"
6+
type="button"
7+
@class([
8+
"flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none",
9+
"text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white",
10+
])
11+
>
12+
<span class="sr-only">@lang('livewire-tables::Remove filter option')</span>
13+
<x-heroicon-m-x-mark class="h-full" />
14+
</button>
15+
@else
16+
<a
17+
href="#"
18+
wire:click="resetFilter('{{ $filterKey }}')"
19+
@class([
20+
'text-white ml-2' => ($isBootstrap),
21+
])
22+
>
23+
<span @class([
24+
'sr-only' => $isBootstrap4,
25+
'visually-hidden' => $isBootstrap5,
26+
])>
27+
@lang('livewire-tables::Remove filter option')
28+
</span>
29+
<x-heroicon-m-x-mark class="laravel-livewire-tables-btn-tiny" />
30+
</a>
31+
@endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@aware(['tableName','isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
2+
@props(['filterPillTitle', 'filterPillValue', 'filterSelectName', 'separator'])
3+
<span
4+
wire:key="{{ $tableName }}-filter-pill-{{ $filterSelectName }}"
5+
@class([
6+
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 bg-indigo-100 text-indigo-800 capitalize dark:bg-indigo-200 dark:text-indigo-900' => $isTailwind,
7+
'badge badge-pill badge-info d-inline-flex align-items-center' => $isBootstrap4,
8+
'badge rounded-pill bg-info d-inline-flex align-items-center' => $isBootstrap5,
9+
])
10+
>
11+
{{ $filterPillTitle }}:
12+
13+
@if(is_array($filterPillValue))
14+
@foreach($filterPillValue as $filterPillArrayValue)
15+
{{ $filterPillArrayValue }}{!! !$loop->last ? $separator : '' !!}
16+
@endforeach
17+
@else
18+
{{ $filterPillValue }}
19+
@endif
20+
21+
<x-livewire-tables::tools.filter-pills.buttons.reset-filter :filterKey="$filterSelectName" />
22+
23+
</span>

src/Traits/Helpers/FilterHelpers.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,24 @@ public function hasAppliedVisibleFiltersForPills(): bool
226226
/**
227227
* @return array<mixed>
228228
*/
229-
public function getAppliedFiltersWithValues(): array
229+
/*public function getAppliedFiltersWithValuesOld(): array
230230
{
231231
return $this->appliedFilters = array_filter($this->getAppliedFilters(), function ($item, $key) {
232232
return ! $this->getFilterByKey($key)->isEmpty($item) && (is_array($item) ? count($item) : $item !== null);
233233
}, ARRAY_FILTER_USE_BOTH);
234+
}*/
235+
236+
/**
237+
* @return array<mixed>
238+
*/
239+
public function getAppliedFiltersWithValues(): array
240+
{
241+
return $this->appliedFilters = array_filter($this->getAppliedFilters(), function ($item, $key) {
242+
$filter = $this->getFilterByKey($key);
243+
$item = (! is_null($item) && ! $filter->isEmpty($item)) ? $filter->validate($item) : $item;
244+
245+
return ! $filter->isEmpty($item) && (is_array($item) ? count($item) : $item !== null);
246+
}, ARRAY_FILTER_USE_BOTH);
234247
}
235248

236249
/**

src/Views/Filters/NumberFilter.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use Rappasoft\LaravelLivewireTables\Views\Filter;
66
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables;
7-
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{IsStringFilter};
7+
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{IsNumericFilter};
88

99
class NumberFilter extends Filter
1010
{
11-
use IsStringFilter;
11+
use IsNumericFilter;
1212
use HasWireables;
1313

1414
public string $wireMethod = 'blur';
@@ -17,12 +17,19 @@ class NumberFilter extends Filter
1717

1818
public function validate(float|int|string|array $value): float|int|string|false
1919
{
20+
$floatValue = (float) $value;
21+
$intValue = (int) $value;
22+
2023
if (is_array($value)) {
2124
return false;
2225
} elseif (is_float($value)) {
23-
return (float) $value;
26+
return $floatValue;
2427
} elseif (is_int($value)) {
25-
return (int) $value;
28+
return $intValue;
29+
} elseif (is_numeric($value)) {
30+
return (($floatValue - $intValue) == 0) ? $intValue : $floatValue;
31+
} elseif (ctype_digit($value)) {
32+
return $intValue;
2633
}
2734

2835
return false;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Views\Traits\Filters;
4+
5+
use Closure;
6+
use Illuminate\View\ComponentAttributeBag;
7+
use Rappasoft\LaravelLivewireTables\Views\{Column,Filter};
8+
9+
trait IsNumericFilter
10+
{
11+
public function isEmpty(float|int|string|array|null $value): bool
12+
{
13+
return ! is_null($value) ? ($this->validate($value) == false) : true;
14+
}
15+
16+
/**
17+
* Gets the Default Value for this Filter via the Component
18+
*/
19+
public function getFilterDefaultValue(): ?string
20+
{
21+
return $this->filterDefaultValue ?? null;
22+
}
23+
}

tests/Traits/Helpers/FilterHelpersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function test_can_set_filter_value(): void
104104

105105
$this->assertSame(['1'], $this->basicTable->getAppliedFilterWithValue('breed'));
106106

107-
$this->basicTable->setFilter('breed_id_filter', '2');
107+
$this->basicTable->setFilter('breed_id_filter', 2);
108108

109109
$this->assertSame('2', $this->basicTable->getAppliedFilterWithValue('breed_id_filter'));
110110

0 commit comments

Comments
 (0)