From 64dd5e373d463ab6aebb9f93083315b162d7d629 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:02:35 +0100 Subject: [PATCH 01/11] Pagination Updates --- src/Traits/Helpers/PaginationHelpers.php | 16 ++++++++++++++++ src/Traits/WithData.php | 7 ++++++- src/Traits/WithPagination.php | 2 ++ tests/Traits/Helpers/PaginationHelpersTest.php | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Traits/Helpers/PaginationHelpers.php b/src/Traits/Helpers/PaginationHelpers.php index d9e3403ff..5357982d1 100644 --- a/src/Traits/Helpers/PaginationHelpers.php +++ b/src/Traits/Helpers/PaginationHelpers.php @@ -143,4 +143,20 @@ public function isPaginationMethod(string $paginationMethod): bool { return $this->paginationMethod === $paginationMethod; } + + /** + * @return array + */ + public function getPerPageDisplayedItemIds(): array + { + return $this->paginationCurrentItems; + } + + /** + * @return int + */ + public function getPerPageDisplayedItemCount(): int + { + return $this->paginationCurrentCount; + } } diff --git a/src/Traits/WithData.php b/src/Traits/WithData.php index d68625fdb..99fa45dfc 100644 --- a/src/Traits/WithData.php +++ b/src/Traits/WithData.php @@ -15,7 +15,12 @@ public function getRows() { $this->baseQuery(); - return $this->executeQuery(); + $executedQuery = $this->executeQuery(); + + $this->paginationCurrentItems = $executedQuery->pluck($this->getPrimaryKey())->toArray() ?? []; + $this->paginationCurrentCount = $executedQuery->count() ?? 0; + + return $executedQuery; } protected function baseQuery(): Builder diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index 74cfe3e18..f601d9995 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -20,6 +20,8 @@ trait WithPagination public bool $paginationVisibilityStatus = true; public bool $perPageVisibilityStatus = true; public string $paginationMethod = 'standard'; + public array $paginationCurrentItems = []; + public int $paginationCurrentCount = 0; // TODO: Test public function setupPagination(): void diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index 52996c976..7c32bbcaa 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -87,4 +87,18 @@ public function can_check_and_set_pagination_method(): void $this->assertTrue($this->basicTable->isPaginationMethod('standard')); } + + /** @test */ + public function can_get_currently_displayed_ids(): void + { + $this->assertSame([1,2,3,4,5], $this->basicTable->getPerPageDisplayedItemIds()); + } + + /** @test */ + public function can_get_currently_displayed_count(): void + { + $this->assertSame(5, $this->basicTable->getPerPageDisplayedItemCount()); + } + + } From 9104975b3c047c6a0731996b55879e1d5c8e59a5 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 00:03:06 +0000 Subject: [PATCH 02/11] Fix styling --- tests/Traits/Helpers/PaginationHelpersTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index 7c32bbcaa..de80f2613 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -99,6 +99,4 @@ public function can_get_currently_displayed_count(): void { $this->assertSame(5, $this->basicTable->getPerPageDisplayedItemCount()); } - - } From f0290efa957230a846a1ccb819e5a63c649509c4 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:09:37 +0100 Subject: [PATCH 03/11] LW Test --- docs/pagination/available-methods.md | 16 ++++++++++++++++ tests/Traits/Helpers/PaginationHelpersTest.php | 11 ----------- tests/Traits/Visuals/PaginationVisualsTest.php | 13 +++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/docs/pagination/available-methods.md b/docs/pagination/available-methods.md index 76e300154..380d92f0e 100644 --- a/docs/pagination/available-methods.md +++ b/docs/pagination/available-methods.md @@ -172,3 +172,19 @@ public function configure(): void $this->setPaginationMethod('simple'); } ``` + +## getPerPageDisplayedItemIds + +Returns the Primary Key for the currently visible rows in an array. This should be used in a blade to ensure accuracy. + +```php + $this->getPerPageDisplayedItemIds(); +``` + +## getPerPageDisplayedItemCount + +Returns the number of rows that are currently displayed. This should be used in a blade to ensure accuracy. + +```php + $this->getPerPageDisplayedItemCount(); +``` diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index 7c32bbcaa..6f2593cca 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -88,17 +88,6 @@ public function can_check_and_set_pagination_method(): void $this->assertTrue($this->basicTable->isPaginationMethod('standard')); } - /** @test */ - public function can_get_currently_displayed_ids(): void - { - $this->assertSame([1,2,3,4,5], $this->basicTable->getPerPageDisplayedItemIds()); - } - /** @test */ - public function can_get_currently_displayed_count(): void - { - $this->assertSame(5, $this->basicTable->getPerPageDisplayedItemCount()); - } - } diff --git a/tests/Traits/Visuals/PaginationVisualsTest.php b/tests/Traits/Visuals/PaginationVisualsTest.php index 8fc9cdaa2..cc2c97fec 100644 --- a/tests/Traits/Visuals/PaginationVisualsTest.php +++ b/tests/Traits/Visuals/PaginationVisualsTest.php @@ -149,4 +149,17 @@ public function per_page_dropdown_only_renders_with_accepted_values(): void Livewire::test(PetsTable::class) ->call('setPerPage', 15); } + + /** @test */ + public function can_get_currently_displayed_ids(): void + { + Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]) + } + + /** @test */ + public function can_get_currently_displayed_count(): void + { + Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5) + } + } From 0730a4c4bcc131f649f565559dac95090cef0053 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:12:27 +0100 Subject: [PATCH 04/11] Test --- tests/Traits/Helpers/PaginationHelpersTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index 0b1177a9e..5e951b9e0 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -88,10 +88,4 @@ public function can_check_and_set_pagination_method(): void $this->assertTrue($this->basicTable->isPaginationMethod('standard')); } - - /** @test */ - public function can_get_currently_displayed_count(): void - { - $this->assertSame(5, $this->basicTable->getPerPageDisplayedItemCount()); - } } From 5b545578eb2e7843011ee2c068990dcbd6bd310a Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 00:12:58 +0000 Subject: [PATCH 05/11] Fix styling --- tests/Traits/Helpers/PaginationHelpersTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index 5e951b9e0..52996c976 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -87,5 +87,4 @@ public function can_check_and_set_pagination_method(): void $this->assertTrue($this->basicTable->isPaginationMethod('standard')); } - } From b00471a2e17bbc5883f994a9da4a33b75ac19b52 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:13:25 +0100 Subject: [PATCH 06/11] Tests --- tests/Traits/Visuals/PaginationVisualsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Traits/Visuals/PaginationVisualsTest.php b/tests/Traits/Visuals/PaginationVisualsTest.php index cc2c97fec..18289b3d0 100644 --- a/tests/Traits/Visuals/PaginationVisualsTest.php +++ b/tests/Traits/Visuals/PaginationVisualsTest.php @@ -153,13 +153,13 @@ public function per_page_dropdown_only_renders_with_accepted_values(): void /** @test */ public function can_get_currently_displayed_ids(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]) + Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]); } /** @test */ public function can_get_currently_displayed_count(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5) + Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5); } } From 0620c3f206ba675e585a6db252f2e9453b08b3d7 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 00:13:55 +0000 Subject: [PATCH 07/11] Fix styling --- tests/Traits/Visuals/PaginationVisualsTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Traits/Visuals/PaginationVisualsTest.php b/tests/Traits/Visuals/PaginationVisualsTest.php index 18289b3d0..983e4a69b 100644 --- a/tests/Traits/Visuals/PaginationVisualsTest.php +++ b/tests/Traits/Visuals/PaginationVisualsTest.php @@ -153,13 +153,12 @@ public function per_page_dropdown_only_renders_with_accepted_values(): void /** @test */ public function can_get_currently_displayed_ids(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]); + Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems', [1,2,3,4,5]); } /** @test */ public function can_get_currently_displayed_count(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5); + Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount', 5); } - } From c8b0e5404e4c2092feb1e9b1c34955f8efdf7b99 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:16:34 +0100 Subject: [PATCH 08/11] Test Merging --- tests/Traits/Visuals/PaginationVisualsTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Traits/Visuals/PaginationVisualsTest.php b/tests/Traits/Visuals/PaginationVisualsTest.php index 18289b3d0..5d7f8120b 100644 --- a/tests/Traits/Visuals/PaginationVisualsTest.php +++ b/tests/Traits/Visuals/PaginationVisualsTest.php @@ -153,13 +153,16 @@ public function per_page_dropdown_only_renders_with_accepted_values(): void /** @test */ public function can_get_currently_displayed_ids(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]); + Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]) + ->assertNotSet('paginationCurrentItems',[1,2,3,4,5,6,7,8,9]); + } /** @test */ public function can_get_currently_displayed_count(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5); + Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5) + ->assertNotSet('paginationCurrentCount',125); } } From a2b0824befab7f0eaaa122c60058845801d5487e Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 00:17:33 +0000 Subject: [PATCH 09/11] Fix styling --- tests/Traits/Visuals/PaginationVisualsTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Traits/Visuals/PaginationVisualsTest.php b/tests/Traits/Visuals/PaginationVisualsTest.php index 30f279f5a..48f0ef98b 100644 --- a/tests/Traits/Visuals/PaginationVisualsTest.php +++ b/tests/Traits/Visuals/PaginationVisualsTest.php @@ -153,15 +153,14 @@ public function per_page_dropdown_only_renders_with_accepted_values(): void /** @test */ public function can_get_currently_displayed_ids(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems',[1,2,3,4,5]) - ->assertNotSet('paginationCurrentItems',[1,2,3,4,5,6,7,8,9]); - + Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems', [1,2,3,4,5]) + ->assertNotSet('paginationCurrentItems', [1,2,3,4,5,6,7,8,9]); } /** @test */ public function can_get_currently_displayed_count(): void { - Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount',5) - ->assertNotSet('paginationCurrentCount',125); + Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount', 5) + ->assertNotSet('paginationCurrentCount', 125); } } From 858eda20f40c55672969c49be369444f0a464952 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:20:20 +0100 Subject: [PATCH 10/11] ChangeLog Update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05cdd9865..2b5677cdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file - Set Row for Filter (setFilterSlidedownRow(()) - Set ColSpan for Filter (setFilterSlidedownColspan()) - Workflow (run-phpstan) - Introducing PHP-Stan at Level 3 to ensure code-quality persists - https://github.com/rappasoft/laravel-livewire-tables/pull/1133 +- Added getPerPageDisplayedItemIds() and getPerPageDisplayedItemCount() along with public variables to allow retrieval of currently paginated PrimayKey and Item Count ### Changed From c37551853937341f3d5a40dc8a76e47d5846847c Mon Sep 17 00:00:00 2001 From: lrljoe Date: Fri, 31 Mar 2023 01:20:51 +0100 Subject: [PATCH 11/11] Updating ChangeLog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5677cdc..6ede90f3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file - Set Row for Filter (setFilterSlidedownRow(()) - Set ColSpan for Filter (setFilterSlidedownColspan()) - Workflow (run-phpstan) - Introducing PHP-Stan at Level 3 to ensure code-quality persists - https://github.com/rappasoft/laravel-livewire-tables/pull/1133 -- Added getPerPageDisplayedItemIds() and getPerPageDisplayedItemCount() along with public variables to allow retrieval of currently paginated PrimayKey and Item Count +- Added getPerPageDisplayedItemIds() and getPerPageDisplayedItemCount() along with public variables to allow retrieval of currently paginated PrimayKey and Item Count https://github.com/rappasoft/laravel-livewire-tables/pull/1136 ### Changed