Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.2 #104

Merged
merged 4 commits into from
Oct 8, 2022
Merged

5.0.2 #104

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
WIP
  • Loading branch information
Arthur LORENT committed Oct 7, 2022
commit 7ec1e38ca25e534c169e4fecbe451a8712261a57
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [5.0.2](https://github.com/Okipa/laravel-table/compare/5.0.1...5.0.2)

2022-10-07

* Fixed wrong `form-select` class uses for Bootstrap 4 template selects: replaced them by `custom-select`

## [5.0.1](https://github.com/Okipa/laravel-table/compare/5.0.0...5.0.1)

2022-09-26
Expand Down
2 changes: 1 addition & 1 deletion resources/views/bootstrap-4/filter.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div wire:key="{{ Str::of($filter->identifier)->snake('-')->slug() }}" class="ml-3 mt-2">
<select wire:model="selectedFilters.{{ $filter->identifier }}" {{ $attributes->class(['form-select', ...$class]) }}>
<select wire:model="selectedFilters.{{ $filter->identifier }}" {{ $attributes->class(['custom-select', ...$class]) }}>
<option wire:key="{{ Str::of($filter->identifier)->snake('-')->slug() }}-option-placeholder" value="" selected{!! $multiple ? ' disabled' : null !!}>{{ $label }}</option>
@foreach($options as $optionValue => $optionLabel)
<option wire:key="{{ Str::of($filter->identifier)->snake('-')->slug() }}-option-{{ Str::of($optionValue)->snake('-')->slug() }}" value="{{ $optionValue }}">{{ $optionLabel }}</option>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/bootstrap-4/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class="btn btn-sm btn-link text-secondary p-0"
{!! config('laravel-table.icon.rows_number') !!}
</span>
</div>
<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="form-select" {!! (new \Illuminate\View\ComponentAttributeBag())->merge([
<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="custom-select" {!! (new \Illuminate\View\ComponentAttributeBag())->merge([
'placeholder' => __('Number of rows per page'),
'aria-label' => __('Number of rows per page'),
'aria-describedby' => 'rows-number-per-page-icon',
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Bootstrap4/TableFiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function columns(): array
'<div wire:ignore>',
'<div wire:key="filter-value-email" class="ml-3 mt-2">',
'<select wire:model="selectedFilters.filter_value_email"',
' class="form-select"',
' class="custom-select"',
' placeholder="Email"',
' aria-label="Email">',
'<option wire:key="filter-value-email-option-placeholder" value="" selected disabled>Email</option>',
Expand All @@ -86,7 +86,7 @@ protected function columns(): array
'<div wire:ignore>',
'<div wire:key="filter-null-email-verified-at" class="ml-3 mt-2">',
'<select wire:model="selectedFilters.filter_null_email_verified_at"',
' class="form-select"',
' class="custom-select"',
' placeholder="Email Verified"',
' aria-label="Email Verified">',
'<option wire:key="filter-null-email-verified-at-option-placeholder" value="" selected>Email Verified</option>',
Expand All @@ -99,7 +99,7 @@ protected function columns(): array
'<div wire:ignore>',
'<div wire:key="filter-relationship-companies" class="ml-3 mt-2">',
'<select wire:model="selectedFilters.filter_relationship_companies"',
' class="form-select"',
' class="custom-select"',
' placeholder="Companies"',
' aria-label="Companies">',
'<option wire:key="filter-relationship-companies-option-placeholder" value="" selected>Companies</option>',
Expand All @@ -119,7 +119,7 @@ protected function columns(): array
'<div wire:ignore>',
'<div wire:key="filter-relationship-categories" class="ml-3 mt-2">',
'<select wire:model="selectedFilters.filter_relationship_categories"',
' class="form-select"',
' class="custom-select"',
' placeholder="Categories"',
' aria-label="Categories">',
'<option wire:key="filter-relationship-categories-option-placeholder" value="" selected disabled>Categories</option>',
Expand All @@ -139,7 +139,7 @@ protected function columns(): array
'<div wire:ignore>',
'<div wire:key="filter-boolean-active" class="ml-3 mt-2">',
'<select wire:model="selectedFilters.filter_boolean_active"',
' class="form-select"',
' class="custom-select"',
' placeholder="Active"',
' aria-label="Active">',
'<option wire:key="filter-boolean-active-option-placeholder" value="" selected>Active</option>',
Expand Down Expand Up @@ -362,7 +362,7 @@ protected function columns(): array
'<div wire:ignore>',
'<div wire:key="filter-boolean-active" class="ml-3 mt-2">',
'<select wire:model="selectedFilters.filter_boolean_active"',
' class="form-select"',
' class="custom-select"',
' placeholder="Active"',
' aria-label="Active"',
' data-selector="data-selector">',
Expand Down
197 changes: 196 additions & 1 deletion tests/Unit/Bootstrap4/TableNumberOfRowsPerPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function columns(): array
'rows-number-icon',
'</span>',
'</div>',
'<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="form-select" placeholder="Number of rows per page" aria-label="Number of rows per page" aria-describedby="rows-number-per-page-icon">',
'<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="custom-select" placeholder="Number of rows per page" aria-label="Number of rows per page" aria-describedby="rows-number-per-page-icon">',
'<option wire:key="rows-number-per-page-option-placeholder" value="" disabled>Number of rows per page</option>',
'<option wire:key="rows-number-per-page-option-1" value="1" selected>',
'1',
Expand All @@ -66,4 +66,199 @@ protected function columns(): array
'</thead>',
]);
}

/** @test */
public function it_can_set_specific_number_of_rows_per_page_options_from_table(): void
{
Config::set('laravel-table.enable_number_of_rows_per_page_choice', true);
Config::set('laravel-table.icon.rows_number', 'rows-number-icon');
Config::set('laravel-table.number_of_rows_per_page_default_options', [10, 25, 50, 75, 100]);
$config = new class extends AbstractTableConfiguration
{
protected function table(): Table
{
return Table::make()->model(User::class)->numberOfRowsPerPageOptions([1, 2, 3, 4, 5]);
}

protected function columns(): array
{
return [
Column::make('id'),
];
}
};
Livewire::test(\Okipa\LaravelTable\Livewire\Table::class, ['config' => $config::class])
->call('init')
->assertSet('numberOfRowsPerPage', 1)
->assertSeeHtmlInOrder([
'<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="custom-select" placeholder="Number of rows per page" aria-label="Number of rows per page" aria-describedby="rows-number-per-page-icon">',
'<option wire:key="rows-number-per-page-option-placeholder" value="" disabled>Number of rows per page</option>',
'<option wire:key="rows-number-per-page-option-1" value="1" selected>',
'1',
'</option>',
'<option wire:key="rows-number-per-page-option-2" value="2">',
'2',
'</option>',
'<option wire:key="rows-number-per-page-option-3" value="3">',
'3',
'</option>',
'<option wire:key="rows-number-per-page-option-4" value="4">',
'4',
'</option>',
'<option wire:key="rows-number-per-page-option-5" value="5">',
'5',
'</option>',
'</select>',
]);
}

/** @test */
public function it_can_set_default_number_of_rows_from_first_option(): void
{
Config::set('laravel-table.enable_number_of_rows_per_page_choice', true);
Config::set('laravel-table.icon.rows_number', 'rows-number-icon');
Config::set('laravel-table.number_of_rows_per_page_default_options', [1, 2, 3, 4, 5]);
$users = User::factory()->count(5)->create();
$config = new class extends AbstractTableConfiguration
{
protected function table(): Table
{
return Table::make()->model(User::class);
}

protected function columns(): array
{
return [
Column::make('id'),
];
}
};
$displayedHtml = [];
$notDisplayedHtml = [];
foreach ($users as $user) {
if ($user->id === $users->first()->id) {
$displayedHtml[] = '<th wire:key="cell-id-' . $user->id . '" class="align-middle" scope="row">';
$displayedHtml[] = $user->id;
$displayedHtml[] = '</th>';
} else {
$notDisplayedHtml[] = '<th wire:key="cell-id-' . $user->id . '" class="align-middle" scope="row">';
}
}
Livewire::test(\Okipa\LaravelTable\Livewire\Table::class, ['config' => $config::class])
->call('init')
->assertSet('numberOfRowsPerPage', 1)
->assertSeeHtmlInOrder([
'<thead>',
'<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="custom-select" placeholder="Number of rows per page" aria-label="Number of rows per page" aria-describedby="rows-number-per-page-icon">',
'<option wire:key="rows-number-per-page-option-placeholder" value="" disabled>Number of rows per page</option>',
'<option wire:key="rows-number-per-page-option-1" value="1" selected>',
'1',
'</option>',
'<option wire:key="rows-number-per-page-option-2" value="2">',
'2',
'</option>',
'<option wire:key="rows-number-per-page-option-3" value="3">',
'3',
'</option>',
'<option wire:key="rows-number-per-page-option-4" value="4">',
'4',
'</option>',
'<option wire:key="rows-number-per-page-option-5" value="5">',
'5',
'</option>',
'</select>',
'</thead>',
'<tbody',
...$displayedHtml,
'</tbody',
])
->assertDontSeeHtml($notDisplayedHtml);
}

/** @test */
public function it_can_change_number_of_rows_per_page_from_select(): void
{
Config::set('laravel-table.enable_number_of_rows_per_page_choice', true);
Config::set('laravel-table.icon.rows_number', 'rows-number-icon');
Config::set('laravel-table.number_of_rows_per_page_default_options', [1, 2, 3, 4, 5]);
$users = User::factory()->count(5)->create();
$config = new class extends AbstractTableConfiguration
{
protected function table(): Table
{
return Table::make()->model(User::class);
}

protected function columns(): array
{
return [
Column::make('id'),
];
}
};
$values = [];
foreach ($users as $user) {
$values[] = '<th wire:key="cell-id-' . $user->id . '" class="align-middle" scope="row">';
$values[] = $user->id;
$values[] = '</th>';
}
Livewire::test(\Okipa\LaravelTable\Livewire\Table::class, ['config' => $config::class])
->call('init')
->call('changeNumberOfRowsPerPage', 5)
->assertSet('numberOfRowsPerPage', 5)
->assertSeeHtmlInOrder([
'<thead>',
'<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="custom-select" placeholder="Number of rows per page" aria-label="Number of rows per page" aria-describedby="rows-number-per-page-icon">',
'<option wire:key="rows-number-per-page-option-placeholder" value="" disabled>Number of rows per page</option>',
'<option wire:key="rows-number-per-page-option-1" value="1">',
'1',
'</option>',
'<option wire:key="rows-number-per-page-option-2" value="2">',
'2',
'</option>',
'<option wire:key="rows-number-per-page-option-3" value="3">',
'3',
'</option>',
'<option wire:key="rows-number-per-page-option-4" value="4">',
'4',
'</option>',
'<option wire:key="rows-number-per-page-option-5" value="5" selected>',
'5',
'</option>',
'</select>',
'</thead>',
'<tbody',
...$values,
'</tbody',
]);
}

/** @test */
public function it_can_set_data_attribute_on_number_of_rows_per_page_selector(): void
{
Config::set('laravel-table.html_select_components_attributes', ['data-selector' => true]);
Config::set('laravel-table.icon.rows_number', 'rows-number-icon');
User::factory()->create();
$config = new class extends AbstractTableConfiguration
{
protected function table(): Table
{
return Table::make()->model(User::class);
}

protected function columns(): array
{
return [
Column::make('id'),
];
}
};
Livewire::test(\Okipa\LaravelTable\Livewire\Table::class, ['config' => $config::class])
->call('init')
->assertSeeHtmlInOrder([
'<thead>',
'<select wire:change="changeNumberOfRowsPerPage($event.target.value)" class="custom-select" placeholder="Number of rows per page" aria-label="Number of rows per page" aria-describedby="rows-number-per-page-icon" data-selector="data-selector">',
'</thead>',
]);
}
}