Skip to content

Commit

Permalink
3.5.1 Release (#2036)
Browse files Browse the repository at this point in the history
## [v3.5.1] - 2024-11-09
### Bug Fixes
- Fix NumberFilter bug for string values by @lrljoe in #2034
- Fixes for Filter Pills - Split blades, and ensure invalid filter alues are removed by @lrljoe in #2035
  • Loading branch information
lrljoe authored Nov 10, 2024
1 parent 8c6d074 commit 29873a0
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 101 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

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

## [v3.5.0] - 2024-11-06
## [v3.5.1] - 2024-11-09
### Bug Fixes
- Fix NumberFilter bug for string values by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2034
- 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

## [v3.5.0] - 2024-11-06
### Bug Fixes
- 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
- Add Value to BooleanColumn custom view by @lrjoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2010
Expand All @@ -22,8 +26,6 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
- Fix missing i18n keys for FR, IT, EN, DE by @khwadj in https://github.com/rappasoft/laravel-livewire-tables/pull/1993
- Add lang Norwegian and Albanian by @channor in https://github.com/rappasoft/laravel-livewire-tables/pull/1988



## [v3.4.22] - 2024-09-29
### Bug Fixes
- Fix Loading Placeholder Bug - Breaking Table by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1969
Expand Down
9 changes: 6 additions & 3 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Localisation Contributors
| Language | Contributor(s) |
| --- | --- |
| Albanian (SQ) | [channor] (https://github.com/channor) |
| Arabic (AR) | None |
| Catalan (CA) | None |
| Brazilian (pt_BR) | [irineujunior](https://github.com/irineujunior)|
Expand All @@ -13,15 +14,17 @@
| Dutch (NL) | [siebsie23](https://github.com/siebsie23), [spekkie2002](https://github.com/spekkie2002), [Jerimu](https://github.com/Jerimu) |
| English (EN) | Core Team |
| Finnish (FI) | [devmikromike](https://github.com/devmikromike) |
| French (FR) | [dgillier](https://github.com/dgillier) |
| German (DE) | None |
| French (FR) | [dgillier](https://github.com/dgillier), [khwadj](https://github.com/khwadj)|
| German (DE) | [khwadj](https://github.com/khwadj) |
| Indonesian (ID) | None |
| Italian (IT) | Core Team |
| Italian (IT) | Core Team, [khwadj](https://github.com/khwadj) |
| Malay (MS) | [wanadri](https://github.com/wanadri) |
| Norwegian (NB) | [channor] (https://github.com/channor) |
| Polish (PL) | [meavric](https://github.com/meavric) |
| Portugese (PT) | None |
| Russian (RU) | None |
| Spanish (ES) | [CristhoferMF](https://github.com/CristhoferMF) |
| Swedish (SV) | [Aiiion](https://github.com/Aiiion) |
| Thai (TH) | None |
| Turkish (TK) | None |
| Ukrainian (UK) | [Oleksandr-Moik](https://github.com/Oleksandr-Moik) |
79 changes: 7 additions & 72 deletions resources/views/components/tools/filter-pills.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,19 @@

@foreach($this->getAppliedFiltersWithValues() as $filterSelectName => $value)
@php($filter = $this->getFilterByKey($filterSelectName))

@continue(is_null($filter))
@continue($filter->isHiddenFromPills())
@continue(is_null($filter) || $filter->isHiddenFromPills())
@php( $filterPillTitle = $filter->getFilterPillTitle())
@php( $filterPillValue = $filter->getFilterPillValue($value))
@php( $separator = method_exists($filter, 'getPillsSeparator') ? $filter->getPillsSeparator() : ', ')
@continue((is_array($filterPillValue) && empty($filterPillValue)))

@if ($filter->hasCustomPillBlade())
@include($filter->getCustomPillBlade(), ['filter' => $filter])
@else
<span
wire:key="{{ $tableName }}-filter-pill-{{ $filter->getKey() }}"
@class([
'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,
'badge badge-pill badge-info d-inline-flex align-items-center' => $isBootstrap4,
'badge rounded-pill bg-info d-inline-flex align-items-center' => $isBootstrap5,
])
>
{{ $filter->getFilterPillTitle() }}:
@php( $filterPillValue = $filter->getFilterPillValue($value))
@php( $separator = method_exists($filter, 'getPillsSeparator') ? $filter->getPillsSeparator() : ', ')

@if(is_array($filterPillValue) && !empty($filterPillValue))
@foreach($filterPillValue as $filterPillArrayValue)
{{ $filterPillArrayValue }}{!! $separator !!}
@endforeach
@else
{{ $filterPillValue }}
@endif

@if ($isTailwind)
<button
wire:click="resetFilter('{{ $filter->getKey() }}')"
type="button"
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"
>
<span class="sr-only">@lang('livewire-tables::Remove filter option')</span>
<x-heroicon-m-x-mark class="h-full" />
</button>
@else
<a
href="#"
wire:click="resetFilter('{{ $filter->getKey() }}')"
@class([
'text-white ml-2' => ($isBootstrap),
])
>
<span @class([
'sr-only' => $isBootstrap4,
'visually-hidden' => $isBootstrap5,
])>
@lang('livewire-tables::Remove filter option')
</span>
<x-heroicon-m-x-mark class="laravel-livewire-tables-btn-tiny" />
</a>
@endif
</span>
<x-livewire-tables::tools.filter-pills.item :$filterPillTitle :$filterPillValue :$filterSelectName :$separator/>
@endif
@endforeach

@if ($isTailwind)
<button
wire:click.prevent="setFilterDefaults"
class="focus:outline-none active:outline-none"
>
<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">
@lang('livewire-tables::Clear')
</span>
</button>
@else
<a
href="#"
wire:click.prevent="setFilterDefaults"
@class([
'badge badge-pill badge-light' => $isBootstrap4,
'badge rounded-pill bg-light text-dark text-decoration-none' => $isBootstrap5,
])
>
@lang('livewire-tables::Clear')
</a>
@endif
<x-livewire-tables::tools.filter-pills.buttons.reset-all />
</div>
</div>
@endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@aware(['isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
@if ($isTailwind)
<button
wire:click.prevent="setFilterDefaults"
@class([
"focus:outline-none active:outline-none"
])>
<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"
])>
@lang('livewire-tables::Clear')
</span>
</button>
@else
<a
href="#"
wire:click.prevent="setFilterDefaults"
@class([
'badge badge-pill badge-light' => $isBootstrap4,
'badge rounded-pill bg-light text-dark text-decoration-none' => $isBootstrap5,
])>
@lang('livewire-tables::Clear')
</a>
@endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@aware(['tableName','isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
@props(['filterKey'])
@if ($isTailwind)
<button
wire:click="resetFilter('{{ $filterKey }}')"
type="button"
@class([
"flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none",
"text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white",
])
>
<span class="sr-only">@lang('livewire-tables::Remove filter option')</span>
<x-heroicon-m-x-mark class="h-full" />
</button>
@else
<a
href="#"
wire:click="resetFilter('{{ $filterKey }}')"
@class([
'text-white ml-2' => ($isBootstrap),
])
>
<span @class([
'sr-only' => $isBootstrap4,
'visually-hidden' => $isBootstrap5,
])>
@lang('livewire-tables::Remove filter option')
</span>
<x-heroicon-m-x-mark class="laravel-livewire-tables-btn-tiny" />
</a>
@endif
23 changes: 23 additions & 0 deletions resources/views/components/tools/filter-pills/item.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@aware(['tableName','isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
@props(['filterPillTitle', 'filterPillValue', 'filterSelectName', 'separator'])
<span
wire:key="{{ $tableName }}-filter-pill-{{ $filterSelectName }}"
@class([
'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,
'badge badge-pill badge-info d-inline-flex align-items-center' => $isBootstrap4,
'badge rounded-pill bg-info d-inline-flex align-items-center' => $isBootstrap5,
])
>
{{ $filterPillTitle }}:

@if(is_array($filterPillValue))
@foreach($filterPillValue as $filterPillArrayValue)
{{ $filterPillArrayValue }}{!! !$loop->last ? $separator : '' !!}
@endforeach
@else
{{ $filterPillValue }}
@endif

<x-livewire-tables::tools.filter-pills.buttons.reset-filter :filterKey="$filterSelectName" />

</span>
15 changes: 14 additions & 1 deletion src/Traits/Helpers/FilterHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,24 @@ public function hasAppliedVisibleFiltersForPills(): bool
/**
* @return array<mixed>
*/
public function getAppliedFiltersWithValues(): array
/*public function getAppliedFiltersWithValuesOld(): array
{
return $this->appliedFilters = array_filter($this->getAppliedFilters(), function ($item, $key) {
return ! $this->getFilterByKey($key)->isEmpty($item) && (is_array($item) ? count($item) : $item !== null);
}, ARRAY_FILTER_USE_BOTH);
}*/

/**
* @return array<mixed>
*/
public function getAppliedFiltersWithValues(): array
{
return $this->appliedFilters = array_filter($this->getAppliedFilters(), function ($item, $key) {
$filter = $this->getFilterByKey($key);
$item = (! is_null($item) && ! $filter->isEmpty($item)) ? $filter->validate($item) : $item;

return ! $filter->isEmpty($item) && (is_array($item) ? count($item) : $item !== null);
}, ARRAY_FILTER_USE_BOTH);
}

/**
Expand Down
15 changes: 11 additions & 4 deletions src/Views/Filters/NumberFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Rappasoft\LaravelLivewireTables\Views\Filter;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables;
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{IsStringFilter};
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{IsNumericFilter};

class NumberFilter extends Filter
{
use IsStringFilter;
use IsNumericFilter;
use HasWireables;

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

public function validate(float|int|string|array $value): float|int|string|false
{
$floatValue = (float) $value;
$intValue = (int) $value;

if (is_array($value)) {
return false;
} elseif (is_float($value)) {
return (float) $value;
return $floatValue;
} elseif (is_int($value)) {
return (int) $value;
return $intValue;
} elseif (is_numeric($value)) {
return (($floatValue - $intValue) == 0) ? $intValue : $floatValue;
} elseif (ctype_digit($value)) {
return $intValue;
}

return false;
Expand Down
23 changes: 23 additions & 0 deletions src/Views/Traits/Filters/IsNumericFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Views\Traits\Filters;

use Closure;
use Illuminate\View\ComponentAttributeBag;
use Rappasoft\LaravelLivewireTables\Views\{Column,Filter};

trait IsNumericFilter
{
public function isEmpty(float|int|string|array|null $value): bool
{
return ! is_null($value) ? ($this->validate($value) == false) : true;
}

/**
* Gets the Default Value for this Filter via the Component
*/
public function getFilterDefaultValue(): ?string
{
return $this->filterDefaultValue ?? null;
}
}
2 changes: 1 addition & 1 deletion tests/Traits/Helpers/FilterHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function test_can_set_filter_value(): void

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

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

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

Expand Down
30 changes: 15 additions & 15 deletions tests/Traits/Helpers/SessionStorageHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,36 @@ public function test_can_store_for_fikers(): void
$this->assertSame(['breed' => ['1']], $this->basicTable->appliedFilters);
$this->assertSame(['breed' => ['1']], $this->basicTable->getStoredFilterValues());

$this->basicTable->setFilter('breed', ['22']);
$this->assertSame(['breed' => ['22']], $this->basicTable->appliedFilters);
$this->assertSame(['22'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['breed' => ['22']], $this->basicTable->getStoredFilterValues());
$this->basicTable->setFilter('breed', ['2']);
$this->assertSame(['breed' => ['2']], $this->basicTable->appliedFilters);
$this->assertSame(['2'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['breed' => ['2']], $this->basicTable->getStoredFilterValues());

$this->basicTable->restoreFilterValues();
$this->assertSame(['22'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['breed' => ['22']], $this->basicTable->getStoredFilterValues());
$this->assertSame(['2'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['breed' => ['2']], $this->basicTable->getStoredFilterValues());

$this->basicTable->clearStoredFilterValues();
$this->assertSame([], $this->basicTable->getStoredFilterValues());
$this->assertSame(['22'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['2'], $this->basicTable->getAppliedFilterWithValue('breed'));

$this->basicTable->setFilter('breed', ['33']);
$this->assertSame(['breed' => ['33']], $this->basicTable->getStoredFilterValues());
$this->assertSame(['33'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->basicTable->setFilter('breed', ['3']);
$this->assertSame(['breed' => ['3']], $this->basicTable->getStoredFilterValues());
$this->assertSame(['3'], $this->basicTable->getAppliedFilterWithValue('breed'));

$this->basicTable->appliedFilters = $this->basicTable->filterComponents = ['breed' => ['44']];
$this->basicTable->appliedFilters = $this->basicTable->filterComponents = ['breed' => ['4']];
$this->basicTable->storeFilterValues();
$this->assertSame(['44'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['4'], $this->basicTable->getAppliedFilterWithValue('breed'));

$this->basicTable->appliedFilters = $this->basicTable->filterComponents = [];
$this->assertNull($this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame([], $this->basicTable->appliedFilters);
$this->assertSame([], $this->basicTable->filterComponents);

$this->basicTable->restoreFilterValues();
$this->assertSame(['breed' => ['44']], $this->basicTable->appliedFilters);
$this->assertSame(['44'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['breed' => ['44']], $this->basicTable->getStoredFilterValues());
$this->assertSame(['breed' => ['4']], $this->basicTable->appliedFilters);
$this->assertSame(['4'], $this->basicTable->getAppliedFilterWithValue('breed'));
$this->assertSame(['breed' => ['4']], $this->basicTable->getStoredFilterValues());

}

Expand Down
1 change: 0 additions & 1 deletion tests/Traits/Visuals/FilterVisualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public function filters(): array
'Cat',
'<br />',
'Dog',
'<br />',
])
->set('filterComponents.breed', [1, 2])
->assertSeeHtmlInOrder([
Expand Down
Loading

0 comments on commit 29873a0

Please sign in to comment.