From 272457d745b38c1aa9eed27a38884352b6220d2e Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:11:27 +0100 Subject: [PATCH 01/11] Adjust for HTML Columns --- resources/views/datatable.blade.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/views/datatable.blade.php b/resources/views/datatable.blade.php index 73d8cf071..5c9625bb0 100644 --- a/resources/views/datatable.blade.php +++ b/resources/views/datatable.blade.php @@ -53,7 +53,11 @@ @continue($column->isReorderColumn() && !$this->getCurrentlyReorderingStatus() && $this->getHideReorderColumnUnlessReorderingStatus()) - {{ $column->renderContents($row) }} + @if($column->isHtml()) + {!! $column->renderContents($row) !!} + @else + {{ $column->renderContents($row) }} + @endif @endforeach From 8b3e3cff74c8f033b2b47037b9ea3c542d779437 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:13:28 +0100 Subject: [PATCH 02/11] Update ChangeLog and SP --- CHANGELOG.md | 4 ++++ src/LaravelLivewireTablesServiceProvider.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 499b54b76..7060f51c2 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.2.7] - 2024-06-05 +### Bug Fixes +- Ensure HTML Columns return HTML correctly by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1737 + ## [v3.2.6] - 2024-06-05 ### New Features - Add configurable wire:model for filters by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1699 diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index 0cdd740db..f0a50ed70 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -14,7 +14,7 @@ class LaravelLivewireTablesServiceProvider extends ServiceProvider public function boot(): void { - AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.6']); + AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.7']); $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' From 2cd6684769082a51f031e1db43c6092e00669543 Mon Sep 17 00:00:00 2001 From: Matt Pickering Date: Sat, 29 Jun 2024 20:52:25 +0100 Subject: [PATCH 03/11] =?UTF-8?q?fix:=20Apply=20cursor=20pointer=20only=20?= =?UTF-8?q?on=20clickable=20columns=20when=20using=20Bootst=E2=80=A6=20(#1?= =?UTF-8?q?742)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ensure HTML Columns Return HTML Correctly (#1737) * Adjust for HTML Columns * fix: Apply cursor pointer only on clickable columns when using Bootstrap --------- Co-authored-by: Joe <104938042+lrljoe@users.noreply.github.com> --- resources/views/components/table/td.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/table/td.blade.php b/resources/views/components/table/td.blade.php index 1ae7e41d6..0d6973242 100644 --- a/resources/views/components/table/td.blade.php +++ b/resources/views/components/table/td.blade.php @@ -21,7 +21,7 @@ ->class(['d-none' => $component->isBootstrap() && $column && $column->shouldCollapseAlways()]) ->class(['d-none d-md-table-cell' => $component->isBootstrap() && $column && $column->shouldCollapseOnMobile()]) ->class(['d-none d-lg-table-cell' => $component->isBootstrap() && $column && $column->shouldCollapseOnTablet()]) - ->style(['cursor:pointer' => $component->isBootstrap()]) + ->style(['cursor:pointer' => $component->isBootstrap() && $column && $column->isClickable()]) ->except('default') }} > From f5dba56bcf5c4f98e5141c0660489e7533c77009 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sat, 29 Jun 2024 19:52:51 +0000 Subject: [PATCH 04/11] Fix styling --- src/DataTableComponent.php | 4 +--- src/Exceptions/DataTableConfigurationException.php | 4 +--- src/Exceptions/NoColumnsException.php | 4 +--- src/Exceptions/NoSearchableColumnsException.php | 4 +--- src/Exceptions/NoSortableColumnsException.php | 4 +--- src/Traits/WithReordering.php | 5 +---- .../Traits/Configuration/ImageColumnConfiguration.php | 4 +--- .../Traits/Configuration/LinkColumnConfiguration.php | 4 +--- src/Views/Traits/Helpers/ImageColumnHelpers.php | 4 +--- src/Views/Traits/Helpers/LinkColumnHelpers.php | 4 +--- tests/DataTableComponentTest.php | 8 ++------ tests/Http/Livewire/FailingTables/NoPrimaryKeyTable.php | 4 +--- 12 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/DataTableComponent.php b/src/DataTableComponent.php index b89da3dee..906878d7d 100644 --- a/src/DataTableComponent.php +++ b/src/DataTableComponent.php @@ -29,9 +29,7 @@ public function boot(): void /** * Runs on every request, after the component is mounted or hydrated, but before any update methods are called */ - public function booted(): void - { - } + public function booted(): void {} public function render(): \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View { diff --git a/src/Exceptions/DataTableConfigurationException.php b/src/Exceptions/DataTableConfigurationException.php index 1dabdf83a..795d82b06 100644 --- a/src/Exceptions/DataTableConfigurationException.php +++ b/src/Exceptions/DataTableConfigurationException.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Exceptions; -class DataTableConfigurationException extends \Exception -{ -} +class DataTableConfigurationException extends \Exception {} diff --git a/src/Exceptions/NoColumnsException.php b/src/Exceptions/NoColumnsException.php index 5d11959c3..875a457cb 100644 --- a/src/Exceptions/NoColumnsException.php +++ b/src/Exceptions/NoColumnsException.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Exceptions; -class NoColumnsException extends \Exception -{ -} +class NoColumnsException extends \Exception {} diff --git a/src/Exceptions/NoSearchableColumnsException.php b/src/Exceptions/NoSearchableColumnsException.php index de6b56713..5597b1235 100644 --- a/src/Exceptions/NoSearchableColumnsException.php +++ b/src/Exceptions/NoSearchableColumnsException.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Exceptions; -class NoSearchableColumnsException extends \Exception -{ -} +class NoSearchableColumnsException extends \Exception {} diff --git a/src/Exceptions/NoSortableColumnsException.php b/src/Exceptions/NoSortableColumnsException.php index 825c54339..7ba3828f9 100644 --- a/src/Exceptions/NoSortableColumnsException.php +++ b/src/Exceptions/NoSortableColumnsException.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Exceptions; -class NoSortableColumnsException extends \Exception -{ -} +class NoSortableColumnsException extends \Exception {} diff --git a/src/Traits/WithReordering.php b/src/Traits/WithReordering.php index 33679a1aa..553c7c42e 100644 --- a/src/Traits/WithReordering.php +++ b/src/Traits/WithReordering.php @@ -40,10 +40,7 @@ public function setupReordering(): void $this->restartReorderingIfNecessary(); } - public function enablePaginatedReordering(): void - { - - } + public function enablePaginatedReordering(): void {} public function enableReordering(): void { diff --git a/src/Views/Traits/Configuration/ImageColumnConfiguration.php b/src/Views/Traits/Configuration/ImageColumnConfiguration.php index e1283c2dc..8ab662b87 100644 --- a/src/Views/Traits/Configuration/ImageColumnConfiguration.php +++ b/src/Views/Traits/Configuration/ImageColumnConfiguration.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Views\Traits\Configuration; -trait ImageColumnConfiguration -{ -} +trait ImageColumnConfiguration {} diff --git a/src/Views/Traits/Configuration/LinkColumnConfiguration.php b/src/Views/Traits/Configuration/LinkColumnConfiguration.php index dedcd6430..9d07ca9ad 100644 --- a/src/Views/Traits/Configuration/LinkColumnConfiguration.php +++ b/src/Views/Traits/Configuration/LinkColumnConfiguration.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Views\Traits\Configuration; -trait LinkColumnConfiguration -{ -} +trait LinkColumnConfiguration {} diff --git a/src/Views/Traits/Helpers/ImageColumnHelpers.php b/src/Views/Traits/Helpers/ImageColumnHelpers.php index 98de49507..2226586a1 100644 --- a/src/Views/Traits/Helpers/ImageColumnHelpers.php +++ b/src/Views/Traits/Helpers/ImageColumnHelpers.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Views\Traits\Helpers; -trait ImageColumnHelpers -{ -} +trait ImageColumnHelpers {} diff --git a/src/Views/Traits/Helpers/LinkColumnHelpers.php b/src/Views/Traits/Helpers/LinkColumnHelpers.php index ef8026bc0..4555786d2 100644 --- a/src/Views/Traits/Helpers/LinkColumnHelpers.php +++ b/src/Views/Traits/Helpers/LinkColumnHelpers.php @@ -2,6 +2,4 @@ namespace Rappasoft\LaravelLivewireTables\Views\Traits\Helpers; -trait LinkColumnHelpers -{ -} +trait LinkColumnHelpers {} diff --git a/tests/DataTableComponentTest.php b/tests/DataTableComponentTest.php index c62fa4e09..5cd0115ff 100644 --- a/tests/DataTableComponentTest.php +++ b/tests/DataTableComponentTest.php @@ -55,9 +55,7 @@ public function test_default_fingerprint_will_always_be_the_same_for_same_datata public function test_default_datatable_fingerprints_will_be_different_for_each_table(): void { - $mockTable = new class() extends PetsTable - { - }; + $mockTable = new class() extends PetsTable {}; $this->assertNotSame($this->basicTable->getDataTableFingerprint(), $mockTable->getDataTableFingerprint()); } @@ -66,9 +64,7 @@ public function test_default_fingerprint_will_be_url_friendy(): void { $mocks = []; for ($i = 0; $i < 9; $i++) { - $mocks[$i] = new class() extends PetsTable - { - }; + $mocks[$i] = new class() extends PetsTable {}; $this->assertFalse(filter_var('http://'.$mocks[$i]->getDataTableFingerprint().'.dev', FILTER_VALIDATE_URL) === false); } // control diff --git a/tests/Http/Livewire/FailingTables/NoPrimaryKeyTable.php b/tests/Http/Livewire/FailingTables/NoPrimaryKeyTable.php index d71f7f3ec..be6f0100c 100644 --- a/tests/Http/Livewire/FailingTables/NoPrimaryKeyTable.php +++ b/tests/Http/Livewire/FailingTables/NoPrimaryKeyTable.php @@ -22,9 +22,7 @@ class NoPrimaryKeyTable extends DataTableComponent { public $model = Pet::class; - public function configure(): void - { - } + public function configure(): void {} public function columns(): array { From 52ad60b62b4f7cc2b73e77d5a8217ed32799dea1 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:59:42 +0100 Subject: [PATCH 05/11] Fix hide bulk actions when empty not reflecting in frontend (#1747) * Fix issue with Hide Bulk Actions When Empty not reflecting in frontend * Fix styling * Add development branch into tests --------- Co-authored-by: lrljoe --- .github/workflows/run-tests-pcov-pull.yml | 1 + .github/workflows/run-tests-pull.yml | 1 + resources/js/laravel-livewire-tables.js | 2 +- resources/js/laravel-livewire-tables.min.js | 2 +- .../views/components/tools/toolbar/items/bulk-actions.blade.php | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests-pcov-pull.yml b/.github/workflows/run-tests-pcov-pull.yml index 08e7eea08..0a5f52d3e 100644 --- a/.github/workflows/run-tests-pcov-pull.yml +++ b/.github/workflows/run-tests-pcov-pull.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - 'develop' + - 'development' - 'master' jobs: diff --git a/.github/workflows/run-tests-pull.yml b/.github/workflows/run-tests-pull.yml index 50c0c38be..1abeaeee8 100644 --- a/.github/workflows/run-tests-pull.yml +++ b/.github/workflows/run-tests-pull.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - 'develop' + - 'development' - 'master' jobs: diff --git a/resources/js/laravel-livewire-tables.js b/resources/js/laravel-livewire-tables.js index 532a615ea..0d068dac1 100644 --- a/resources/js/laravel-livewire-tables.js +++ b/resources/js/laravel-livewire-tables.js @@ -8,7 +8,7 @@ document.addEventListener('alpine:init', () => { paginationTotalItemCount: wire.entangle('paginationTotalItemCount'), paginationCurrentItems: wire.entangle('paginationCurrentItems'), selectedItems: wire.entangle('selected'), - alwaysShowBulkActions: !wire.entangle('hideBulkActionsWhenEmpty'), + hideBulkActionsWhenEmpty: wire.entangle('hideBulkActionsWhenEmpty'), toggleSelectAll() { if (!showBulkActionsAlpine) { return; diff --git a/resources/js/laravel-livewire-tables.min.js b/resources/js/laravel-livewire-tables.min.js index 6d78ed178..3b5991c4a 100644 --- a/resources/js/laravel-livewire-tables.min.js +++ b/resources/js/laravel-livewire-tables.min.js @@ -1 +1 @@ -document.addEventListener("alpine:init",()=>{Alpine.data("tableWrapper",(e,t)=>({childElementOpen:!1,filtersOpen:e.entangle("filterSlideDownDefaultVisible"),paginationCurrentCount:e.entangle("paginationCurrentCount"),paginationTotalItemCount:e.entangle("paginationTotalItemCount"),paginationCurrentItems:e.entangle("paginationCurrentItems"),selectedItems:e.entangle("selected"),alwaysShowBulkActions:!e.entangle("hideBulkActionsWhenEmpty"),toggleSelectAll(){t&&(this.paginationTotalItemCount===this.selectedItems.length?this.clearSelected():this.setAllSelected())},setAllSelected(){t&&e.setAllSelected()},clearSelected(){t&&e.clearSelected()},selectAllOnPage(){if(!t)return;let e=this.selectedItems,i=this.paginationCurrentItems.values();for(let l of i)e.push(l.toString());this.selectedItems=[...new Set(e)]}})),Alpine.data("numberRangeFilter",(e,t,i,l,a)=>({allFilters:e.entangle("filterComponents",!1),originalMin:0,originalMax:100,filterMin:0,filterMax:100,currentMin:0,currentMax:100,hasUpdate:!1,wireValues:e.entangle("filterComponents."+t,!1),defaultMin:l.minRange,defaultMax:l.maxRange,restrictUpdates:!1,updateStyles(){let e=document.getElementById(i),t=document.getElementById(a+"-min"),l=document.getElementById(a+"-max");e.style.setProperty("--value-a",t.value),e.style.setProperty("--text-value-a",JSON.stringify(t.value)),e.style.setProperty("--value-b",l.value),e.style.setProperty("--text-value-b",JSON.stringify(l.value))},setupWire(){void 0!==this.wireValues?(this.filterMin=this.originalMin=void 0!==this.wireValues.min?this.wireValues.min:this.defaultMin,this.filterMax=this.originalMax=void 0!==this.wireValues.max?this.wireValues.max:this.defaultMax):(this.filterMin=this.originalMin=this.defaultMin,this.filterMax=this.originalMax=this.defaultMax),this.updateStyles()},allowUpdates(){this.updateWire()},updateWire(){let e=parseInt(this.filterMin),t=parseInt(this.filterMax);(e!=this.originalMin||t!=this.originalMax)&&(tthis.setupWire())}})),Alpine.data("flatpickrFilter",(e,t,i,l,a)=>({wireValues:e.entangle("filterComponents."+t),flatpickrInstance:flatpickr(l,{mode:"range",clickOpens:!0,allowInvalidPreload:!0,defaultDate:[],ariaDateFormat:i.ariaDateFormat,allowInput:i.allowInput,altFormat:i.altFormat,altInput:i.altInput,dateFormat:i.dateFormat,locale:"en",minDate:i.earliestDate,maxDate:i.latestDate,onOpen:function(){window.childElementOpen=!0},onChange:function(i,l,a){if(i.length>1){var s=l.split(" ")[0],r=l.split(" ")[2],n={};window.childElementOpen=!1,window.filterPopoverOpen=!1,n={minDate:s,maxDate:r},e.set("filterComponents."+t,n)}}}),setupWire(){if(void 0!==this.wireValues){if(void 0!==this.wireValues.minDate&&void 0!==this.wireValues.maxDate){let e=[this.wireValues.minDate,this.wireValues.maxDate];this.flatpickrInstance.setDate(e)}else this.flatpickrInstance.setDate([])}else this.flatpickrInstance.setDate([])},init(){this.setupWire(),this.$watch("wireValues",e=>this.setupWire())}})),Alpine.data("reorderFunction",(e,t,i)=>({dragging:!1,reorderEnabled:!1,sourceID:"",targetID:"",evenRowClasses:"",oddRowClasses:"",currentlyHighlightedElement:"",evenRowClassArray:{},oddRowClassArray:{},evenNotInOdd:{},oddNotInEven:{},orderedRows:[],defaultReorderColumn:e.get("defaultReorderColumn"),reorderStatus:e.get("reorderStatus"),currentlyReorderingStatus:e.entangle("currentlyReorderingStatus"),hideReorderColumnUnlessReorderingStatus:e.entangle("hideReorderColumnUnlessReorderingStatus"),reorderDisplayColumn:e.entangle("reorderDisplayColumn"),dragStart(e){this.sourceID=e.target.id,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",e.target.id),e.target.classList.add("laravel-livewire-tables-dragging")},dragOverEvent(e){"object"==typeof this.currentlyHighlightedElement&&this.currentlyHighlightedElement.classList.remove("laravel-livewire-tables-highlight-bottom","laravel-livewire-tables-highlight-top");let t=e.target.closest("tr");this.currentlyHighlightedElement=t,e.offsetYi.getBoundingClientRect().height/2?l.insertBefore(a,i.nextSibling):l.insertBefore(a,i),r!l.includes(e)),this.oddNotInEven=l.filter(e=>!i.includes(e)),i=[],l=[])}},init(){this.$watch("currentlyReorderingStatus",e=>this.setupEvenOddClasses())}}))}); \ No newline at end of file +document.addEventListener("alpine:init",()=>{Alpine.data("tableWrapper",(e,t)=>({childElementOpen:!1,filtersOpen:e.entangle("filterSlideDownDefaultVisible"),paginationCurrentCount:e.entangle("paginationCurrentCount"),paginationTotalItemCount:e.entangle("paginationTotalItemCount"),paginationCurrentItems:e.entangle("paginationCurrentItems"),selectedItems:e.entangle("selected"),hideBulkActionsWhenEmpty:e.entangle("hideBulkActionsWhenEmpty"),toggleSelectAll(){t&&(this.paginationTotalItemCount===this.selectedItems.length?this.clearSelected():this.setAllSelected())},setAllSelected(){t&&e.setAllSelected()},clearSelected(){t&&e.clearSelected()},selectAllOnPage(){if(!t)return;let e=this.selectedItems,i=this.paginationCurrentItems.values();for(let l of i)e.push(l.toString());this.selectedItems=[...new Set(e)]}})),Alpine.data("numberRangeFilter",(e,t,i,l,a)=>({allFilters:e.entangle("filterComponents",!1),originalMin:0,originalMax:100,filterMin:0,filterMax:100,currentMin:0,currentMax:100,hasUpdate:!1,wireValues:e.entangle("filterComponents."+t,!1),defaultMin:l.minRange,defaultMax:l.maxRange,restrictUpdates:!1,updateStyles(){let e=document.getElementById(i),t=document.getElementById(a+"-min"),l=document.getElementById(a+"-max");e.style.setProperty("--value-a",t.value),e.style.setProperty("--text-value-a",JSON.stringify(t.value)),e.style.setProperty("--value-b",l.value),e.style.setProperty("--text-value-b",JSON.stringify(l.value))},setupWire(){void 0!==this.wireValues?(this.filterMin=this.originalMin=void 0!==this.wireValues.min?this.wireValues.min:this.defaultMin,this.filterMax=this.originalMax=void 0!==this.wireValues.max?this.wireValues.max:this.defaultMax):(this.filterMin=this.originalMin=this.defaultMin,this.filterMax=this.originalMax=this.defaultMax),this.updateStyles()},allowUpdates(){this.updateWire()},updateWire(){let e=parseInt(this.filterMin),t=parseInt(this.filterMax);(e!=this.originalMin||t!=this.originalMax)&&(tthis.setupWire())}})),Alpine.data("flatpickrFilter",(e,t,i,l,a)=>({wireValues:e.entangle("filterComponents."+t),flatpickrInstance:flatpickr(l,{mode:"range",clickOpens:!0,allowInvalidPreload:!0,defaultDate:[],ariaDateFormat:i.ariaDateFormat,allowInput:i.allowInput,altFormat:i.altFormat,altInput:i.altInput,dateFormat:i.dateFormat,locale:"en",minDate:i.earliestDate,maxDate:i.latestDate,onOpen:function(){window.childElementOpen=!0},onChange:function(i,l,a){if(i.length>1){var s=l.split(" ")[0],r=l.split(" ")[2],n={};window.childElementOpen=!1,window.filterPopoverOpen=!1,n={minDate:s,maxDate:r},e.set("filterComponents."+t,n)}}}),setupWire(){if(void 0!==this.wireValues){if(void 0!==this.wireValues.minDate&&void 0!==this.wireValues.maxDate){let e=[this.wireValues.minDate,this.wireValues.maxDate];this.flatpickrInstance.setDate(e)}else this.flatpickrInstance.setDate([])}else this.flatpickrInstance.setDate([])},init(){this.setupWire(),this.$watch("wireValues",e=>this.setupWire())}})),Alpine.data("reorderFunction",(e,t,i)=>({dragging:!1,reorderEnabled:!1,sourceID:"",targetID:"",evenRowClasses:"",oddRowClasses:"",currentlyHighlightedElement:"",evenRowClassArray:{},oddRowClassArray:{},evenNotInOdd:{},oddNotInEven:{},orderedRows:[],defaultReorderColumn:e.get("defaultReorderColumn"),reorderStatus:e.get("reorderStatus"),currentlyReorderingStatus:e.entangle("currentlyReorderingStatus"),hideReorderColumnUnlessReorderingStatus:e.entangle("hideReorderColumnUnlessReorderingStatus"),reorderDisplayColumn:e.entangle("reorderDisplayColumn"),dragStart(e){this.sourceID=e.target.id,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",e.target.id),e.target.classList.add("laravel-livewire-tables-dragging")},dragOverEvent(e){"object"==typeof this.currentlyHighlightedElement&&this.currentlyHighlightedElement.classList.remove("laravel-livewire-tables-highlight-bottom","laravel-livewire-tables-highlight-top");let t=e.target.closest("tr");this.currentlyHighlightedElement=t,e.offsetYi.getBoundingClientRect().height/2?l.insertBefore(a,i.nextSibling):l.insertBefore(a,i),r!l.includes(e)),this.oddNotInEven=l.filter(e=>!i.includes(e)),i=[],l=[])}},init(){this.$watch("currentlyReorderingStatus",e=>this.setupEvenOddClasses())}}))}); \ No newline at end of file diff --git a/resources/views/components/tools/toolbar/items/bulk-actions.blade.php b/resources/views/components/tools/toolbar/items/bulk-actions.blade.php index 82fe34ca1..811a27b99 100644 --- a/resources/views/components/tools/toolbar/items/bulk-actions.blade.php +++ b/resources/views/components/tools/toolbar/items/bulk-actions.blade.php @@ -1,7 +1,7 @@ @aware(['component', 'tableName'])
$component->isBootstrap(), 'w-full md:w-auto mb-4 md:mb-0' => $component->isTailwind(), From ce95a70af99ba2cd36063c04ca44eae6d8c7a2a1 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:25:08 +0100 Subject: [PATCH 06/11] Change Return Type for attributes() to static (#1749) --- src/Views/Traits/Core/HasAttributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Views/Traits/Core/HasAttributes.php b/src/Views/Traits/Core/HasAttributes.php index 2707b8671..2978d5822 100644 --- a/src/Views/Traits/Core/HasAttributes.php +++ b/src/Views/Traits/Core/HasAttributes.php @@ -11,7 +11,7 @@ trait HasAttributes { protected ?Closure $attributesCallback = null; - public function attributes(Closure $callback): self + public function attributes(Closure $callback): static { $this->attributesCallback = $callback; From 5c404729e9e28e991bb807fd4b0d104d48d7feca Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:25:22 +0100 Subject: [PATCH 07/11] Switch to using Composer\InstalledVersions for AboutCommand to reduce necessity to update ServiceProvider with each update (#1748) --- src/LaravelLivewireTablesServiceProvider.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index f0a50ed70..c3c32fe2d 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -14,7 +14,11 @@ class LaravelLivewireTablesServiceProvider extends ServiceProvider public function boot(): void { - AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.7']); + if (class_exists(AboutCommand::class) && class_exists(\Composer\InstalledVersions::class)) { + AboutCommand::add('Rappasoft Laravel Livewire Tables', [ + 'Version' => \Composer\InstalledVersions::getPrettyVersion('rappasoft/laravel-livewire-tables'), + ]); + } $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' From 119401b2f609bac3ce6549e8f7a4ed701a03a2da Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:48:18 +0100 Subject: [PATCH 08/11] Two improvements to improve typehinting, migrate to larastan/larastan, cleanup of test (#1750) --- composer.json | 2 +- phpstan.neon | 6 +++--- src/LaravelLivewireTablesServiceProvider.php | 2 +- src/Traits/Helpers/TableAttributeHelpers.php | 4 ++-- tests/Views/Columns/LinkColumnTest.php | 6 ++---- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index d3e9e6372..bda267c29 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "laravel/pint": "^1.10", "monolog/monolog": "*", "nunomaduro/collision": "^6.0|^7.0|^8.0", - "nunomaduro/larastan": "^2.6", + "larastan/larastan": "^2.6", "orchestra/testbench": "^7.0|^8.0|^9.0", "phpunit/phpunit": "^9.0|^10.0|^11.0" }, diff --git a/phpstan.neon b/phpstan.neon index 7ed8f5027..a0324459d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - vendor/nunomaduro/larastan/extension.neon + - vendor/larastan/larastan/extension.neon parameters: paths: @@ -10,11 +10,11 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true - checkMissingIterableValueType: false treatPhpDocTypesAsCertain: false reportUnmatchedIgnoredErrors: false - checkGenericClassInNonGenericObjectType: false ignoreErrors: + - identifier: missingType.generics + - identifier: missingType.iterableValue - '#Access to an undefined property Rappasoft\\LaravelLivewireTables\\Views\\Column\:\:\$view#' - "#Unsafe usage of new static#" - '#on array\, mixed\>\> in empty\(\) does not exist.#' diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index c3c32fe2d..e10027b51 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -44,7 +44,7 @@ public function boot(): void } - public function consoleCommands() + public function consoleCommands(): void { if ($this->app->runningInConsole()) { diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 3da2da12e..866e72526 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -84,12 +84,12 @@ public function hasTableRowUrl(): bool return $this->trUrlCallback !== null; } - public function getTableRowUrl($row): ?string + public function getTableRowUrl(int|Model $row): ?string { return $this->trUrlCallback ? call_user_func($this->trUrlCallback, $row) : null; } - public function getTableRowUrlTarget($row): ?string + public function getTableRowUrlTarget(int|Model $row): ?string { return $this->trUrlTargetCallback ? call_user_func($this->trUrlTargetCallback, $row) : null; } diff --git a/tests/Views/Columns/LinkColumnTest.php b/tests/Views/Columns/LinkColumnTest.php index 4a204c0ff..d981d7aad 100644 --- a/tests/Views/Columns/LinkColumnTest.php +++ b/tests/Views/Columns/LinkColumnTest.php @@ -44,8 +44,7 @@ public function test_can_render_field_if_title_and_location_callback(): void $this->assertNotEmpty($column); } - /** @test */ - public function can_check_ishtml_from_html_column(): void + public function test_can_check_ishtml_from_html_column(): void { $column = LinkColumn::make('Name', 'name') ->title(fn ($row) => 'Title') @@ -55,8 +54,7 @@ public function can_check_ishtml_from_html_column(): void $this->assertTrue($column->isHtml()); } - /** @test */ - public function can_get_html_from_html_label_column(): void + public function test_can_get_html_from_html_label_column(): void { $column = LinkColumn::make('Name', 'name') ->title(fn ($row) => 'My Label') From ea2c8fc3cfa6e8c2bb808946d349147b9589bffe Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:48:45 +0100 Subject: [PATCH 09/11] Add ArrayColumn (BETA) (#1751) * Add ArrayColumn * Fix styling --------- Co-authored-by: lrljoe --- src/Views/Columns/ArrayColumn.php | 31 +++++++++ .../ArrayColumnConfiguration.php | 29 ++++++++ .../Traits/Helpers/ArrayColumnHelpers.php | 69 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/Views/Columns/ArrayColumn.php create mode 100644 src/Views/Traits/Configuration/ArrayColumnConfiguration.php create mode 100644 src/Views/Traits/Helpers/ArrayColumnHelpers.php diff --git a/src/Views/Columns/ArrayColumn.php b/src/Views/Columns/ArrayColumn.php new file mode 100644 index 000000000..be9366db0 --- /dev/null +++ b/src/Views/Columns/ArrayColumn.php @@ -0,0 +1,31 @@ +'; + + public string $emptyValue = ''; + + protected mixed $dataCallback = null; + + protected mixed $outputFormat = null; + + public function __construct(string $title, ?string $from = null) + { + parent::__construct($title, $from); + if (! isset($from)) { + $this->label(fn () => null); + } + } +} diff --git a/src/Views/Traits/Configuration/ArrayColumnConfiguration.php b/src/Views/Traits/Configuration/ArrayColumnConfiguration.php new file mode 100644 index 000000000..72188fd79 --- /dev/null +++ b/src/Views/Traits/Configuration/ArrayColumnConfiguration.php @@ -0,0 +1,29 @@ +separator = $value; + + return $this; + } + + public function data(callable $callable): self + { + $this->dataCallback = $callable; + + return $this; + } + + public function outputFormat(callable $callable): self + { + $this->outputFormat = $callable; + + return $this; + } +} diff --git a/src/Views/Traits/Helpers/ArrayColumnHelpers.php b/src/Views/Traits/Helpers/ArrayColumnHelpers.php new file mode 100644 index 000000000..7c32f7c70 --- /dev/null +++ b/src/Views/Traits/Helpers/ArrayColumnHelpers.php @@ -0,0 +1,69 @@ +separator !== null && is_string($this->separator); + } + + public function getSeparator(): string + { + return $this->separator; + } + + public function getEmptyValue(): string + { + return $this->emptyValue; + } + + public function hasDataCallback(): bool + { + return isset($this->dataCallback) && is_callable($this->dataCallback); + } + + public function getDataCallback(): ?callable + { + return $this->dataCallback; + } + + public function hasOutputFormatCallback(): bool + { + return isset($this->outputFormat) && is_callable($this->outputFormat); + } + + public function getOutputFormatCallback(): ?callable + { + return $this->outputFormat; + } + + public function getContents(Model $row): null|string|\BackedEnum|HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + { + $outputValues = []; + $value = $this->getValue($row); + + if (! $this->hasSeparator()) { + throw new DataTableConfigurationException('You must set a valid separator on an ArrayColumn'); + } + + if (! $this->hasDataCallback()) { + throw new DataTableConfigurationException('You must set a data() method on an ArrayColumn'); + } + + if (! $this->hasOutputFormatCallback()) { + throw new DataTableConfigurationException('You must set an outputFormat() method on an ArrayColumn'); + } + + foreach (call_user_func($this->getDataCallback(), $value, $row) as $i => $v) { + $outputValues[] = call_user_func($this->getOutputFormatCallback(), $i, $v); + } + + return new HtmlString((! empty($outputValues) ? implode($this->getSeparator(), $outputValues) : $this->getEmptyValue())); + } +} From 2acac1b70c041218bf4893670ee973bca219f5c8 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:09:05 +0100 Subject: [PATCH 10/11] Always hide bulk actions option (#1752) * Add option to "Always Hide Bulk Actions" * Fix styling * Fix test function name clash --------- Co-authored-by: lrljoe --- docs/bulk-actions/available-methods.md | 35 ++++++ .../views/components/tools/toolbar.blade.php | 2 +- .../BulkActionsConfiguration.php | 21 ++++ src/Traits/Helpers/BulkActionsHelpers.php | 8 ++ src/Traits/WithBulkActions.php | 2 + .../Traits/Visuals/BulkActionsVisualsTest.php | 109 ++++++++++++++++++ 6 files changed, 176 insertions(+), 1 deletion(-) diff --git a/docs/bulk-actions/available-methods.md b/docs/bulk-actions/available-methods.md index 22b8210ee..ad98e1999 100644 --- a/docs/bulk-actions/available-methods.md +++ b/docs/bulk-actions/available-methods.md @@ -239,3 +239,38 @@ public function configure(): void ]); } ``` + +## setShouldAlwaysHideBulkActionsDropdownOption + +Allows hiding the Bulk Actions button & menu, regardless of whether there are any items selected, or hideBulkActionsWhenEmptyEnabled behaviour + +```php +public function configure(): void +{ + $this->setShouldAlwaysHideBulkActionsDropdownOption(true); +} +``` + + +## setShouldAlwaysHideBulkActionsDropdownOptionEnabled + +Allows hiding the Bulk Actions button & menu, regardless of whether there are any items selected, or hideBulkActionsWhenEmptyEnabled behaviour + +```php +public function configure(): void +{ + $this->setShouldAlwaysHideBulkActionsDropdownOptionEnabled(); +} +``` + + +## setShouldAlwaysHideBulkActionsDropdownOptionDisabled + +Restores the Bulk Actions to default functionality, so it will respect the hideBulkActionsWhenEmptyEnabled behaviour + +```php +public function configure(): void +{ + $this->setShouldAlwaysHideBulkActionsDropdownOptionDisabled(); +} +``` diff --git a/resources/views/components/tools/toolbar.blade.php b/resources/views/components/tools/toolbar.blade.php index a753403c6..84bb061e8 100644 --- a/resources/views/components/tools/toolbar.blade.php +++ b/resources/views/components/tools/toolbar.blade.php @@ -56,7 +56,7 @@ @include($component->getConfigurableAreaFor('toolbar-right-start'), $component->getParametersForConfigurableArea('toolbar-right-start')) @endif - @if ($component->showBulkActionsDropdownAlpine()) + @if ($component->showBulkActionsDropdownAlpine() && $this->shouldAlwaysHideBulkActionsDropdownOption != true) @endif diff --git a/src/Traits/Configuration/BulkActionsConfiguration.php b/src/Traits/Configuration/BulkActionsConfiguration.php index 813d46f42..d0d5e17f3 100644 --- a/src/Traits/Configuration/BulkActionsConfiguration.php +++ b/src/Traits/Configuration/BulkActionsConfiguration.php @@ -150,4 +150,25 @@ public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxA return $this; } + + public function setShouldAlwaysHideBulkActionsDropdownOption(bool $status = false): self + { + $this->alwaysHideBulkActionsDropdownOption = $status; + + return $this; + } + + public function setShouldAlwaysHideBulkActionsDropdownOptionEnabled(): self + { + $this->setShouldAlwaysHideBulkActionsDropdownOption(true); + + return $this; + } + + public function setShouldAlwaysHideBulkActionsDropdownOptionDisabled(): self + { + $this->setShouldAlwaysHideBulkActionsDropdownOption(false); + + return $this; + } } diff --git a/src/Traits/Helpers/BulkActionsHelpers.php b/src/Traits/Helpers/BulkActionsHelpers.php index 29f162bb6..70ea427a5 100644 --- a/src/Traits/Helpers/BulkActionsHelpers.php +++ b/src/Traits/Helpers/BulkActionsHelpers.php @@ -2,6 +2,8 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; +use Livewire\Attributes\Computed; + trait BulkActionsHelpers { public function getBulkActionsStatus(): bool @@ -212,4 +214,10 @@ public function getBulkActionsTdCheckboxAttributes(): array { return $this->bulkActionsTdCheckboxAttributes ?? ['default' => true]; } + + #[Computed] + public function shouldAlwaysHideBulkActionsDropdownOption(): bool + { + return $this->alwaysHideBulkActionsDropdownOption ?? false; + } } diff --git a/src/Traits/WithBulkActions.php b/src/Traits/WithBulkActions.php index e05175733..08f69197b 100644 --- a/src/Traits/WithBulkActions.php +++ b/src/Traits/WithBulkActions.php @@ -34,6 +34,8 @@ trait WithBulkActions protected array $bulkActionsTdCheckboxAttributes = ['default' => true]; + protected bool $alwaysHideBulkActionsDropdownOption = false; + public function bulkActions(): array { return property_exists($this, 'bulkActions') ? $this->bulkActions : []; diff --git a/tests/Traits/Visuals/BulkActionsVisualsTest.php b/tests/Traits/Visuals/BulkActionsVisualsTest.php index 5447891da..91f73c177 100644 --- a/tests/Traits/Visuals/BulkActionsVisualsTest.php +++ b/tests/Traits/Visuals/BulkActionsVisualsTest.php @@ -80,4 +80,113 @@ public function test_bulk_actions_row_shows_correct_for_select_some(): void ->assertSee('do you want to select all') ->assertDontSee('You are currently selecting all'); }*/ + + public function test_bulk_dropdown_shows_when_necessary_extended(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id'); + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertSee('Bulk Actions'); + } + + public function test_bulk_dropdown_shows_when_not_permanently_hidden(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id') + ->setShouldAlwaysHideBulkActionsDropdownOption(false); + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertSee('Bulk Actions'); + } + + public function test_bulk_dropdown_hides_when_permanently_hidden(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id') + ->setShouldAlwaysHideBulkActionsDropdownOption(true); + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertDontSee('Bulk Actions'); + } + + public function test_bulk_dropdown_shows_when_not_permanently_hidden_disabled(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id') + ->setShouldAlwaysHideBulkActionsDropdownOptionDisabled(); + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertSee('Bulk Actions'); + } + + public function test_bulk_dropdown_hides_when_permanently_hidden_enabled(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id') + ->setShouldAlwaysHideBulkActionsDropdownOptionEnabled(); + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertDontSee('Bulk Actions'); + } } From 363374370e9c5d261a50a94bf2c53606033b004f Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:29:33 +0100 Subject: [PATCH 11/11] Optionally disable count for simple pagination (#1755) * Add option for setShouldRetrieveTotalItemCountStatus * Fix styling --------- Co-authored-by: lrljoe --- docs/pagination/available-methods.md | 33 +++++++++++++++++++ .../Configuration/PaginationConfiguration.php | 22 +++++++++++++ src/Traits/Helpers/PaginationHelpers.php | 6 ++++ src/Traits/WithData.php | 18 ++++++---- src/Traits/WithPagination.php | 2 ++ .../Traits/Helpers/PaginationHelpersTest.php | 30 +++++++++++++++++ 6 files changed, 104 insertions(+), 7 deletions(-) diff --git a/docs/pagination/available-methods.md b/docs/pagination/available-methods.md index d1b60a375..638e58a4b 100644 --- a/docs/pagination/available-methods.md +++ b/docs/pagination/available-methods.md @@ -263,3 +263,36 @@ public function configure(): void ]); } ``` + +## setShouldRetrieveTotalItemCountStatus + +Used when "simple" pagination is being used, allows the enabling/disabling of the "total records" count. This may be desirable to disable in larger data sets. This is enabled by default. + +```php +public function configure(): void +{ + $this->setShouldRetrieveTotalItemCountStatus(false); +} +``` + +## setShouldRetrieveTotalItemCountEnabled + +Used when "simple" pagination is being used, enables the "total records" count. + +```php +public function configure(): void +{ + $this->setShouldRetrieveTotalItemCountEnabled(); +} +``` + +## setShouldRetrieveTotalItemCountDisabled + +Used when "simple" pagination is being used, disables the "total records" count. + +```php +public function configure(): void +{ + $this->setShouldRetrieveTotalItemCountDisabled(); +} +``` diff --git a/src/Traits/Configuration/PaginationConfiguration.php b/src/Traits/Configuration/PaginationConfiguration.php index d7ffa5c34..a8877653a 100644 --- a/src/Traits/Configuration/PaginationConfiguration.php +++ b/src/Traits/Configuration/PaginationConfiguration.php @@ -155,4 +155,26 @@ public function setPerPageFieldAttributes(array $attributes = []): self return $this; } + + public function setShouldRetrieveTotalItemCountStatus(bool $status): self + { + $this->shouldRetrieveTotalItemCount = $status; + + return $this; + + } + + public function setShouldRetrieveTotalItemCountEnabled(): self + { + $this->setShouldRetrieveTotalItemCountStatus(true); + + return $this; + } + + public function setShouldRetrieveTotalItemCountDisabled(): self + { + $this->setShouldRetrieveTotalItemCountStatus(false); + + return $this; + } } diff --git a/src/Traits/Helpers/PaginationHelpers.php b/src/Traits/Helpers/PaginationHelpers.php index 7a744f225..717af7c12 100644 --- a/src/Traits/Helpers/PaginationHelpers.php +++ b/src/Traits/Helpers/PaginationHelpers.php @@ -149,4 +149,10 @@ public function getPerPageFieldAttributes(): array { return $this->perPageFieldAttributes; } + + #[Computed] + public function getShouldRetrieveTotalItemCount(): bool + { + return $this->shouldRetrieveTotalItemCount; + } } diff --git a/src/Traits/WithData.php b/src/Traits/WithData.php index 9dcd44a4c..6d3261c93 100644 --- a/src/Traits/WithData.php +++ b/src/Traits/WithData.php @@ -80,21 +80,25 @@ protected function executeQuery(): Collection|CursorPaginator|Paginator|LengthAw $this->paginationTotalItemCount = $paginatedResults->total() ?? 0; return $paginatedResults; - } - - if ($this->isPaginationMethod('simple')) { + } elseif ($this->isPaginationMethod('simple')) { - $this->paginationTotalItemCount = $this->getBuilder()->count(); + if ($this->getShouldRetrieveTotalItemCount()) { + $this->paginationTotalItemCount = $this->getBuilder()->count(); - return $this->getBuilder()->simplePaginate($this->getPerPage() === -1 ? $this->paginationTotalItemCount : $this->getPerPage(), ['*'], $this->getComputedPageName()); + return $this->getBuilder()->simplePaginate($this->getPerPage() === -1 ? $this->paginationTotalItemCount : $this->getPerPage(), ['*'], $this->getComputedPageName()); + } else { + $this->paginationTotalItemCount = -1; - } + return $this->getBuilder()->simplePaginate($this->getPerPage() === -1 ? 10 : $this->getPerPage(), ['*'], $this->getComputedPageName()); + } - if ($this->isPaginationMethod('cursor')) { + } elseif ($this->isPaginationMethod('cursor')) { $this->paginationTotalItemCount = $this->getBuilder()->count(); return $this->getBuilder()->cursorPaginate($this->getPerPage() === -1 ? $this->paginationTotalItemCount : $this->getPerPage(), ['*'], $this->getComputedPageName()); + } else { + throw new DataTableConfigurationException('Pagination method must be either simple, standard or cursor'); } } diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index 676d034b6..6f022a9fb 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -41,6 +41,8 @@ trait WithPagination protected array $perPageFieldAttributes = ['default-styling' => true, 'default-colors' => true, 'class' => '']; + protected bool $shouldRetrieveTotalItemCount = true; + public function mountWithPagination(): void { $sessionPerPage = session()->get($this->getPerPagePaginationSessionKey(), $this->getPerPageAccepted()[0] ?? 10); diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index 471ee0d7f..0ec6557a4 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -141,4 +141,34 @@ public function test_can_get_pagination_field_attributes(): void $this->assertSame(['default-styling' => false, 'default-colors' => true, 'class' => 'bg-blue-500 dark:bg-red-500'], $this->basicTable->getPerPageFieldAttributes()); } + + public function test_can_toggle_total_item_count_retrieval(): void + { + + $this->assertTrue($this->basicTable->getShouldRetrieveTotalItemCount()); + + $this->basicTable->setShouldRetrieveTotalItemCountDisabled(); + + $this->assertFalse($this->basicTable->getShouldRetrieveTotalItemCount()); + + $this->basicTable->setShouldRetrieveTotalItemCountEnabled(); + + $this->assertTrue($this->basicTable->getShouldRetrieveTotalItemCount()); + + } + + public function test_can_toggle_total_item_count_retrieval_via_status(): void + { + + $this->assertTrue($this->basicTable->getShouldRetrieveTotalItemCount()); + + $this->basicTable->setShouldRetrieveTotalItemCountStatus(false); + + $this->assertFalse($this->basicTable->getShouldRetrieveTotalItemCount()); + + $this->basicTable->setShouldRetrieveTotalItemCountStatus(true); + + $this->assertTrue($this->basicTable->getShouldRetrieveTotalItemCount()); + + } }