From 1e20fb0b411acbeb85ba082479a0c6928b7f4f55 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 16 Aug 2024 04:16:34 +0100 Subject: [PATCH 01/24] Update ChangeLog (#1852) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02091bd22..5957e1bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file ### Tweaks - Remove Component from Column, move getRows into ComputedProperty by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1838 - Clean up filter generic data by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1837 +- Further work to clean up Blades, and use Computed Properties by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1850 ## [v3.4.5] - 2024-08-10 ### Bug Fixes From 0c8ec457fd1261d830d48663e7e8848f8e4fefdf Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 16 Aug 2024 06:33:51 +0100 Subject: [PATCH 02/24] Add one-of-many-example --- docs/misc/one-of-many-example.md | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 docs/misc/one-of-many-example.md diff --git a/docs/misc/one-of-many-example.md b/docs/misc/one-of-many-example.md new file mode 100644 index 000000000..b90f558ad --- /dev/null +++ b/docs/misc/one-of-many-example.md @@ -0,0 +1,59 @@ +--- +title: One Of Many Example +weight: 8 +--- + +When trying to retrieve "OneOfMany", you may experience duplicate records. + +Core functionality for this will be added in due course, this is simply a work-around. + +In the meantime, to avoid this, you can use the following approach. + +This example assumes two Models: +User -> HasMany -> Things + +### Models +#### User +id +name +created_at +updated_at +etc + +```php + public function things(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Things::class); + } +``` + +#### Things +id +name +user_id +created_at +updated_at + +### Table +The following is the table code for this example, and retrieves the most recently created "Thing" + +#### Column +```php + Column::make('Latest Thing') + ->label( + fn ($row, Column $column) => $row->things->first()->name + ), +``` + +#### Builder +```php + public function builder(): Builder { + + return User::query()->with(['things' => function ($query) { + $query->select(['id','user_id','name'])->orderBy('created_at', 'desc')->limit(1); + }]); + + } +``` + +Core functionality for this will be added in due course, this is simply a work-around. \ No newline at end of file From 30d65ac20b5b6d035f13bf2785134da13e3de043 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 16 Aug 2024 07:59:25 +0100 Subject: [PATCH 03/24] Add explanation of setRefreshMethod (#1857) --- docs/misc/refreshing.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/misc/refreshing.md b/docs/misc/refreshing.md index e318bfdc7..5e07f69b6 100644 --- a/docs/misc/refreshing.md +++ b/docs/misc/refreshing.md @@ -42,11 +42,16 @@ public function configure(): void ## setRefreshMethod -Fire a specific action when polling. +Fire a specific action when polling. This is only necessary when you wish to call additional actions on each refresh. You must have a public function with the same name as the refresh method. ```php public function configure(): void { - $this->setRefreshMethod('refresh'); + $this->setRefreshMethod('refreshTable'); +} + +public function refreshTable() +{ + // Custom Code Here } ``` From 8f237b05b598e979b49be3f2ca8d7f43a50b37e4 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 16 Aug 2024 07:59:45 +0100 Subject: [PATCH 04/24] Add explanation of setRefreshMethod (#1857) (#1858) --- docs/misc/refreshing.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/misc/refreshing.md b/docs/misc/refreshing.md index e318bfdc7..5e07f69b6 100644 --- a/docs/misc/refreshing.md +++ b/docs/misc/refreshing.md @@ -42,11 +42,16 @@ public function configure(): void ## setRefreshMethod -Fire a specific action when polling. +Fire a specific action when polling. This is only necessary when you wish to call additional actions on each refresh. You must have a public function with the same name as the refresh method. ```php public function configure(): void { - $this->setRefreshMethod('refresh'); + $this->setRefreshMethod('refreshTable'); +} + +public function refreshTable() +{ + // Custom Code Here } ``` From b3137d95e5d5bb7c7f5c60e587567d6960d55d6e Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sat, 17 Aug 2024 23:23:27 +0100 Subject: [PATCH 05/24] Unlocking Entangled Items (#1859) * Unlock properties locked in error --------- Co-authored-by: lrljoe --- CHANGELOG.md | 4 ++++ src/Traits/WithBulkActions.php | 4 ++++ src/Traits/WithFilters.php | 4 +++- src/Traits/WithPagination.php | 3 +++ src/Traits/WithReordering.php | 5 +++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5957e1bac..55abcde31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## [v3.4.7] - 2024-08-18 +### Bug Fixes +- Correct a locked property that is entangled in js, and add comments around some key properties to prevent reoccurrence by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1859 + ## [v3.4.6] - 2024-08-15 ### New Features - Column Features - deselectedIf/selectedIf by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1846 diff --git a/src/Traits/WithBulkActions.php b/src/Traits/WithBulkActions.php index f7121cf2d..c36b87bb4 100644 --- a/src/Traits/WithBulkActions.php +++ b/src/Traits/WithBulkActions.php @@ -12,14 +12,17 @@ trait WithBulkActions public bool $bulkActionsStatus = true; + // Entangled in JS public bool $selectAll = false; public array $bulkActions = []; public array $bulkActionConfirms = []; + // Entangled in JS public array $selected = []; + // Entangled in JS public bool $hideBulkActionsWhenEmpty = false; public ?string $bulkActionConfirmDefaultMessage; @@ -46,6 +49,7 @@ trait WithBulkActions protected array $bulkActionsMenuItemAttributes = ['default-colors' => true, 'default-styling' => true]; + // Entangled in JS public bool $delaySelectAll = false; public function bulkActions(): array diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php index 1499fa1d0..d843f2a71 100644 --- a/src/Traits/WithFilters.php +++ b/src/Traits/WithFilters.php @@ -22,7 +22,7 @@ trait WithFilters #[Locked] public bool $filterPillsStatus = true; - #[Locked] + // Entangled in JS public bool $filterSlideDownDefaultVisible = false; #[Locked] @@ -31,8 +31,10 @@ trait WithFilters #[Locked] public int $filterCount; + // Set in JS public array $filterComponents = []; + // Set in Frontend public array $appliedFilters = []; public array $filterGenericData = []; diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index 28be97ee5..571c2b76c 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -32,10 +32,13 @@ trait WithPagination #[Locked] public bool $perPageVisibilityStatus = true; + // Entangled in JS public array $paginationCurrentItems = []; + // Entangled in JS public int $paginationCurrentCount = 0; + // Entangled in JS public ?int $paginationTotalItemCount = null; public array $numberOfPaginatorsRendered = []; diff --git a/src/Traits/WithReordering.php b/src/Traits/WithReordering.php index f9e833e4b..2251fe2c4 100644 --- a/src/Traits/WithReordering.php +++ b/src/Traits/WithReordering.php @@ -11,14 +11,19 @@ trait WithReordering use ReorderingConfiguration, ReorderingHelpers; + // Entangled in JS public bool $reorderStatus = false; + // Entangled in JS public bool $currentlyReorderingStatus = false; + // Entangled in JS public bool $hideReorderColumnUnlessReorderingStatus = false; + // Entangled in JS public bool $reorderDisplayColumn = false; + // Retrieved in JS public string $defaultReorderColumn = 'sort'; public array $orderedItems = []; From 9cb98cc760446521029263dc99d236d146e082ca Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sat, 17 Aug 2024 23:29:36 +0100 Subject: [PATCH 06/24] v3.4.7 (#1860) * Add explanation of setRefreshMethod (#1857) * Unlocking Entangled Items (#1859) * Unlock properties locked in error --------- Co-authored-by: lrljoe --------- Co-authored-by: lrljoe --- CHANGELOG.md | 4 ++++ src/Traits/WithBulkActions.php | 4 ++++ src/Traits/WithFilters.php | 4 +++- src/Traits/WithPagination.php | 3 +++ src/Traits/WithReordering.php | 5 +++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5957e1bac..55abcde31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## [v3.4.7] - 2024-08-18 +### Bug Fixes +- Correct a locked property that is entangled in js, and add comments around some key properties to prevent reoccurrence by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1859 + ## [v3.4.6] - 2024-08-15 ### New Features - Column Features - deselectedIf/selectedIf by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1846 diff --git a/src/Traits/WithBulkActions.php b/src/Traits/WithBulkActions.php index f7121cf2d..c36b87bb4 100644 --- a/src/Traits/WithBulkActions.php +++ b/src/Traits/WithBulkActions.php @@ -12,14 +12,17 @@ trait WithBulkActions public bool $bulkActionsStatus = true; + // Entangled in JS public bool $selectAll = false; public array $bulkActions = []; public array $bulkActionConfirms = []; + // Entangled in JS public array $selected = []; + // Entangled in JS public bool $hideBulkActionsWhenEmpty = false; public ?string $bulkActionConfirmDefaultMessage; @@ -46,6 +49,7 @@ trait WithBulkActions protected array $bulkActionsMenuItemAttributes = ['default-colors' => true, 'default-styling' => true]; + // Entangled in JS public bool $delaySelectAll = false; public function bulkActions(): array diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php index 1499fa1d0..d843f2a71 100644 --- a/src/Traits/WithFilters.php +++ b/src/Traits/WithFilters.php @@ -22,7 +22,7 @@ trait WithFilters #[Locked] public bool $filterPillsStatus = true; - #[Locked] + // Entangled in JS public bool $filterSlideDownDefaultVisible = false; #[Locked] @@ -31,8 +31,10 @@ trait WithFilters #[Locked] public int $filterCount; + // Set in JS public array $filterComponents = []; + // Set in Frontend public array $appliedFilters = []; public array $filterGenericData = []; diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index 28be97ee5..571c2b76c 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -32,10 +32,13 @@ trait WithPagination #[Locked] public bool $perPageVisibilityStatus = true; + // Entangled in JS public array $paginationCurrentItems = []; + // Entangled in JS public int $paginationCurrentCount = 0; + // Entangled in JS public ?int $paginationTotalItemCount = null; public array $numberOfPaginatorsRendered = []; diff --git a/src/Traits/WithReordering.php b/src/Traits/WithReordering.php index f9e833e4b..2251fe2c4 100644 --- a/src/Traits/WithReordering.php +++ b/src/Traits/WithReordering.php @@ -11,14 +11,19 @@ trait WithReordering use ReorderingConfiguration, ReorderingHelpers; + // Entangled in JS public bool $reorderStatus = false; + // Entangled in JS public bool $currentlyReorderingStatus = false; + // Entangled in JS public bool $hideReorderColumnUnlessReorderingStatus = false; + // Entangled in JS public bool $reorderDisplayColumn = false; + // Retrieved in JS public string $defaultReorderColumn = 'sort'; public array $orderedItems = []; From b6890e920324c7366533b346d14d3c3323bdfb26 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 18 Aug 2024 03:10:38 +0100 Subject: [PATCH 07/24] Add dispatch on updated filter components (#1861) * Add additional dispatch * Add FilterApplied Event * Add Filter Event Dispatch Tests --------- Co-authored-by: lrljoe --- CHANGELOG.md | 4 ++++ src/Traits/WithFilters.php | 5 +++++ tests/Traits/Visuals/FilterVisualsTest.php | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55abcde31..5843df9ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## UNRELEASED +### New Features +- Add an event dispatch for Filter Was Set when filterComponents is updated by @lrljoe + ## [v3.4.7] - 2024-08-18 ### Bug Fixes - Correct a locked property that is entangled in js, and add comments around some key properties to prevent reoccurrence by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1859 diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php index d843f2a71..49c91da8c 100644 --- a/src/Traits/WithFilters.php +++ b/src/Traits/WithFilters.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use Livewire\Attributes\Locked; +use Rappasoft\LaravelLivewireTables\Events\FilterApplied; use Rappasoft\LaravelLivewireTables\Traits\Configuration\FilterConfiguration; use Rappasoft\LaravelLivewireTables\Traits\Helpers\FilterHelpers; @@ -103,6 +104,10 @@ public function updatedFilterComponents(string|array|null $value, string $filter } elseif ($filter) { $this->callHook('filterUpdated', ['filter' => $filter->getKey(), 'value' => $value]); $this->callTraitHook('filterUpdated', ['filter' => $filter->getKey(), 'value' => $value]); + if ($this->getEventStatusFilterApplied() && $filter->getKey() != null && $value != null) { + event(new FilterApplied($this->getTableName(), $filter->getKey(), $value)); + } + $this->dispatch('filter-was-set', tableName: $this->getTableName(), filterKey: $filter->getKey(), value: $value); } } diff --git a/tests/Traits/Visuals/FilterVisualsTest.php b/tests/Traits/Visuals/FilterVisualsTest.php index 221ee7836..5b34da945 100644 --- a/tests/Traits/Visuals/FilterVisualsTest.php +++ b/tests/Traits/Visuals/FilterVisualsTest.php @@ -49,6 +49,20 @@ public function test_filter_pills_show_when_enabled(): void ->assertSee('Applied Filters'); } + public function test_event_dispatched_when_filterComponents_set(): void + { + Livewire::test(PetsTable::class) + ->set('filterComponents.breed', [1]) + ->assertDispatched('filter-was-set'); + } + + public function test_event_dispatched_when_setFilter_dispatched(): void + { + Livewire::test(PetsTable::class) + ->dispatch('setFilter', filterKey: 'breed', value: [1]) + ->assertDispatched('filter-was-set'); + } + public function test_filter_pills_show_when_visible(): void { Livewire::test(PetsTable::class) From fb646a54fe929aa76ff44caa76b7470923ded6aa Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 18 Aug 2024 03:12:50 +0100 Subject: [PATCH 08/24] v3.4.8 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5843df9ce..7f47783c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ All notable changes to `laravel-livewire-tables` will be documented in this file -## UNRELEASED +## [v3.4.8] - 2024-08-18 ### New Features -- Add an event dispatch for Filter Was Set when filterComponents is updated by @lrljoe +- Add an event dispatch for Filter Was Set when filterComponents is updated by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1861 ## [v3.4.7] - 2024-08-18 ### Bug Fixes From 6fe1c57a89ca249d21f179cff54867b8c62b215b Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 18 Aug 2024 03:23:16 +0100 Subject: [PATCH 09/24] v3.4.8 (#1863) ## [v3.4.8] - 2024-08-18 ### New Features - Add an event dispatch for Filter Was Set when filterComponents is updated by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1861 --- CHANGELOG.md | 4 ++++ src/Traits/WithFilters.php | 5 +++++ tests/Traits/Visuals/FilterVisualsTest.php | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55abcde31..7f47783c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## [v3.4.8] - 2024-08-18 +### New Features +- Add an event dispatch for Filter Was Set when filterComponents is updated by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1861 + ## [v3.4.7] - 2024-08-18 ### Bug Fixes - Correct a locked property that is entangled in js, and add comments around some key properties to prevent reoccurrence by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1859 diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php index d843f2a71..49c91da8c 100644 --- a/src/Traits/WithFilters.php +++ b/src/Traits/WithFilters.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use Livewire\Attributes\Locked; +use Rappasoft\LaravelLivewireTables\Events\FilterApplied; use Rappasoft\LaravelLivewireTables\Traits\Configuration\FilterConfiguration; use Rappasoft\LaravelLivewireTables\Traits\Helpers\FilterHelpers; @@ -103,6 +104,10 @@ public function updatedFilterComponents(string|array|null $value, string $filter } elseif ($filter) { $this->callHook('filterUpdated', ['filter' => $filter->getKey(), 'value' => $value]); $this->callTraitHook('filterUpdated', ['filter' => $filter->getKey(), 'value' => $value]); + if ($this->getEventStatusFilterApplied() && $filter->getKey() != null && $value != null) { + event(new FilterApplied($this->getTableName(), $filter->getKey(), $value)); + } + $this->dispatch('filter-was-set', tableName: $this->getTableName(), filterKey: $filter->getKey(), value: $value); } } diff --git a/tests/Traits/Visuals/FilterVisualsTest.php b/tests/Traits/Visuals/FilterVisualsTest.php index 221ee7836..5b34da945 100644 --- a/tests/Traits/Visuals/FilterVisualsTest.php +++ b/tests/Traits/Visuals/FilterVisualsTest.php @@ -49,6 +49,20 @@ public function test_filter_pills_show_when_enabled(): void ->assertSee('Applied Filters'); } + public function test_event_dispatched_when_filterComponents_set(): void + { + Livewire::test(PetsTable::class) + ->set('filterComponents.breed', [1]) + ->assertDispatched('filter-was-set'); + } + + public function test_event_dispatched_when_setFilter_dispatched(): void + { + Livewire::test(PetsTable::class) + ->dispatch('setFilter', filterKey: 'breed', value: [1]) + ->assertDispatched('filter-was-set'); + } + public function test_filter_pills_show_when_visible(): void { Livewire::test(PetsTable::class) From 8eafffe945c0af2a2f2333e162d3bb4f253a48c6 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:38:15 +0100 Subject: [PATCH 10/24] Fix superfluous bulk actions tr < (#1868) --- resources/views/components/table/tr/bulk-actions.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/table/tr/bulk-actions.blade.php b/resources/views/components/table/tr/bulk-actions.blade.php index 7c7815b91..73201debf 100644 --- a/resources/views/components/table/tr/bulk-actions.blade.php +++ b/resources/views/components/table/tr/bulk-actions.blade.php @@ -97,7 +97,7 @@ class="btn btn-primary btn-sm" - <