Skip to content

Commit 5cb0c87

Browse files
authored
Development to Master for v3.5.3 (#2068)
Co-authored-by: lrljoe <[email protected]> * Remove Waiting For Tests * Use CODECOV_TOKEN * Fix styling * Update phpdoc for boot (#2055) * Update phpdoc for boot * Fix styling --------- Co-authored-by: lrljoe <[email protected]> * Add test for No Columns defined - throws correct Exception (#2057) * Add test for No Columns * Fix styling --------- Co-authored-by: lrljoe <[email protected]> * Add Simple updatedSearch tests (#2058) * Add Simple updatedSearch tests * Fix styling --------- Co-authored-by: lrljoe <[email protected]> * Add test for FilterApplied Event being dispatched (#2059) * Add test for FilterApplied being dispatched * Fix styling --------- Co-authored-by: lrljoe <[email protected]> * Add updatedSelectedColumns test for Event (#2060) * Add test for ColumnsSelected Event dispatch * Apply Separate Tests --------- Co-authored-by: lrljoe <[email protected]> * Adjustment for DateRangeFilter (#2064) * Adjust SessionStorageHelpersTest (#2065) * FixSetDefaultPerPage (#2067) * FixSetDefaultPerPage * Update getDefaultPerPage to respect getPerPageAccepted * Fix missing ) * Fix styling * Add test fix * Add final tests --------- Co-authored-by: lrljoe <[email protected]> * Fix BooleanColumn unexpected truthy behaviour (#2066) * Fix BooleanColumn unexpected truthy behaviour * Support previous iteration * Update ChangeLog ---------
1 parent 393013b commit 5cb0c87

File tree

14 files changed

+346
-37
lines changed

14 files changed

+346
-37
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
## [v3.5.3] - 2024-11-18
6+
## Bug Fixes
7+
- FixSetDefaultPerPage by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2067
8+
- Fix BooleanColumn unexpected truthy behaviour by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2066
9+
- Adjustment for DateRangeFilter by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2064
10+
11+
## Testing
12+
- Adjust SessionStorageHelpersTest by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2065
13+
- Add updatedSelectedColumns test for Event by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2060
14+
- Add test for FilterApplied Event being dispatched by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2059
15+
- Add Simple updatedSearch tests by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2058
16+
- Add test for No Columns defined - throws correct Exception by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2057
17+
518
## [v3.5.2] - 2024-11-09
619
## Bug Fixes
720
- Migrate Localisation back to PHP Files from JSON by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2038

resources/js/laravel-livewire-tables.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ document.addEventListener('alpine:init', () => {
250250

251251
}
252252
}));
253-
254253

