Skip to content

Commit

Permalink
Respect setDisplayPaginationDetailsDisabled for unpaginated tables
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Dec 8, 2024
1 parent 51f998a commit 3ec04fc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 94 deletions.
129 changes: 40 additions & 89 deletions resources/views/components/pagination.blade.php
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
@aware(['isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])

@includeWhen(
$this->hasConfigurableAreaFor('before-pagination'),
$this->getConfigurableAreaFor('before-pagination'),
$this->getParametersForConfigurableArea('before-pagination')
)

@if ($this->isTailwind)
<div {{ $this->getPaginationWrapperAttributesBag() }}>
@if ($this->paginationVisibilityIsEnabled())
<div {{ $this->getPaginationWrapperAttributesBag() }}>
@if ($this->paginationVisibilityIsEnabled())
@if ($this->isTailwind)
<div class="mt-4 px-4 md:p-0 sm:flex justify-between items-center space-y-4 sm:space-y-0">
<div>
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
@if ($this->paginationIsEnabled && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1 && $this->showPaginationDetails)
<p class="paged-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
@if($this->showPaginationDetails())
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<span class="font-medium">{{ $this->getRows->firstItem() }}</span>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
<span class="font-medium">{{ $this->getRows->lastItem() }}</span>
<span>{{ __($this->getLocalisationPath.'of') }}</span>
<span class="font-medium"><span x-text="paginationTotalItemCount"></span></span>
<span>{{ __($this->getLocalisationPath.'results') }}</span>
@endif
</p>
@elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('simple'))
@elseif ($this->paginationIsEnabled && $this->isPaginationMethod('simple') && $this->showPaginationDetails)
<p class="paged-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
@if($this->showPaginationDetails())
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<span class="font-medium">{{ $this->getRows->firstItem() }}</span>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
<span class="font-medium">{{ $this->getRows->lastItem() }}</span>
@endif
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<span class="font-medium">{{ $this->getRows->firstItem() }}</span>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
<span class="font-medium">{{ $this->getRows->lastItem() }}</span>
</p>
@elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('cursor'))
@elseif ($this->paginationIsEnabled && $this->isPaginationMethod('cursor'))
@else
<p class="total-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
{{ __($this->getLocalisationPath.'Showing') }}
<span class="font-medium">{{ $this->getRows->count() }}</span>
{{ __($this->getLocalisationPath.'results') }}
</p>
@if($this->showPaginationDetails)
<p class="total-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<span class="font-medium">{{ $this->getRows->count() }}</span>
<span>{{ __($this->getLocalisationPath.'results') }}</span>
</p>
@endif
@endif
</div>

