Skip to content

Commit

Permalink
Migrate "Updated" from ComponentUtilities (#1666)
Browse files Browse the repository at this point in the history
* Migrate "Updated" from ComponentUtilities

* Fix styling

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>
  • Loading branch information
lrljoe and lrljoe authored Feb 24, 2024
1 parent bed2130 commit f20721a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## [v3.2.0] - 2023-01-04
## [v3.2.1] - 2024-02-24
### Bug Fixes
- Fix collapsing columns not respecting view point collapse points by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1665

### Tweaks
- Migrate "updated" Search and FilterComponents calls to WithSearch and WithFilters by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1666
- Allow nullable search/filter values by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1666

## [v3.2.0] - 2024-01-04
### Tweaks
- Migration to new Core Traits, and de-duplication of code by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1623

Expand Down
34 changes: 0 additions & 34 deletions src/Traits/ComponentUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,6 @@ protected function generateDataTableFingerprint(): string
return base_convert($crc32, 10, 36);
}

/**
* Keep track of any properties on the custom query string key for this specific table
*/
public function updated(string $name, string|array $value): void
{
if ($name === 'search') {
$this->resetComputedPage();

// Clear bulk actions on search
$this->clearSelected();
$this->setSelectAllDisabled();

if ($value === '') {
$this->clearSearch();
}
}

if (Str::contains($name, 'filterComponents')) {
$this->resetComputedPage();

// Clear bulk actions on filter
$this->clearSelected();
$this->setSelectAllDisabled();

// Clear filters on empty value
$filterName = Str::after($name, 'filterComponents.');
$filter = $this->getFilterByKey($filterName);

if ($filter && $filter->isEmpty($value)) {
$this->resetFilter($filterName);
}
}
}

/**
* 1. After the sorting method is hit we need to tell the table to go back into reordering mode
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Traits/Helpers/TableAttributeHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,47 @@ public function getComponentWrapperAttributes(): array
}

/**
* @return array<mixed>
* @return array<mixed>
*/
public function getTableWrapperAttributes(): array
{
return count($this->tableWrapperAttributes) ? $this->tableWrapperAttributes : ['default' => true];
}

/**
* @return array<mixed>
* @return array<mixed>
*/
public function getTableAttributes(): array
{
return count($this->tableAttributes) ? $this->tableAttributes : ['id' => 'table-'.$this->getTableName(), 'default' => true];
}

/**
* @return array<mixed>
* @return array<mixed>
*/
public function getTheadAttributes(): array
{
return count($this->theadAttributes) ? $this->theadAttributes : ['default' => true];
}

/**
* @return array<mixed>
* @return array<mixed>
*/
public function getTbodyAttributes(): array
{
return count($this->tbodyAttributes) ? $this->tbodyAttributes : ['default' => true];
}

/**
* @return array<mixed>
* @return array<mixed>
*/
public function getThAttributes(Column $column): array
{
return $this->thAttributesCallback ? call_user_func($this->thAttributesCallback, $column) : ['default' => true];
}

/**
* @return array<mixed>
* @return array<mixed>
*/
public function getThSortButtonAttributes(Column $column): array
{
Expand Down
16 changes: 16 additions & 0 deletions src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ public function applyFilters(): Builder

return $this->getBuilder();
}

public function updatedFilterComponents(string|array|null $value, string $filterName): void
{
$this->resetComputedPage();

// Clear bulk actions on filter
$this->clearSelected();
$this->setSelectAllDisabled();

// Clear filters on empty value
$filter = $this->getFilterByKey($filterName);

if ($filter && $filter->isEmpty($value)) {
$this->resetFilter($filterName);
}
}
}
13 changes: 13 additions & 0 deletions src/Traits/WithSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public function applySearch(): Builder

return $this->getBuilder();
}

public function updatedSearch(string|array|null $value): void
{
$this->resetComputedPage();

// Clear bulk actions on search
$this->clearSelected();
$this->setSelectAllDisabled();

if (is_null($value) || $value === '') {
$this->clearSearch();
}
}
}

0 comments on commit f20721a

Please sign in to comment.