Skip to content

Commit 1d5f458

Browse files
committed
Changes
- Added bool to disable bulk actions completely - Removed reorder sorts to just use default sorts - Change reorder functionality to use sessions to determine if reordering or not - Added reorderEnabled and reordering bool - Added reorder/done reordering button - Don't set wire:sortable method unless reordering - Refactor everywhere to use new $bulkActionsEnabled - Refactor old $reorderRows to new $reordering on all themes - Fix colspan on empty - On row component, don't set wire:sortable.item unless reordering to prevent reordering when reordering is false - Null wire:sortable when not reordering
1 parent 8e8527d commit 1d5f458

File tree

12 files changed

+107
-29
lines changed

12 files changed

+107
-29
lines changed

resources/lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Bulk Actions": "Bulk Actions",
66
"Clear": "Clear",
77
"Columns": "Columns",
8+
"Done Reordering": "Done Reordering",
89
"Filters": "Filters",
910
"Remove filter option": "Remove filter option",
1011
"Remove sort option": "Remove sort option",
@@ -16,6 +17,7 @@
1617
"You are not connected to the internet.": "You are not connected to the internet.",
1718
"You have selected": "You have selected",
1819
"of": "of",
20+
"Reorder": "Reorder",
1921
"results": "results",
2022
"rows": "rows",
2123
"rows, do you want to select all": "rows, do you want to select all",

resources/views/bootstrap-4/includes/table.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<x-livewire-tables::bs4.table wire:sortable="{{ $reorderRows }}">
1+
<x-livewire-tables::bs4.table wire:sortable="{{ $reorderingMethod }}">
22
<x-slot name="head">
3-
@if (is_string($reorderRows))
3+
@if ($reordering)
44
<x-livewire-tables::bs4.table.heading />
55
@endif
66

@@ -37,7 +37,7 @@
3737
@php
3838
$colspan = count($columns);
3939
if (count($bulkActions)) $colspan++;
40-
if (is_string($reorderRows)) $colspan++;
40+
if ($reordering) $colspan++;
4141
@endphp
4242

4343
@include('livewire-tables::bootstrap-4.includes.bulk-select-row')
@@ -52,7 +52,7 @@
5252
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
5353
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
5454
>
55-
@if (is_string($reorderRows))
55+
@if ($reordering)
5656
<x-livewire-tables::bs4.table.cell wire:sortable.handle>
5757
<svg xmlns="http://www.w3.org/2000/svg" style="width:1em;height:1em;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
5858
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />

resources/views/bootstrap-5/includes/table.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<x-livewire-tables::bs5.table wire:sortable="{{ $reorderRows }}">
1+
<x-livewire-tables::bs5.table wire:sortable="{{ $reorderingMethod }}">
22
<x-slot name="head">
3-
@if (is_string($reorderRows))
3+
@if ($reordering)
44
<x-livewire-tables::bs5.table.heading />
55
@endif
66

@@ -38,7 +38,7 @@ class="form-check-input"
3838
@php
3939
$colspan = count($columns);
4040
if (count($bulkActions)) $colspan++;
41-
if (is_string($reorderRows)) $colspan++;
41+
if ($reordering) $colspan++;
4242
@endphp
4343

4444
@include('livewire-tables::bootstrap-5.includes.bulk-select-row')
@@ -53,7 +53,7 @@ class="form-check-input"
5353
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
5454
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
5555
>
56-
@if (is_string($reorderRows))
56+
@if ($reordering)
5757
<x-livewire-tables::bs5.table.cell wire:sortable.handle>
5858
<svg xmlns="http://www.w3.org/2000/svg" style="width:1em;height:1em;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
5959
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />

resources/views/tailwind/components/table/row.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
@props(['url' => null, 'customAttributes' => []])
1+
@props(['url' => null, 'reordering' => false, 'customAttributes' => []])
2+
3+
@if (!$reordering && $attributes->has('wire:sortable.item'))
4+
@php
5+
$attributes = $attributes->filter(fn ($value, $key) => $key !== 'wire:sortable.item');
6+
@endphp
7+
@endif
28

39
<tr
410
{{ $attributes->merge($customAttributes) }}

resources/views/tailwind/datatable.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<div class="space-y-4">
2222
<div class="md:flex md:justify-between p-6 md:p-0">
2323
<div class="w-full mb-4 md:mb-0 md:w-2/4 md:flex space-y-4 md:space-y-0 md:space-x-4">
24+
@include('livewire-tables::tailwind.includes.reorder')
2425
@include('livewire-tables::tailwind.includes.search')
2526
@include('livewire-tables::tailwind.includes.filters')
2627
</div>