255254
Alpine.data('booleanFilter', (wire,filterKey,tableName,defaultValue) => ({
256255
switchOn: false,
@@ -270,6 +269,47 @@ document.addEventListener('alpine:init', () => {
270269
}
271270
}));
272271

272+
Alpine.data('newBooleanFilter', (filterKey,tableName,defaultValue) => ({
273+
switchOn: false,
274+
value: false,
275+
toggleStatus()
276+
{
277+
let tempValue = Boolean(Number(this.$wire.get('filterComponents.'+filterKey) ?? this.value));
278+
let newBoolean = !tempValue;
279+
this.switchOn = this.value = newBoolean;
280+
return Number(newBoolean);
281+
},
282+
toggleStatusWithUpdate()
283+
{
284+
let newValue = this.toggleStatus();
285+
this.$wire.set('filterComponents.'+filterKey, newValue);
286+
},
287+
toggleStatusWithReset()
288+
{
289+
let newValue = this.toggleStatus();
290+
this.$wire.call('resetFilter',filterKey);
291+
},
292+
setSwitchOn(val)
293+
{
294+
let number = Number(val ?? 0);
295+
this.switchOn = Boolean(number);
296+
},
297+
init() {
298+
this.$nextTick(() => {
299+
this.value = this.$wire.get('filterComponents.'+filterKey) ?? defaultValue;
300+
this.setSwitchOn(this.value ?? 0);
301+
});
302+
303+
this.listeners.push(
304+
Livewire.on('filter-was-set', (detail) => {
305+
if(detail.tableName == tableName && detail.filterKey == filterKey) {
306+
this.switchOn = detail.value ?? defaultValue;
307+
}
308+
})
309+
);
310+
}
311+
}));
312+
273313
Alpine.data('numberRangeFilter', (wire, filterKey, parentElementPath, filterConfig, childElementRoot) => ({
274314
allFilters: wire.entangle('filterComponents', false),
275315
originalMin: 0,
@@ -407,7 +447,6 @@ document.addEventListener('alpine:init', () => {
407447

408448
}));
409449

410-
411450
Alpine.data('tableWrapper', (wire, showBulkActionsAlpine) => ({
412451
shouldBeDisplayed: wire.entangle('shouldBeDisplayed'),
413452
listeners: [],

resources/js/laravel-livewire-tables.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/components/tools/filters/boolean.blade.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
@php($defaultValue = ($filter->hasFilterDefaultValue() ? (bool) $filter->getFilterDefaultValue() : false))
22
<div class="flex flex-cols"
3-
x-data="booleanFilter($wire,'{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')"
3+
x-data="newBooleanFilter('{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')"
44
>
55
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
6-
<input id="thisId" type="checkbox" name="switch" class="hidden" :checked="switchOn" >
6+
<input id="thisId" type="checkbox" name="switch" class="hidden" :checked="value" />
77

88
<button id="{{ $tableName }}-filter-{{ $filter->getKey() }}"
99
x-ref="switchButton"
1010
type="button"
11-
@click="switchOn = ! switchOn; value = (switchOn ? '1' : '0')"
12-
:class="switchOn ? 'bg-blue-600' : 'bg-neutral-200'"
11+
@click="toggleStatusWithUpdate"
12+
:class="(value == 1 || value == true) ? 'bg-blue-600' : 'bg-neutral-200'"
1313
class="relative inline-flex h-6 py-0.5 ml-4 focus:outline-none rounded-full w-10"
1414
x-cloak>
15-
<span :class="switchOn ? 'translate-x-[18px]' : 'translate-x-0.5'" class="w-5 h-5 duration-200 ease-in-out bg-white rounded-full shadow-md"></span>
15+
<span :class="(value == 1 || value == true) ? 'translate-x-[18px]' : 'translate-x-0.5'" class="w-5 h-5 duration-200 ease-in-out bg-white rounded-full shadow-md"></span>
1616
</button>
17-
<template x-if="value === '1' || value === '0'">
18-
<button
19-
x-on:click="switchOn = {{ $defaultValue }};"
20-
wire:click="resetFilter('{{ $filter->getKey() }}')"
21-
type="button"
17+
<template x-if="(value == 1 || value == true)">
18+
<button @click="toggleStatusWithReset" type="button"
2219
class="flex-shrink-0 ml-1 h-6 w-6 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"
2320
>
2421

src/Traits/Configuration/PaginationConfiguration.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ public function setPerPage(int $perPage): self
107107
return $this;
108108
}
109109

110+
public function unsetPerPage(): self
111+
{
112+
$this->perPage = null;
113+
114+
return $this;
115+
}
116+
110117
public function setPaginationMethod(string $paginationMethod): self
111118
{
112119
$this->paginationMethod = $paginationMethod;
@@ -138,12 +145,10 @@ public function setDisplayPaginationDetailsDisabled(): self
138145
/**
139146
* Set a default per-page value (if not set already by session or querystring)
140147
*/
141-
public function setDefaultPerPage(int $perPage): self
148+
public function setDefaultPerPage(int $defaultPerPage): self
142149
{
143-
$defaultPerPage = $perPage;
144-
145-
if ($this->perPage == 10) {
146-
$this->setPerPage($perPage);
150+
if (in_array((int) $defaultPerPage, $this->getPerPageAccepted())) {
151+
$this->defaultPerPage = $defaultPerPage;
147152
}
148153

149154
return $this;

src/Traits/Helpers/PaginationHelpers.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ public function getComputedPageName(): string
6969

7070
public function getPerPage(): int
7171
{
72-
return $this->perPage;
72+
return $this->perPage ?? $this->getDefaultPerPage();
73+
}
74+
75+
public function getDefaultPerPage(): int
76+
{
77+
return in_array((int) $this->defaultPerPage, $this->getPerPageAccepted()) ? $this->defaultPerPage : ($this->getPerPageAccepted()[0] ?? 10);
7378
}
7479

7580
/**
@@ -128,7 +133,7 @@ public function setupPagination(): void
128133
if (in_array(session($this->getPerPagePaginationSessionKey(), $this->getPerPage()), $this->getPerPageAccepted(), true)) {
129134
$this->setPerPage(session($this->getPerPagePaginationSessionKey(), $this->getPerPage()));
130135
} else {
131-
$this->setPerPage($this->getPerPageAccepted()[0] ?? 10);
136+
$this->setPerPage($this->getDefaultPerPage());
132137
}
133138
}
134139

src/Traits/WithPagination.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ trait WithPagination
1515

1616
public ?string $pageName = null;
1717

18-
public int $perPage = 10;
18+
public ?int $perPage;
19+
20+
#[Locked]
21+
public int $defaultPerPage = 10;
1922

2023
#[Locked]
2124
public array $perPageAccepted = [10, 25, 50];
@@ -57,9 +60,9 @@ trait WithPagination
5760

5861
public function mountWithPagination(): void
5962
{
60-
$sessionPerPage = session()->get($this->getPerPagePaginationSessionKey(), $this->getPerPageAccepted()[0] ?? 10);
63+
$sessionPerPage = session()->get($this->getPerPagePaginationSessionKey(), $this->getPerPage());
6164
if (! in_array((int) $sessionPerPage, $this->getPerPageAccepted(), false)) {
62-
$sessionPerPage = $this->getPerPageAccepted()[0] ?? 10;
65+
$sessionPerPage = $this->getDefaultPerPage();
6366
}
6467
$this->setPerPage($sessionPerPage);
6568
}
@@ -68,7 +71,7 @@ public function mountWithPagination(): void
6871
public function updatedPerPage(int|string $value): void
6972
{
7073
if (! in_array((int) $value, $this->getPerPageAccepted(), false)) {
71-
$value = $this->getPerPageAccepted()[0] ?? 10;
74+
$value = $this->getDefaultPerPage();
7275
}
7376

7477
if (in_array(session($this->getPerPagePaginationSessionKey(), (int) $value), $this->getPerPageAccepted(), true)) {

src/Views/Filters/DateRangeFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getKeys(): array
2828
return ['minDate' => '', 'maxDate' => ''];
2929
}
3030

31-
public function validate(array|string $values): array|bool
31+
public function validate(array|string|null $values): array|bool
3232
{
3333
$this->getOptions();
3434
$this->getConfigs();
@@ -197,7 +197,7 @@ public function getFilterPillValue($value): array|string|bool|null
197197
return '';
198198
}
199199

200-
public function isEmpty(array|string $value): bool
200+
public function isEmpty(array|string|null $value): bool
201201
{
202202
$values = [];
203203
if (is_array($value)) {

tests/Unit/Traits/Configuration/PaginationConfigurationTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,18 @@ public function test_can_set_per_page_manually(): void
113113

114114
public function test_can_set_default_per_page(): void
115115
{
116-
$this->assertSame(10, $this->unpaginatedTable->getPerPage());
117-
$this->unpaginatedTable->setDefaultPerPage(50);
118-
$this->assertSame(50, $this->unpaginatedTable->getPerPage());
119-
$this->unpaginatedTable->perPage = 25;
120-
$this->assertSame(25, $this->unpaginatedTable->getPerPage());
116+
$this->assertSame(10, $this->basicTable->getPerPage());
117+
$this->basicTable->unsetPerPage();
118+
$this->basicTable->setDefaultPerPage(50);
119+
$this->assertSame(50, $this->basicTable->getDefaultPerPage());
120+
$this->assertSame(50, $this->basicTable->getPerPage());
121+
$this->basicTable->perPage = 25;
122+
$this->assertSame(25, $this->basicTable->getPerPage());
123+
$this->basicTable->setPerPage(10);
124+
$this->assertSame(10, $this->basicTable->getPerPage());
125+
$this->assertSame(50, $this->basicTable->getDefaultPerPage());
126+
$this->basicTable->unsetPerPage();
127+
$this->assertSame(50, $this->basicTable->getPerPage());
128+
121129
}
122130
}

tests/Unit/Traits/Helpers/ColumnHelpersTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers;
44

5+
use Rappasoft\LaravelLivewireTables\Exceptions\NoColumnsException;
6+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
57
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
68
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
79
use Rappasoft\LaravelLivewireTables\Views\Column;
@@ -360,4 +362,27 @@ public function test_can_check_if_column_label_has_attributes(): void
360362
$this->assertSame(['class' => 'text-xl', 'default' => true, 'default-colors' => false, 'default-styling' => false], $column->getLabelAttributes());
361363

362364
}
365+
366+
public function test_throws_error_if_no_columns_are_defined(): void
367+
{
368+
$this->expectException(NoColumnsException::class);
369+
370+
$testTable = new class extends PetsTable
371+
{
372+
public function columns(): array
373+
{
374+
return [];
375+
}
376+
};
377+
378+
$testTable->configure();
379+
$testTable->boot();
380+
$testTable->bootedComponentUtilities();
381+
$testTable->bootedWithData();
382+
$testTable->bootedWithColumns();
383+
$testTable->bootedWithColumnSelect();
384+
$testTable->bootedWithSecondaryHeader();
385+
$testTable->booted();
386+
387+
}
363388
}

0 commit comments

Comments
 (0)