Skip to content

Commit df0cca0

Browse files
committed
Extract session key
1 parent ddbac6e commit df0cca0

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7-
## [1.11.0] - 2021-06-23
7+
## [1.10.4] - 2021-06-23
88

99
### Added
1010

@@ -414,7 +414,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
414414

415415
- Initial release
416416

417-
[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
418419
[1.10.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.2...v1.10.3
419420
[1.10.2]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.1...v1.10.2
420421
[1.10.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.0...v1.10.1

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: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public function mountWithPerPagePagination(): void
2727
}
2828
}
2929

30-
/**
31-
* @param $value
32-
*/
3330
public function updatedPerPage($value): void
3431
{
3532
if (in_array(session()->get($this->getPerPagePaginationSessionKey(), $this->perPage), $this->perPageAccepted, true)) {
@@ -41,10 +38,6 @@ public function updatedPerPage($value): void
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());

0 commit comments

Comments
 (0)