Skip to content

Commit

Permalink
5.0.2 (#104)
Browse files Browse the repository at this point in the history
* Fixed wrong `form-select` class uses for Bootstrap 4 template selects: replaced them by `custom-select`
* Fixed Column action still displays original column value with ->when(false) : #103
  • Loading branch information
Okipa committed Oct 8, 2022
1 parent af3f086 commit b2807c5
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 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`
* Fixed Column action still displays original column value with ->when(false) : #103

## [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
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -196,11 +196,11 @@ class="d-flex align-items-center"
{{-- Row columns values --}}
@foreach($columns as $column)
@if($loop->first)
<th wire:key="cell-{{ $column->getAttribute() }}-{{ $model->getKey() }}"{!! $orderColumn ? ' wire:sortable.handle style="cursor: move;"' : null !!} class="align-middle" scope="row">
<th wire:key="cell-{{ Str::of($column->getAttribute())->snake('-')->slug() }}-{{ $model->getKey() }}"{!! $orderColumn ? ' wire:sortable.handle style="cursor: move;"' : null !!} class="align-middle" scope="row">
{!! $orderColumn ? '<span class="mr-2">' . config('laravel-table.icon.drag_drop') . '</span>' : null !!}{{ $column->getValue($model, $tableColumnActionsArray) }}
</th>
@else
<td wire:key="cell-{{ $column->getAttribute() }}-{{ $model->getKey() }}" class="align-middle">
<td wire:key="cell-{{ Str::of($column->getAttribute())->snake('-')->slug() }}-{{ $model->getKey() }}" class="align-middle">
{{ $column->getValue($model, $tableColumnActionsArray) }}
</td>
@endif
Expand Down
4 changes: 2 additions & 2 deletions resources/views/bootstrap-5/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ class="d-flex align-items-center"
{{-- Row columns values --}}
@foreach($columns as $column)
@if($loop->first)
<th wire:key="cell-{{ $column->getAttribute() }}-{{ $model->getKey() }}"{!! $orderColumn ? ' wire:sortable.handle style="cursor: move;"' : null !!} class="align-middle" scope="row">
<th wire:key="cell-{{ Str::of($column->getAttribute())->snake('-')->slug() }}-{{ $model->getKey() }}"{!! $orderColumn ? ' wire:sortable.handle style="cursor: move;"' : null !!} class="align-middle" scope="row">
{!! $orderColumn ? '<span class="me-2">' . config('laravel-table.icon.drag_drop') . '</span>' : null !!}{{ $column->getValue($model, $tableColumnActionsArray) }}
</th>
@else
<td wire:key="cell-{{ $column->getAttribute() }}-{{ $model->getKey() }}" class="align-middle">
<td wire:key="cell-{{ Str::of($column->getAttribute())->snake('-')->slug() }}-{{ $model->getKey() }}" class="align-middle">
{{ $column->getValue($model, $tableColumnActionsArray) }}
</td>
@endif
Expand Down
6 changes: 6 additions & 0 deletions src/Livewire/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ public function rowAction(string $identifier, string $modelKey, bool $requiresCo
}
$rowActionArray = collect($rowActionsArray)->where('identifier', $identifier)->first();
$rowActionInstance = AbstractRowAction::make($rowActionArray);
if (! $rowActionInstance->isAllowed()) {
return null;
}
$model = app($rowActionArray['modelClass'])->findOrFail($modelKey);
if ($requiresConfirmation) {
return $this->emit(
Expand All @@ -322,6 +325,9 @@ public function columnAction(string $identifier, string $modelKey, bool $require
return null;
}
$columnActionInstance = AbstractColumnAction::make($columnActionArray);
if (! $columnActionInstance->isAllowed()) {
return null;
}
$model = app($columnActionArray['modelClass'])->findOrFail($modelKey);
if ($requiresConfirmation) {
return $this->emit(
Expand Down
3 changes: 0 additions & 3 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,6 @@ public function generateColumnActionsArray(): array
->filter();
foreach ($columnActions as $attribute => $columnAction) {
$columnAction->setup($model, $attribute);
if (! $columnAction->isAllowed()) {
continue;
}
$tableColumnActionsArray[] = json_decode(json_encode(
$columnAction,
JSON_THROW_ON_ERROR
Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/Bootstrap4/ColumnActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ protected function columns(): array
->assertSeeHtmlInOrder([
'<tbody>',
'<tr wire:key="row-' . $users->first()->id . '" class="border-bottom">',
'<th wire:key="cell-name-' . $users->first()->id . '" class="align-middle" scope="row">',
$users->first()->name,
'</th>',
'<td wire:key="cell-email-verified-at-' . $users->first()->id . '" class="align-middle">',
'<a wire:key="column-action-email-verified-at-' . $users->first()->id . '"',
' wire:click.prevent="columnAction(\'email_verified_at\', \'' . $users->first()->id . '\', 1)"',
' class="link-success p-1"',
Expand All @@ -58,6 +62,8 @@ protected function columns(): array
' data-toggle="tooltip">',
'email-verified-icon',
'</a>',
'</td>',
'<td wire:key="cell-active-' . $users->first()->id . '" class="align-middle">',
'<a wire:key="column-action-active-' . $users->first()->id . '"',
' wire:click.prevent="columnAction(\'active\', \'' . $users->first()->id . '\', 0)"',
' class="link-success p-1"',
Expand All @@ -66,8 +72,13 @@ protected function columns(): array
' data-toggle="tooltip">',
'toggle-on-icon',
'</a>',
'</td>',
'</tr>',
'<tr wire:key="row-' . $users->last()->id . '" class="border-bottom">',
'<th wire:key="cell-name-' . $users->last()->id . '" class="align-middle" scope="row">',
$users->last()->name,
'</th>',
'<td wire:key="cell-email-verified-at-' . $users->last()->id . '" class="align-middle">',
'<a wire:key="column-action-email-verified-at-' . $users->last()->id . '"',
' wire:click.prevent="columnAction(\'email_verified_at\', \'' . $users->last()->id . '\', 1)"',
' class="link-danger p-1"',
Expand All @@ -76,6 +87,8 @@ protected function columns(): array
' data-toggle="tooltip">',
'email-unverified-icon',
'</a>',
'</td>',
'<td wire:key="cell-active-' . $users->last()->id . '" class="align-middle">',
'<a wire:key="column-action-active-' . $users->last()->id . '"',
' wire:click.prevent="columnAction(\'active\', \'' . $users->last()->id . '\', 0)"',
' class="link-danger p-1"',
Expand All @@ -84,6 +97,7 @@ protected function columns(): array
' data-toggle="tooltip">',
'toggle-off-icon',
'</a>',
'</td>',
'</tr>',
'</tbody>',
])
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
Loading

0 comments on commit b2807c5

Please sign in to comment.