Skip to content

Commit 81410c2

Browse files
committed
Merge branch 'v2-query-rework' into develop
2 parents 1ef9cb4 + 088a6b8 commit 81410c2

19 files changed

+97
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ phpunit.xml
99
psalm.xml
1010
testbench.yaml
1111
vendor
12+
output.txt

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
1111
- Added $row as second parameter to BooleanColumn `setCallback()`.
1212
- Added `setThSortButtonAttributes()` to set attributes for th sort button.
1313

14+
### Changed
15+
16+
- Rework builder to fix passed parameters in `builder()` and `columns()` methods.
17+
- Fixed possible bug with bulk actions dropdown on Tailwind when bulk actions are hidden until a selection is made.
18+
1419
## [2.3.0] - 2022-04-28
1520

1621
### Added

resources/views/components/tools/toolbar.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class="w-full inline-flex items-center justify-center px-3 py-2 border border-gr
152152
@keydown.window.escape="open = false"
153153
x-on:click.away="open = false"
154154
class="relative inline-block text-left z-10 w-full md:w-auto"
155-
wire:key="bulk-actions-button-{{ $component->getTableName() }}"
156155
>
157156
<div>
158157
<span class="rounded-md shadow-sm">

src/DataTableComponent.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ public function boot(): void
5959

6060
// Set the filter defaults based on the filter type
6161
$this->setFilterDefaults();
62-
63-
// Set the user defined columns to work with
64-
$this->setColumns();
6562

6663
// Call the child configuration, if any
6764
$this->configure();
@@ -78,6 +75,8 @@ public function boot(): void
7875
public function booted(): void
7976
{
8077
$this->setTheme();
78+
$this->setBuilder($this->builder());
79+
$this->setColumns();
8180
}
8281

8382
/**
@@ -119,6 +118,14 @@ public function customView(): string
119118
*/
120119
public function render()
121120
{
121+
$this->setBuilder($this->builder());
122+
$this->setColumns();
123+
$this->setupColumnSelect();
124+
$this->setupPagination();
125+
$this->setupSecondaryHeader();
126+
$this->setupFooter();
127+
$this->setupReordering();
128+
122129
return view('livewire-tables::datatable')
123130
->with([
124131
'columns' => $this->getColumns(),

src/Traits/ComponentUtilities.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Traits;
44

5+
use Illuminate\Database\Eloquent\Builder;
56
use Illuminate\Support\Str;
67
use Rappasoft\LaravelLivewireTables\Traits\Configuration\ComponentConfiguration;
78
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ComponentHelpers;
@@ -13,6 +14,7 @@ trait ComponentUtilities
1314

1415
public array $table = [];
1516
public $theme = null;
17+
protected Builder $builder;
1618
protected $model;
1719
protected $primaryKey;
1820
protected string $tableName = 'table';

src/Traits/Helpers/BulkActionsHelpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function updatedSelected(): void
172172
*/
173173
public function updatedSelectAll(): void
174174
{
175-
if (count($this->getSelected()) === $this->baseQuery()->pluck($this->getPrimaryKey())->count()) {
175+
if (count($this->getSelected()) === (clone $this->baseQuery())->pluck($this->getPrimaryKey())->count()) {
176176
$this->clearSelected();
177177
} else {
178178
$this->setAllSelected();
@@ -185,6 +185,6 @@ public function updatedSelectAll(): void
185185
public function setAllSelected(): void
186186
{
187187
$this->setSelectAllEnabled();
188-
$this->setSelected($this->baseQuery()->pluck($this->getPrimaryKey())->map(fn ($item) => (string)$item)->toArray());
188+
$this->setSelected((clone $this->baseQuery())->pluck($this->getPrimaryKey())->map(fn ($item) => (string)$item)->toArray());
189189
}
190190
}

src/Traits/Helpers/ColumnHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function setColumns(): void
1919

2020
if ($column->hasField()) {
2121
if ($column->isBaseColumn()) {
22-
$column->setTable($this->builder()->getModel()->getTable());
22+
$column->setTable($this->getBuilder()->getModel()->getTable());
2323
} else {
2424
$column->setTable($this->getTableForColumn($column));
2525
}

src/Traits/Helpers/ComponentHelpers.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,28 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;
44

5+
use Illuminate\Database\Eloquent\Builder;
56
use Illuminate\Database\Eloquent\Model;
67
use Rappasoft\LaravelLivewireTables\Views\Column;
78

89
trait ComponentHelpers
910
{
11+
/**
12+
* @param Builder
13+
*/
14+
public function setBuilder(Builder $builder): void
15+
{
16+
$this->builder = $builder;
17+
}
18+
19+
/**
20+
* @return Builder
21+
*/
22+
public function getBuilder(): Builder
23+
{
24+
return $this->builder;
25+
}
26+
1027
/**
1128
* @return bool
1229
*/

src/Traits/WithColumnSelect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait WithColumnSelect
1414
protected bool $columnSelectStatus = true;
1515
protected bool $rememberColumnSelectionStatus = true;
1616

17-
public function mountWithColumnSelect(): void
17+
public function setupColumnSelect(): void
1818
{
1919
// If remember selection is off, then clear the session
2020
if ($this->rememberColumnSelectionIsDisabled()) {

src/Traits/WithColumns.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ trait WithColumns
1010
use ColumnHelpers;
1111

1212
protected Collection $columns;
13+
14+
public function bootWithColumns(): void
15+
{
16+
$this->columns = collect();
17+
}
1318
}

0 commit comments

Comments
 (0)