Skip to content

Commit d90aecb

Browse files
authored
3.4.2 Release (rappasoft#1824)
## [v3.4.2] - 2024-08-04 ### New Features - Additional Events & Customisable Behaviour by @lrljoe in rappasoft#1820 ### Bug Fixes - Typehinting to allow events to be used to update Multi-Value Filters by @lrljoe in rappasoft#1822 ### Tweaks - Add missing ReturnTypes by @lrljoe in rappasoft#1823 - Removing old $listeners approach, now using the Livewire v3 On attribute by @lrljoe in rappasoft#1821 --------- Co-authored-by: lrljoe <[email protected]>
1 parent 8dc4bbd commit d90aecb

23 files changed

+629
-40
lines changed

CHANGELOG.md

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

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

5+
## [v3.4.2] - 2024-08-04
6+
### New Features
7+
- Additional Events & Customisable Behaviour by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1820
8+
9+
### Bug Fixes
10+
- Typehinting to allow events to be used to update Multi-Value Filters by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1822
11+
12+
### Tweaks
13+
- Add missing ReturnTypes by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1823
14+
- Removing old $listeners approach, now using the Livewire v3 On attribute by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1821
15+
516
## [v3.4.1] - 2024-08-04
617
### Bug Fixes
718
- Fix ViewComponentColumn issue with not accepting parameters cleanly by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1818

docs/datatable/events.md

Lines changed: 106 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,144 @@ title: Events
33
weight: 2
44
---
55

6-
These are the available events on the datatable component that you can fire from your application:
6+
### Listened For
7+
These are the available events on the datatable component that you can fire from your application, or client-side
78

8-
### refreshDatatable
9+
#### refreshDatatable
910

1011
```php
1112
$this->dispatch('refreshDatatable');
1213
```
1314

1415
Calls `$refresh` on the component. Good for updating from external sources or as an alternative to polling.
1516

16-
### setSort
17+
#### setSort
1718

1819
You can have the table sort a specific column:
1920

2021
```php
2122
$this->dispatch('setSort', 'name', 'asc');
2223
```
2324

24-
### clearSorts
25+
#### clearSorts
2526

2627
You can clear all the applied sorts:
2728

2829
```php
2930
$this->dispatch('clearSorts');
3031
```
3132

32-
### setFilter
33+
#### setFilter
3334

3435
You can have the table run a specific filter:
3536

3637
```php
3738
$this->dispatch('setFilter', 'status', '1');
3839
```
3940

40-
### clearFilters
41+
#### clearFilters
4142

4243
You can have the table clear all filters:
4344

4445
```php
4546
$this->dispatch('clearFilters');
4647
```
48+
49+
### Dispatched
50+
51+
There are several events, all in the Rappasoft\LaravelLivewireTables\Events namespace
52+
| Event Name | Event Purpose | Data Passed |
53+
| --- | --- | --- |
54+
| ColumnsSelected | Applied whenever a Column is selected/deselected from view | The Table Name ($tableName), Selected Columns ($value), Logged In User ($user) |
55+
| FilterApplied | Applied when a Filter is applied (not when removed) | The Table Name ($tableName), Filter Key ($key), Filter Value ($value), Logged In User ($user) |
56+
| SearchApplied | Applied when a Search is applied (not when removed) | The Table Name ($tableName), Search Term ($value), Logged In User ($user) |
57+
58+
By default, the Tables will dispatch an event when the Selected Columns is changed, you may customise this behaviour:
59+
60+
#### enableAllEvents
61+
62+
This enables all Dispatched Events. This should be used with caution, as more events will be introduced in the future.
63+
64+
```php
65+
public function configure(): void
66+
{
67+
$this->enableAllEvents();
68+
}
69+
```
70+
71+
#### disableAllEvents
72+
73+
This disables all Dispatched Events.
74+
75+
```php
76+
public function configure(): void
77+
{
78+
$this->disableAllEvents();
79+
}
80+
```
81+
82+
#### enableColumnSelectEvent
83+
84+
Enables the Column Select Event, has no impact on other events
85+
86+
```php
87+
public function configure(): void
88+
{
89+
$this->enableColumnSelectEvent();
90+
}
91+
```
92+
93+
#### disableColumnSelectEvent
94+
95+
Disables the Column Select Event, has no impact on other events
96+
97+
```php
98+
public function configure(): void
99+
{
100+
$this->disableColumnSelectEvent();
101+
}
102+
```
103+
104+
#### enableSearchAppliedEvent
105+
106+
Enables the Search Applied Event, has no impact on other events
107+
108+
```php
109+
public function configure(): void
110+
{
111+
$this->enableSearchAppliedEvent();
112+
}
113+
```
114+
115+
#### disableSearchAppliedEvent
116+
117+
Disables the Search Applied Event, has no impact on other events
118+
119+
```php
120+
public function configure(): void
121+
{
122+
$this->disableSearchAppliedEvent();
123+
}
124+
```
125+
126+
#### enableFilterAppliedEvent
127+
128+
Enables the Filter Applied Event, has no impact on other events
129+
130+
```php
131+
public function configure(): void
132+
{
133+
$this->enableFilterAppliedEvent();
134+
}
135+
```
136+
137+
#### disableFilterAppliedEvent
138+
139+
Disables the Filter Applied Event, has no impact on other events
140+
141+
```php
142+
public function configure(): void
143+
{
144+
$this->disableFilterAppliedEvent();
145+
}
146+
```

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ parameters:
66
- config
77
- database
88
- src
9-
level: 5
9+
level: 6
1010
tmpDir: build/phpstan
1111
checkOctaneCompatibility: true
1212
checkModelProperties: true

src/DataTableComponent.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@
22

33
namespace Rappasoft\LaravelLivewireTables;
44

5+
use Livewire\Attributes\On;
56
use Livewire\Component;
67
use Rappasoft\LaravelLivewireTables\Traits\HasAllTraits;
78

89
abstract class DataTableComponent extends Component
910
{
1011
use HasAllTraits;
1112

12-
/** @phpstan-ignore-next-line */
13-
protected $listeners = [
14-
'refreshDatatable' => '$refresh',
15-
'setSort' => 'setSortEvent',
16-
'clearSorts' => 'clearSortEvent',
17-
'setFilter' => 'setFilterEvent',
18-
'clearFilters' => 'clearFilterEvent',
19-
];
20-
2113
/**
2214
* Runs on every request, immediately after the component is instantiated, but before any other lifecycle methods are called
2315
*/
16+
#[On('refreshDatatable')]
2417
public function boot(): void
2518
{
2619
//

src/Events/ColumnsSelected.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
use Illuminate\Foundation\Events\Dispatchable;
66
use Illuminate\Queue\SerializesModels;
77

8-
class ColumnsSelected
8+
class ColumnsSelected extends LaravelLivewireTablesEvent
99
{
1010
use Dispatchable, SerializesModels;
1111

1212
public array $columns;
1313

14-
public string $key;
15-
16-
public function __construct(string $key, array $columns)
14+
public function __construct(string $tableName, string $key, array $columns = [])
1715
{
18-
$this->key = $key;
16+
$this->setTableForEvent($tableName)
17+
->setKeyForEvent($key)
18+
->setValueForEvent($columns)
19+
->setUserForEvent();
20+
1921
$this->columns = $columns;
2022
}
2123
}

src/Events/FilterApplied.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class FilterApplied extends LaravelLivewireTablesEvent
9+
{
10+
use Dispatchable, SerializesModels;
11+
12+
public function __construct(string $tableName, string $key, string|array|null $value = null)
13+
{
14+
$this->setTableForEvent($tableName)
15+
->setKeyForEvent($key)
16+
->setValueForEvent($value)
17+
->setUserForEvent();
18+
19+
}
20+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Events;
4+
5+
use Illuminate\Foundation\Auth\User;
6+
use Illuminate\Foundation\Events\Dispatchable;
7+
use Illuminate\Queue\SerializesModels;
8+
9+
class LaravelLivewireTablesEvent
10+
{
11+
use Dispatchable, SerializesModels;
12+
13+
public string $tableName;
14+
15+
public ?string $key;
16+
17+
public string|array|null $value;
18+
19+
public ?User $user;
20+
21+
public function setKeyForEvent(string $key): self
22+
{
23+
$this->key = $key;
24+
25+
return $this;
26+
}
27+
28+
public function setValueForEvent(string|array $value): self
29+
{
30+
$this->value = $value;
31+
32+
return $this;
33+
34+
}
35+
36+
public function setTableForEvent(string $tableName): self
37+
{
38+
$this->tableName = $tableName;
39+
40+
return $this;
41+
}
42+
43+
public function setUserForEvent(): self
44+
{
45+
if (auth()->user()) {
46+
$this->user = auth()->user();
47+
}
48+
49+
return $this;
50+
}
51+
}

src/Events/SearchApplied.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class SearchApplied extends LaravelLivewireTablesEvent
9+
{
10+
use Dispatchable, SerializesModels;
11+
12+
public function __construct(string $tableName, string $value)
13+
{
14+
$this->setTableForEvent($tableName)
15+
->setValueForEvent($value)
16+
->setUserForEvent();
17+
18+
}
19+
}

0 commit comments

Comments
 (0)