resources/views/tailwind/includes/bulk-actions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if (count($bulkActions))
1+
@if ($bulkActionsEnabled && count($bulkActions))
22
<div class="w-full md:w-auto mb-4 md:mb-0">
33
<div
44
x-data="{ open: false }"

resources/views/tailwind/includes/bulk-select-row.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if (count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
1+
@if ($bulkActionsEnabled && count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
22
<x-livewire-tables::table.row wire:key="row-message" class="bg-indigo-50">
33
<x-livewire-tables::table.cell :colspan="$colspan">
44
@if (count($selected) && !$selectAll && !$selectPage)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@if ($reorderEnabled)
2+
<button
3+
wire:click="{{ $reordering ? 'disableReordering' : 'enableReordering' }}"
4+
type="button"
5+
class="inline-flex justify-center items-center w-full md:w-auto px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:text-gray-500 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo active:bg-gray-50 active:text-gray-800 transition ease-in-out duration-150"
6+
>
7+
@if ($reordering)
8+
@lang('Done Reordering')
9+
@else
10+
@lang('Reorder')
11+
@endif
12+
</button>
13+
@endif

resources/views/tailwind/includes/table.blade.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<x-livewire-tables::table wire:sortable="{{ $reorderRows }}">
1+
<x-livewire-tables::table wire:sortable="{{ $reordering ? $reorderingMethod : '' }}">
22
<x-slot name="head">
3-
@if (is_string($reorderRows))
3+
@if ($reordering)
44
<x-livewire-tables::table.heading />
55
@endif
66

7-
@if (count($bulkActions))
7+
@if ($bulkActionsEnabled && count($bulkActions))
88
<x-livewire-tables::table.heading>
99
<div class="inline-flex rounded-md shadow-sm">
1010
<input
@@ -39,8 +39,8 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
3939
<x-slot name="body">
4040
@php
4141
$colspan = count($columns);
42-
if (count($bulkActions)) $colspan++;
43-
if (is_string($reorderRows)) $colspan++;
42+
if ($bulkActionsEnabled && count($bulkActions)) $colspan++;
43+
if ($reordering) $colspan++;
4444
@endphp
4545

4646
@include('livewire-tables::tailwind.includes.bulk-select-row')
@@ -50,6 +50,7 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
5050
wire:loading.class.delay="opacity-50"
5151
wire:key="table-row-{{ $row->{$primaryKey} }}"
5252
wire:sortable.item="{{ $row->{$primaryKey} }}"
53+
:reordering="$reordering"
5354
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
5455
:class="
5556
($index % 2 === 0 ?
@@ -61,15 +62,15 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
6162
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
6263
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
6364
>
64-
@if (is_string($reorderRows))
65+
@if ($reordering)
6566
<x-livewire-tables::table.cell wire:sortable.handle>
66-
<svg xmlns="http://www.w3.org/2000/svg" style="width:1em;height:1em;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
67+
<svg xmlns="http://www.w3.org/2000/svg" class="inline" style="width:1em;height:1em;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
6768
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
6869
</svg>
6970
</x-livewire-tables::table.cell>
7071
@endif
7172

72-
@if (count($bulkActions))
73+
@if ($bulkActionsEnabled && count($bulkActions))
7374
<x-livewire-tables::table.cell>
7475
<div class="inline-flex rounded-md shadow-sm">
7576
<input
@@ -88,7 +89,7 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
8889
</x-livewire-tables::table.row>
8990
@empty
9091
<x-livewire-tables::table.row>
91-
<x-livewire-tables::table.cell :colspan="count($bulkActions) ? count($columns) + 1 : count($columns)">
92+
<x-livewire-tables::table.cell :colspan="$colspan">
9293
<div class="flex justify-center items-center space-x-2">
9394
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
9495
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4" />

src/Traits/WithBulkActions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
trait WithBulkActions
1212
{
13+
public bool $bulkActionsEnabled = true;
1314
public string $primaryKey = 'id';
1415
public bool $selectPage = false;
1516
public bool $selectAll = false;
@@ -18,6 +19,10 @@ trait WithBulkActions
1819

1920
public function renderingWithBulkActions(): void
2021
{
22+
if (! $this->bulkActionsEnabled) {
23+
return;
24+
}
25+
2126
if ($this->selectAll) {
2227
$this->selectPageRows();
2328
}

0 commit comments

Comments
 (0)