Skip to content

Commit 4470951

Browse files
committed
Additional Fixes for Tests & Adding Collections
1 parent 83f9a91 commit 4470951

35 files changed

+429
-204
lines changed

resources/views/includes/toolbar/items/column-select/modern.blade.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
childElementOpen: false,
2020
updatingRoot: false,
2121
previousCols: [],
22+
selectableCols: $wire.entangle('selectableColumns'),
2223
selectedCols: $wire.entangle('selectedColumns'),
2324
selectableColumnCount: $wire.entangle('selectableColumnCount'),
2425
timeout: 0,
@@ -27,19 +28,35 @@
2728
this.open = false;
2829
$wire.call('toggleAllColumns');
2930
},
31+
checkShouldSendUpdate()
32+
{
33+
if(this.selectedCols.length != this.previousCols.length)
34+
{
35+
return true;
36+
}
37+
38+
for (let i = 0; i < this.selectedCols.length; i++) {
39+
if (this.selectedCols[i] !== this.previousCols[i]) {
40+
return true;
41+
}
42+
}
43+
44+
return false;
45+
},
3046
sendUpdate()
3147
{
32-
if(this.selectedCols != this.previousCols)
48+
if(this.checkShouldSendUpdate())
3349
{
3450
this.previousCols = this.selectedCols;
35-
open = false;
51+
this.open = false;
3652
$wire.$refresh();
3753
}
3854
},
3955
init()
4056
{
4157
$nextTick(() => {
42-
this.previousCols = $wire.get('selectedColumns');
58+
let preCol = $wire.get('selectedColumns');
59+
this.previousCols = preCol;
4360
});
4461
}
4562
}"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Collections;
4+
5+
use Illuminate\Support\Collection;
6+
use Rappasoft\LaravelLivewireTables\Features\Actions\Views\Action;
7+
8+
class ActionCollection extends Collection
9+
{
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Collections;
4+
5+
use Illuminate\Support\Collection;
6+
use Rappasoft\LaravelLivewireTables\Features\BulkActions\Views\BulkAction;
7+
8+
class BulkActionCollection extends Collection
9+
{
10+
11+
}

src/Collections/ColumnCollection.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,40 @@ public function selected() {
2323
return $this->reject(fn (Column $column) => $column->isSelectable() && ! $column->isSelected());
2424
}
2525

26+
/**
27+
* Undocumented function
28+
*
29+
* @param array<mixed> $selectedColumns
30+
*/
31+
public function selectedInTable(array $selectedColumns) {
32+
return $this->reject(function (Column $column) use ($selectedColumns) {
33+
return !empty($selectedColumns) && in_array($column->getSlug(), $selectedColumns, true);
34+
});
35+
}
36+
37+
38+
/**
39+
* Undocumented function
40+
*
41+
* @param array<mixed> $selectedColumns
42+
*/
43+
public function rejectUnselectedColumns(array $selectedColumns) {
44+
return $this->reject(function (Column $column) use ($selectedColumns) {
45+
return $column->isSelectable() && !empty($selectedColumns) && in_array($column->getSlug(), $selectedColumns, true);
46+
});
47+
}
48+
49+
2650
public function visibleOnReorder() {
2751
return $this->reject(fn (Column $column) => !$column->isVisibleOnReorder());
2852
}
2953

54+
public function rejectInvisibleWhileReordering(bool $currentlyReordering = false)
55+
{
56+
return $this->reject(function (Column $column) use ($currentlyReordering) {
57+
return $currentlyReordering && !$column->isVisibleOnReorder();
58+
});
59+
}
3060

3161
public function reorder() {
3262
return $this->reject(fn (Column $column) => !$column->isVisibleOnReorder());
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Collections;
4+
5+
use Illuminate\Support\Collection;
6+
use Rappasoft\LaravelLivewireTables\Features\Filters\Views\Filter;
7+
8+
class FilterCollection extends Collection
9+
{
10+
11+
}

src/Features/Actions/Core/Helpers/ActionsHelpers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Features\Actions\Core\Helpers;
44

5-
use Illuminate\Support\Collection;
65
use Livewire\Attributes\Computed;
76
use Rappasoft\LaravelLivewireTables\Features\Actions\Views\Action;
7+
use Rappasoft\LaravelLivewireTables\Collections\ActionCollection;
88

99
trait ActionsHelpers
1010
{
@@ -80,12 +80,12 @@ public function hasActions(): bool
8080
/**
8181
* Retrieves the valid actions
8282
*
83-
* @return Collection<int,Action>
83+
* @return ActionCollection<int,Action>
8484
*/
8585
#[Computed]
86-
public function getActions(): Collection
86+
public function getActions(): ActionCollection
8787
{
88-
return (new Collection($this->actions()))
88+
return (new ActionCollection($this->actions()))
8989
->filter(fn ($action) => $action instanceof Action)
9090
->each(function (Action $action, int $key) {
9191
$action->setTheme($this->getTheme());

src/Features/Actions/Core/WithActions.php

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

33
namespace Rappasoft\LaravelLivewireTables\Features\Actions\Core;
44

5-
use Illuminate\Support\Collection;
5+
use Rappasoft\LaravelLivewireTables\Collections\ActionCollection;
66
use Rappasoft\LaravelLivewireTables\Features\Actions\Core\Configuration\ActionsConfiguration;
77
use Rappasoft\LaravelLivewireTables\Features\Actions\Core\Helpers\ActionsHelpers;
88
use Rappasoft\LaravelLivewireTables\Features\Actions\Core\Styling\HasActionsStyling;
@@ -37,9 +37,9 @@ trait WithActions
3737
/**
3838
* Undocumented variable
3939
*
40-
* @var Collection<int,\Rappasoft\LaravelLivewireTables\Features\Actions\Views\Action>|null
40+
* @var ActionCollection<int,\Rappasoft\LaravelLivewireTables\Features\Actions\Views\Action>|null
4141
*/
42-
protected ?Collection $validActions;
42+
protected ?ActionCollection $validActions;
4343

4444
/**
4545
* Undocumented function
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Features\ColumnSelect\Concerns;
4+
5+
trait HandlesColumnSelectRemembering
6+
{
7+
8+
protected function setRememberColumnSelectionStatus(bool $status): self
9+
{
10+
$this->storeColumnSelectInSessionStatus($status);
11+
12+
return $this;
13+
}
14+
15+
protected function setRememberColumnSelectionEnabled(): self
16+
{
17+
return $this->setRememberColumnSelectionStatus(true);
18+
}
19+
20+
protected function setRememberColumnSelectionDisabled(): self
21+
{
22+
return $this->setRememberColumnSelectionStatus(false);
23+
}
24+
25+
26+
}

src/Features/ColumnSelect/Configuration/ColumnSelectConfiguration.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@
77
trait ColumnSelectConfiguration
88
{
99

10-
public function setRememberColumnSelectionStatus(bool $status): self
11-
{
12-
$this->storeColumnSelectInSessionStatus($status);
13-
14-
return $this;
15-
}
16-
17-
public function setRememberColumnSelectionEnabled(): self
18-
{
19-
return $this->setRememberColumnSelectionStatus(true);
20-
}
21-
22-
public function setRememberColumnSelectionDisabled(): self
23-
{
24-
return $this->setRememberColumnSelectionStatus(false);
25-
}
2610

2711
public function setExcludeDeselectedColumnsFromQuery(bool $status): self
2812
{

src/Features/ColumnSelect/Helpers/ColumnSelectHelpers.php

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

33
namespace Rappasoft\LaravelLivewireTables\Features\ColumnSelect\Helpers;
44

5-
use Illuminate\Support\Collection;
65
use Livewire\Attributes\Computed;
76
use Rappasoft\LaravelLivewireTables\Events\ColumnsSelected;
87
use Rappasoft\LaravelLivewireTables\Features\Columns\Views\Column;
@@ -19,7 +18,7 @@ trait ColumnSelectHelpers
1918
*/
2019
public function columnSelectIsEnabledForColumn(mixed $column): bool
2120
{
22-
return in_array($column instanceof Column ? $column->getSlug() : $column, $this->selectedColumns ?? [], true);
21+
return !empty($this->selectedColumns) && in_array($column instanceof Column ? $column->getSlug() : $column, $this->selectedColumns ?? [], true);
2322
}
2423

2524

@@ -76,7 +75,7 @@ public function getSelectableColumns(): ColumnCollection
7675
return $this->getColumns()
7776
->visible()
7877
->selectable()
79-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
78+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
8079
->values();
8180
}
8281

@@ -92,7 +91,7 @@ public function getSelectableSelectedColumns(): ColumnCollection
9291
->visible()
9392
->selectable()
9493
->reject(fn (Column $column) => !in_array($column->getSlug(), $this->selectedColumns ?? []))
95-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
94+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
9695
->values();
9796
}
9897

@@ -106,7 +105,7 @@ public function getUnSelectableColumns(): ColumnCollection
106105
return $this->getColumns()
107106
->visible()
108107
->unselectable()
109-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
108+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
110109
->values();
111110
}
112111

@@ -131,7 +130,7 @@ public function getSelectedColumnsForQuery(): array
131130
->visible()
132131
->reject(fn (Column $column) => $column->isLabel())
133132
->reject(fn (Column $column) => ($column->isSelectable() && ! $this->columnSelectIsEnabledForColumn($column)))
134-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
133+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
135134
->values()
136135
->toArray();
137136
}
@@ -146,8 +145,8 @@ public function getColumnsForColumnSelect(): array
146145
return $this->getColumns()
147146
->visible()
148147
->selectable()
149-
->reject(fn (Column $column) => ! $this->columnSelectIsEnabledForColumn($column))
150-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
148+
->reject(fn (Column $column) => !$column->isSelectable() || ! $this->columnSelectIsEnabledForColumn($column))
149+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
151150
->keyBy(function (Column $column, int $key) {
152151
return $column->getSlug();
153152
})
@@ -172,7 +171,7 @@ public function getDefaultVisibleColumns(): array
172171
->visible()
173172
->reject(fn (Column $column) => $column->isSelectable() && ! $column->isSelected())
174173
->reject(fn (Column $column) => !$column->isSelectable())
175-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
174+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
176175
->map(fn ($column) => $column->getSlug())
177176
->values()
178177
->toArray();
@@ -199,7 +198,7 @@ public function selectedVisibleColumns(): array
199198
return $this->getColumns()
200199
->visible()
201200
->reject(fn (Column $column) => ($column->isSelectable() && ! $this->columnSelectIsEnabledForColumn($column)))
202-
->reject(fn (Column $column) => $this->currentlyReorderingIsEnabled() && !$column->isVisibleOnReorder())
201+
->rejectInvisibleWhileReordering($this->currentlyReorderingIsEnabled())
203202
->values()
204203
->toArray();
205204
}
@@ -215,6 +214,7 @@ public function selectAllColumns(): void
215214
foreach ($this->getSelectableColumns() as $column) {
216215
$this->selectedColumns[] = $column->getSlug();
217216
}
217+
$this->pushToQueryString($this->selectedColumns);
218218
$this->storeColumnSelectValues();
219219

220220
if ($this->getEventStatusColumnSelect()) {
@@ -230,6 +230,7 @@ public function selectAllColumns(): void
230230
public function deselectAllColumns(): void
231231
{
232232
$this->selectedColumns = [];
233+
$this->pushToQueryString($this->selectedColumns);
233234
session([$this->getColumnSelectSessionKey() => []]);
234235
if ($this->getEventStatusColumnSelect()) {
235236
event(new ColumnsSelected($this->getTableName(), $this->getColumnSelectSessionKey(), $this->selectedColumns));
@@ -345,5 +346,4 @@ public function getColumnSelectDelay(): int
345346
return $this->columnSelectDelay ?? 1500;
346347
}
347348

348-
349349
}

0 commit comments

Comments
 (0)