@if ($this->paginationIsEnabled())
@if ($this->paginationIsEnabled)
{{ $this->getRows->links('livewire-tables::specific.tailwind.'.(!$this->isPaginationMethod('standard') ? 'simple-' : '').'pagination') }}
@endif
</div>
@endif
</div>
@elseif ($this->isBootstrap4)
<div {{ $this->getPaginationWrapperAttributesBag() }}>
@if ($this->paginationVisibilityIsEnabled())
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
@else
@if ($this->paginationIsEnabled && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
<div class="row mt-3">
<div class="col-12 col-md-6 overflow-auto">
{{ $this->getRows->links('livewire-tables::specific.bootstrap-4.pagination') }}
</div>

<div class="col-12 col-md-6 text-center text-md-right text-muted">
@if($this->showPaginationDetails())
<div @class([
"col-12 col-md-6 text-center text-muted",
"text-md-right" => $this->isBootstrap4,
"text-md-end" => $this->isBootstrap5,
])>
@if($this->showPaginationDetails)
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }}</strong>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
Expand All @@ -69,22 +65,26 @@
@endif
</div>
</div>
@elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('simple'))
@elseif ($this->paginationIsEnabled && $this->isPaginationMethod('simple'))
<div class="row mt-3">
<div class="col-12 col-md-6 overflow-auto">
{{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
</div>

<div class="col-12 col-md-6 text-center text-md-right text-muted">
@if($this->showPaginationDetails())
<div @class([
"col-12 col-md-6 text-center text-muted",
"text-md-right" => $this->isBootstrap4,
"text-md-end" => $this->isBootstrap5,
])>
@if($this->showPaginationDetails)
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }}</strong>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }}</strong>
@endif
</div>
</div>
@elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('cursor'))
@elseif ($this->paginationIsEnabled && $this->isPaginationMethod('cursor'))
<div class="row mt-3">
<div class="col-12 col-md-6 overflow-auto">
{{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
Expand All @@ -93,66 +93,17 @@
@else
<div class="row mt-3">
<div class="col-12 text-muted">
{{ __($this->getLocalisationPath.'Showing') }}
<strong>{{ $this->getRows->count() }}</strong>
{{ __($this->getLocalisationPath.'results') }}
</div>
</div>
@endif
@endif
</div>
@elseif ($this->isBootstrap5)
<div {{ $this->getPaginationWrapperAttributesBag() }} >
@if ($this->paginationVisibilityIsEnabled())
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
<div class="row mt-3">
<div class="col-12 col-md-6 overflow-auto">
{{ $this->getRows->links('livewire-tables::specific.bootstrap-4.pagination') }}
</div>
<div class="col-12 col-md-6 text-center text-md-end text-muted">
@if($this->showPaginationDetails())
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }}</strong>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }}</strong>
<span>{{ __($this->getLocalisationPath.'of') }}</span>
<strong><span x-text="paginationTotalItemCount"></span></strong>
<span>{{ __($this->getLocalisationPath.'results') }}</span>
@endif
</div>
</div>
@elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('simple'))
<div class="row mt-3">
<div class="col-12 col-md-6 overflow-auto">
{{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
</div>
<div class="col-12 col-md-6 text-center text-md-end text-muted">
@if($this->showPaginationDetails())
<span>{{ __($this->getLocalisationPath.'Showing') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }}</strong>
<span>{{ __($this->getLocalisationPath.'to') }}</span>
<strong>{{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }}</strong>
@if($this->showPaginationDetails)
{{ __($this->getLocalisationPath.'Showing') }}
<strong>{{ $this->getRows->count() }}</strong>
{{ __($this->getLocalisationPath.'results') }}
@endif
</div>
</div>
@elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('cursor'))
<div class="row mt-3">
<div class="col-12 col-md-6 overflow-auto">
{{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
</div>
</div>
@else
<div class="row mt-3">
<div class="col-12 text-muted">
{{ __($this->getLocalisationPath.'Showing') }}
<strong>{{ $this->getRows->count() }}</strong>
{{ __($this->getLocalisationPath.'results') }}
</div>
</div>
@endif
@endif
</div>
@endif
@endif
</div>

@includeWhen(
$this->hasConfigurableAreaFor('after-pagination'),
Expand Down
6 changes: 4 additions & 2 deletions src/Traits/Helpers/PaginationHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function getPaginationTheme(): string
{
return $this->paginationTheme;
}


#[Computed]
public function paginationIsEnabled(): bool
{
return $this->getPaginationStatus() === true;
Expand Down Expand Up @@ -117,7 +118,8 @@ public function getPerPageDisplayedItemCount(): int
{
return $this->paginationCurrentCount;
}


#[Computed]
public function showPaginationDetails(): bool
{
return $this->shouldShowPaginationDetails === true;
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Traits/Visuals/PaginationVisualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function test_detailed_pagination_is_displayed_standard_bs4(): void
Livewire::test(PetsTable::class)
->call('setTheme', 'bootstrap-4')
->call('enableDetailedPagination', 'standard')
->assertSeeHtmlInOrder(['<div class="col-12 col-md-6 text-center text-md-right text-muted">',
->assertSeeHtmlInOrder(['<div class="col-12 col-md-6 text-center text-muted text-md-right">',
'<span>Showing</span>',
'<strong>1</strong>',
'<span>to</span>',
Expand Down Expand Up @@ -231,7 +231,7 @@ public function test_detailed_pagination_is_displayed_standard_bs5(): void
Livewire::test(PetsTable::class)
->call('setTheme', 'bootstrap-5')
->call('enableDetailedPagination', 'standard')
->assertSeeHtmlInOrder(['<div class="col-12 col-md-6 text-center text-md-end text-muted">',
->assertSeeHtmlInOrder(['<div class="col-12 col-md-6 text-center text-muted text-md-end">',
'<span>Showing</span>',
'<strong>1</strong>',
'<span>to</span>',
Expand All @@ -244,7 +244,7 @@ public function test_detailed_pagination_is_displayed_simple_bs5(): void
Livewire::test(PetsTable::class)
->call('setTheme', 'bootstrap-5')
->call('enableDetailedPagination', 'simple')
->assertSeeHtmlInOrder(['<div class="col-12 col-md-6 text-center text-md-end text-muted">',
->assertSeeHtmlInOrder(['<div class="col-12 col-md-6 text-center text-muted text-md-end">',
'<span>Showing</span>',
'<strong>1</strong>',
'<span>to</span>',
Expand Down

0 comments on commit 3ec04fc

Please sign in to comment.