Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 2749479

Browse files
authored
Refactor + docs (#59)
1 parent ebd88cd commit 2749479

31 files changed

+1041
-114
lines changed

app/app/Http/Controllers/TableController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ public function custom()
1919
]);
2020
}
2121

22+
public function noPerPage()
23+
{
24+
$users = User::query()->orderBy('name')->paginate(10);
25+
26+
SpladeTable::defaultPerPageOptions([10]);
27+
28+
return view('table.users', [
29+
'users' => SpladeTable::for($users)
30+
->column('name')
31+
->column('email')
32+
->column('actions'),
33+
]);
34+
}
35+
2236
public function rowLink()
2337
{
2438
$users = User::query()->orderBy('name')->paginate(10);

app/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
Route::prefix('table')->group(function () {
172172
$table = new UserTableView;
173173

174+
Route::get('/noPerPage', [TableController::class, 'noPerPage'])->name('table.noPerPage');
174175
Route::get('/custom', [TableController::class, 'custom'])->name('table.custom');
175176
Route::get('/rowLink', [TableController::class, 'rowLink'])->name('table.rowLink');
176177

app/tests/Browser/Table/PaginationTest.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88

99
class PaginationTest extends DuskTestCase
1010
{
11-
public function fullUrls()
12-
{
13-
return [
14-
['/table/users/eloquent'],
15-
];
16-
}
17-
1811
public function simpleUrls()
1912
{
2013
return [
@@ -23,18 +16,17 @@ public function simpleUrls()
2316
];
2417
}
2518

26-
/**
27-
* @test
28-
* @dataProvider fullUrls
29-
*/
30-
public function it_generates_a_paginator_with_links($url)
19+
/** @test */
20+
public function it_generates_a_paginator_with_links()
3121
{
32-
$this->browse(function (Browser $browser) use ($url) {
22+
$this->browse(function (Browser $browser) {
3323
$users = User::query()
3424
->select(['id', 'name'])
3525
->orderBy('name')
3626
->get();
3727

28+
$url = '/table/users/eloquent';
29+
3830
$browser
3931
->visit($url)
4032
->resize(1920, 1080)
@@ -86,6 +78,22 @@ public function it_generates_a_paginator_with_links($url)
8678
});
8779
}
8880

81+
/** @test */
82+
public function it_disabled_the_per_page_selection_on_less_than_two_options()
83+
{
84+
$this->browse(function (Browser $browser) {
85+
$users = User::query()
86+
->select(['id', 'name'])
87+
->orderBy('name')
88+
->get();
89+
90+
$browser->visit('/table/noPerPage')
91+
->resize(1920, 1080)
92+
->assertSeeIn('tr:first-child td:nth-child(1)', $users->get(0)->name)
93+
->assertMissing('select[name="per_page"]');
94+
});
95+
}
96+
8997
/**
9098
* @test
9199
* @dataProvider simpleUrls

resources/views/table/pagination.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</Link>
1111
@endif
1212

13-
@include('splade::table.per-page-selector')
13+
@includeWhen($hasPerPageOptions ?? true, 'splade::table.per-page-selector')
1414

1515
@if ($paginator->hasMorePages())
1616
<Link dusk="pagination-simple-next" href="{{ $paginator->nextPageUrl() }}" class="relative inline-flex items-center px-4 py-2 ml-3 text-xs sm:text-sm font-medium text-gray-700 bg-white border border-gray-300 leading-5 rounded-md hover:text-gray-500 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-700 transition ease-in-out duration-150">
@@ -25,9 +25,9 @@
2525

2626
<div class="hidden md:flex-1 md:flex md:items-center md:justify-between">
2727
<div class="flex items-center">
28-
@include('splade::table.per-page-selector')
28+
@includeWhen($hasPerPageOptions ?? true, 'splade::table.per-page-selector')
2929

30-
<div class="hidden lg:block ml-3">
30+
<div class="hidden lg:block @if($hasPerPageOptions ?? true) ml-3 @endif">
3131
<p class="text-xs sm:text-sm text-gray-700 leading-5">
3232
@if ($paginator->firstItem())
3333
<span class="font-medium">{{ $paginator->firstItem() }}</span>

resources/views/table/simple-pagination.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</Link>
1111
@endif
1212

13-
@include('splade::table.per-page-selector')
13+
@includeWhen($hasPerPageOptions ?? true, 'splade::table.per-page-selector')
1414

1515
{{-- Next Page Link --}}
1616
@if ($paginator->hasMorePages())

resources/views/table/table.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</x-splade-component>
3131

3232
@if($isPaginated())
33-
{{ $table->resource->links($paginationView, ['table' => $table]) }}
33+
{{ $table->resource->links($paginationView, ['table' => $table, 'hasPerPageOptions' => $hasPerPageOptions()]) }}
3434
@endif
3535
</div>
3636
</template>

src/Commands/PublishFormStylesheetsCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class PublishFormStylesheetsCommand extends Command
1111

1212
public $description = 'Publish the stylesheets for Choices.js and Flatpickr';
1313

14+
/**
15+
* Publishes the stylesheets for the Choices.js and
16+
* Flatpickr integrations into the app's resources/css folder.
17+
*
18+
* @return int
19+
*/
1420
public function handle(): int
1521
{
1622
(new Filesystem)->ensureDirectoryExists(resource_path('css'));

src/Commands/SpladeInstallCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class SpladeInstallCommand extends Command
1414

1515
public $description = 'Install the Splade components and resources';
1616

17+
/**
18+
* Installs the Splade Route Middleware, the Exception Handler, the
19+
* required NPM packages and copies all boilerplate files into
20+
* the application.
21+
*
22+
* @return int
23+
*/
1724
public function handle(): int
1825
{
1926
$this->installRouteMiddleware();
@@ -84,6 +91,11 @@ public static function eol(): string
8491
return windows_os() ? "\n" : PHP_EOL;
8592
}
8693

94+
/**
95+
* Adds the SSR build step to the 'build' command.
96+
*
97+
* @return void
98+
*/
8799
protected function updateNodeScript()
88100
{
89101
if (!file_exists(base_path('package.json'))) {
@@ -99,7 +111,7 @@ protected function updateNodeScript()
99111
}
100112

101113
/**
102-
* Update the "package.json" file.
114+
* Updates the "package.json" file.
103115
*
104116
* @param callable $callback
105117
* @param bool $dev

src/Commands/SsrTestCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class SsrTestCommand extends Command
1313

1414
public $description = 'Test the SSR server';
1515

16+
/**
17+
* Sends a request to the SSR servers and verifies that it rendered correctly.
18+
*
19+
* @return int
20+
*/
1621
public function handle(): int
1722
{
1823
$this->info('Testing SSR server: ' . config('splade.ssr.server'));

src/Components/Modal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function render()
2525
{
2626
return $this->splade->isModalRequest()
2727
? view(
28-
$this->splade->modalType() === SpladeCore::MODAL_TYPE_MODAL ? 'splade::modal' : 'splade::slideover',
28+
$this->splade->getModalType() === SpladeCore::MODAL_TYPE_MODAL ? 'splade::modal' : 'splade::slideover',
2929
[
3030
'closeButton' => $this->closeButton,
3131
'modalKey' => $this->splade->getModalKey(),

0 commit comments

Comments
 (0)