Skip to content

Commit 7df7c00

Browse files
authored
Merge pull request #370 from rappasoft/develop
v1.10.4
2 parents bcdf185 + df0cca0 commit 7df7c00

File tree

7 files changed

+53
-21
lines changed

7 files changed

+53
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [1.10.4] - 2021-06-23
8+
9+
### Added
10+
11+
- Added $hideBulkActionsOnEmpty to hide the bulk actions dropdown until something is selected.
12+
713
## [1.10.3] - 2021-06-22
814

915
### Added
@@ -408,7 +414,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
408414

409415
- Initial release
410416

411-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.3...development
417+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.4...development
418+
[1.10.4]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.3...v1.10.4
412419
[1.10.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.2...v1.10.3
413420
[1.10.2]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.1...v1.10.2
414421
[1.10.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.0...v1.10.1

resources/views/bootstrap-4/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 ($bulkActionsEnabled && count($bulkActions))
1+
@if ($this->showBulkActionsDropdown)
22
<div class="mb-3 mb-md-0">
33
<div class="dropdown d-block d-md-inline">
44
<button class="btn dropdown-toggle d-block w-100 d-md-inline" type="button" id="bulkActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

resources/views/bootstrap-5/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 ($bulkActionsEnabled && count($bulkActions))
1+
@if ($this->showBulkActionsDropdown)
22
<div class="mb-3 mb-md-0">
33
<div class="dropdown d-block d-md-inline">
44
<button class="btn dropdown-toggle d-block w-100 d-md-inline" type="button" id="bulkActions" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

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 ($bulkActionsEnabled && count($bulkActions))
1+
@if ($this->showBulkActionsDropdown)
22
<div class="w-full md:w-auto mb-4 md:mb-0">
33
<div
44
x-data="{ open: false }"

src/Traits/WithBulkActions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ trait WithBulkActions
1616
public bool $selectAll = false;
1717
public $selected = [];
1818
public array $bulkActions = [];
19+
public bool $hideBulkActionsOnEmpty = false;
1920

2021
public function renderingWithBulkActions(): void
2122
{
@@ -89,4 +90,25 @@ public function getSelectedKeysProperty(): array
8990
{
9091
return $this->selectedKeys();
9192
}
93+
94+
public function getShowBulkActionsDropdownProperty(): bool
95+
{
96+
$showBulkActions = false;
97+
98+
if ($this->bulkActionsEnabled) {
99+
if (count($this->bulkActions)) {
100+
$showBulkActions = true;
101+
}
102+
103+
if ($this->hideBulkActionsOnEmpty) {
104+
if (count($this->selected)) {
105+
$showBulkActions = true;
106+
} else {
107+
$showBulkActions = false;
108+
}
109+
}
110+
}
111+
112+
return $showBulkActions;
113+
}
92114
}

src/Traits/WithColumnSelect.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ trait WithColumnSelect
1515
public function mountWithColumnSelect(): void
1616
{
1717
// If the column select is off, make sure to clear the session
18-
if (! $this->columnSelect && session()->has($this->tableName.'-columnSelectEnabled')) {
19-
session()->forget($this->tableName.'-columnSelectEnabled');
18+
if (! $this->columnSelect && session()->has($this->getColumnSelectSessionKey())) {
19+
session()->forget($this->getColumnSelectSessionKey());
2020
}
2121

2222
// Get a list of visible default columns that are not excluded
@@ -27,24 +27,29 @@ public function mountWithColumnSelect(): void
2727
->toArray();
2828

2929
// Set to either the default set or what is stored in the session
30-
$this->columnSelectEnabled = session()->get($this->tableName.'-columnSelectEnabled', $columns);
30+
$this->columnSelectEnabled = session()->get($this->getColumnSelectSessionKey(), $columns);
3131

3232
// Check to see if there are any excluded that are already stored in the enabled and remove them
3333
foreach ($this->columns() as $column) {
3434
if (! $column->isSelectable() && ! in_array($column->column(), $this->columnSelectEnabled, true)) {
3535
$this->columnSelectEnabled[] = $column->column();
36-
session([$this->tableName.'-columnSelectEnabled' => $this->columnSelectEnabled]);
36+
session([$this->getColumnSelectSessionKey() => $this->columnSelectEnabled]);
3737
}
3838
}
3939
}
4040

4141
public function updatedColumnSelectEnabled(): void
4242
{
43-
session([$this->tableName.'-columnSelectEnabled' => $this->columnSelectEnabled]);
43+
session([$this->getColumnSelectSessionKey() => $this->columnSelectEnabled]);
4444
}
4545

4646
public function isColumnSelectEnabled($column): bool
4747
{
4848
return in_array($column instanceof Column ? $column->column() : $column, $this->columnSelectEnabled, true);
4949
}
50+
51+
private function getColumnSelectSessionKey(): string
52+
{
53+
return $this->tableName.'-columnSelectEnabled';
54+
}
5055
}

src/Traits/WithPerPagePagination.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,31 @@ public function mountWithPerPagePagination(): void
2020
$this->perPageAccepted[] = -1;
2121
}
2222

23-
if (in_array(session()->get($this->tableName.'-perPage', $this->perPage), $this->perPageAccepted, true)) {
24-
$this->perPage = session()->get($this->tableName.'-perPage', $this->perPage);
23+
if (in_array(session()->get($this->getPerPagePaginationSessionKey(), $this->perPage), $this->perPageAccepted, true)) {
24+
$this->perPage = session()->get($this->getPerPagePaginationSessionKey(), $this->perPage);
2525
} else {
2626
$this->perPage = $this->perPageAccepted[0] ?? 10;
2727
}
2828
}
2929

30-
/**
31-
* @param $value
32-
*/
3330
public function updatedPerPage($value): void
3431
{
35-
if (in_array(session()->get($this->tableName.'-perPage', $this->perPage), $this->perPageAccepted, true)) {
36-
session()->put($this->tableName.'-perPage', (int) $value);
32+
if (in_array(session()->get($this->getPerPagePaginationSessionKey(), $this->perPage), $this->perPageAccepted, true)) {
33+
session()->put($this->getPerPagePaginationSessionKey(), (int) $value);
3734
} else {
38-
session()->put($this->tableName.'-perPage', $this->perPageAccepted[0] ?? 10);
35+
session()->put($this->getPerPagePaginationSessionKey(), $this->perPageAccepted[0] ?? 10);
3936
}
4037

4138
$this->resetPage();
4239
}
4340

44-
/**
45-
* @param $query
46-
* @return mixed
47-
*/
4841
public function applyPagination($query)
4942
{
5043
return $query->paginate($this->perPage === -1 ? $query->count() : $this->perPage, ['*'], $this->pageName());
5144
}
45+
46+
private function getPerPagePaginationSessionKey(): string
47+
{
48+
return $this->tableName.'-perPage';
49+
}
5250
}

0 commit comments

Comments
 (0)