Skip to content

Commit

Permalink
Merge pull request #1672 from rappasoft/develop
Browse files Browse the repository at this point in the history
v3.2.2 Release
  • Loading branch information
lrljoe authored Feb 29, 2024
2 parents d49c0c7 + bc3d2f3 commit d07354a
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## [v3.2.2] - 2024-02-29
### New Features
- Add setDefaultPerPage by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1671

## [v3.2.1] - 2024-02-24
### Bug Fixes
- Fix collapsing columns not respecting view point collapse points by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1665
Expand Down
13 changes: 12 additions & 1 deletion docs/pagination/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function configure(): void

## setPerPage

Set the default selected option of the per page dropdown.
Set the selected option of the per page dropdown.

```php
public function configure(): void
Expand All @@ -158,6 +158,17 @@ public function configure(): void
}
```

## setDefaultPerPage

Set the default selected option of the per-page dropdown, will be over-ridden if set at Session or QueryString level.

```php
public function configure(): void
{
$this->setDefaultPerPage(10);
}
```

**Note:** The value set must be included in the `per page accepted` values.

## setPaginationMethod
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelLivewireTablesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LaravelLivewireTablesServiceProvider extends ServiceProvider
public function boot(): void
{

AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.1']);
AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.2']);

$this->mergeConfigFrom(
__DIR__.'/../config/livewire-tables.php', 'livewire-tables'
Expand Down
14 changes: 14 additions & 0 deletions src/Traits/Configuration/PaginationConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,18 @@ public function setDisplayPaginationDetailsDisabled(): self

return $this;
}

/**
* Set a default per-page value (if not set already by session or querystring)
*/
public function setDefaultPerPage(int $perPage): self
{
$defaultPerPage = $perPage;

if ($this->perPage == 10) {
$this->setPerPage($perPage);
}

return $this;
}
}
150 changes: 150 additions & 0 deletions tests/Http/Livewire/PetsTableUnpaginated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire;

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateTimeFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectDropdownFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\NumberFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;

class PetsTableUnpaginated extends DataTableComponent
{
public $model = Pet::class;

public string $paginationTest = 'standard';

public function configure(): void
{
$this->setPrimaryKey('id');
}

public function columns(): array
{
return [
Column::make('ID', 'id')
->sortable()
->setSortingPillTitle('Key')
->setSortingPillDirections('0-9', '9-0'),
Column::make('Sort')
->sortable()
->excludeFromColumnSelect(),
Column::make('Name')
->sortable()
->secondaryHeader($this->getFilterByKey('pet_name_filter'))
->footerFilter('pet_name_filter')
->searchable(),

Column::make('Age'),

Column::make('Breed', 'breed.name')
->secondaryHeaderFilter('breed')
->footer($this->getFilterByKey('breed'))
->sortable(
fn (Builder $query, string $direction) => $query->orderBy('pets.id', $direction)
)
->searchable(
fn (Builder $query, $searchTerm) => $query->orWhere('breed.name', $searchTerm)
),

Column::make('Other')
->label(function ($row, Column $column) {
return 'Other';
})
->footer(function ($rows) {
return 'Count: '.$rows->count();
}),

LinkColumn::make('Link')
->title(fn ($row) => 'Edit')
->location(fn ($row) => 'http://www.google.com')
->attributes(fn ($row) => [
'class' => 'rounded-full',
'alt' => $row->name.' Avatar',
]),
ImageColumn::make('RowImg')
->location(fn ($row) => 'test'.$row->id)
->attributes(fn ($row) => [
'class' => 'rounded-full',
'alt' => $row->name.' Avatar',
]),
Column::make('Last Visit', 'last_visit')
->sortable()
->deselected(),
];
}

public function filters(): array
{
return [
MultiSelectFilter::make('Breed')
->options(
Breed::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($breed) => $breed->name)
->toArray()
)
->filter(function (Builder $builder, array $values) {
return $builder->whereIn('breed_id', $values);
}),
MultiSelectDropdownFilter::make('Species')
->options(
Species::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($species) => $species->name)
->toArray()
)
->filter(function (Builder $builder, array $values) {
return $builder->whereIn('species_id', $values);
}),
NumberFilter::make('Breed ID', 'breed_id_filter')
->filter(function (Builder $builder, string $value) {
return $builder->where('breed_id', '=', $value);
}),

TextFilter::make('Pet Name', 'pet_name_filter')
->filter(function (Builder $builder, string $value) {
return $builder->where('pets.name', '=', $value);
}),

DateFilter::make('Last Visit After Date', 'last_visit_date_filter')
->filter(function (Builder $builder, string $value) {
return $builder->whereDate('pets.last_visit', '=>', $value);
}),

DateTimeFilter::make('Last Visit Before DateTime', 'last_visit_datetime_filter')
->filter(function (Builder $builder, string $value) {
return $builder->whereDate('pets.last_visit', '<=', $value);
}),

SelectFilter::make('Breed SelectFilter', 'breed_select_filter')
->options(
Breed::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($breed) => $breed->name)
->toArray()
)
->filter(function (Builder $builder, string $value) {
return $builder->where('breed_id', $value);
})
->setCustomFilterLabel('livewire-tables::tests.testFilterLabel')
->setFilterPillBlade('livewire-tables::tests.testFilterPills'),
];
}
}
24 changes: 23 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Livewire\LivewireServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;
use Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\{PetsTable,PetsTableUnpaginated};
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
Expand All @@ -19,6 +19,8 @@ class TestCase extends Orchestra
{
public PetsTable $basicTable;

public PetsTableUnpaginated $unpaginatedTable;

/**
* Setup the test environment.
*/
Expand Down Expand Up @@ -73,6 +75,8 @@ protected function setUp(): void
]);
}
$this->setupBasicTable();
$this->setupUnpaginatedTable();

}

protected function setupBasicTable()
Expand All @@ -91,6 +95,24 @@ protected function setupBasicTable()
$this->basicTable->render();
}

protected function setupUnpaginatedTable()
{

$view = view('livewire-tables::datatable');
$this->unpaginatedTable = new PetsTableUnpaginated();
$this->unpaginatedTable->boot();
$this->unpaginatedTable->bootedComponentUtilities();
$this->unpaginatedTable->bootedWithData();
$this->unpaginatedTable->bootedWithColumns();
$this->unpaginatedTable->bootedWithColumnSelect();
$this->unpaginatedTable->bootedWithSecondaryHeader();
$this->unpaginatedTable->booted();
$this->unpaginatedTable->renderingWithData($view, []);
$this->unpaginatedTable->renderingWithPagination($view, []);
$this->unpaginatedTable->render();

}

protected function getPackageProviders($app): array
{
return [
Expand Down
10 changes: 10 additions & 0 deletions tests/Traits/Configuration/PaginationConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ public function can_set_per_page_manually(): void

$this->assertSame(25, $this->basicTable->getPerPage());
}

/** @test */
public function can_set_default_per_page(): void
{
$this->assertSame(10, $this->unpaginatedTable->getPerPage());
$this->unpaginatedTable->setDefaultPerPage(50);
$this->assertSame(50, $this->unpaginatedTable->getPerPage());
$this->unpaginatedTable->perPage = 25;
$this->assertSame(25, $this->unpaginatedTable->getPerPage());
}
}

0 comments on commit d07354a

Please sign in to comment.