Skip to content

Commit 92f9e18

Browse files
committed
Add blade for Livewire Component Array Filter - not live
1 parent 0a23df2 commit 92f9e18

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div wire:key="filterComponents.{{ $filter->getKey() }}-wrapper">
2+
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
3+
<livewire:dynamic-component :is="$livewireComponent" :tableComponent="get_class($this)" :filterKey="$filter->getKey()" :$tableName :key="'filterComponents-'.$filter->getKey()" wire:model="filterComponents.{{ $filter->getKey() }}" />
4+
</div>

src/Traits/Helpers/FilterHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public function showFilterPillsSection(): bool
347347
}
348348

349349
#[On('livewireArrayFilterUpdateValues')]
350-
public function updateLivewireArrayFilterValues(string $filterKey, string $tableName, array $values)
350+
public function updateLivewireArrayFilterValues(string $filterKey, string $tableName, array $values): void
351351
{
352352
if ($this->tableName == $tableName) {
353353
$filter = $this->getFilterByKey($filterKey);

src/Views/Filters/LivewireComponentArrayFilter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LivewireComponentArrayFilter extends Filter
1616

1717
public string $wireMethod = 'blur';
1818

19-
protected string $view = 'livewire-tables::components.tools.filters.livewire-component-filter';
19+
protected string $view = 'livewire-tables::components.tools.filters.livewire-component-array-filter';
2020

2121
public function validate(array $value): array|bool
2222
{
@@ -50,4 +50,9 @@ public function getFilterPillValue($value): array|string|bool|null
5050

5151
return $values;
5252
}
53+
54+
public function getKeys(): array
55+
{
56+
return array_keys($this->options ?? []);
57+
}
5358
}

src/Views/Traits/Filters/HasOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function options(array $options = []): self
3333

3434
public function getOptions(): array
3535
{
36-
return $this->options ?? $this->options = config($this->optionsPath, []);
36+
return $this->options ?? $this->options = (property_exists($this, 'optionsPath') ? config($this->optionsPath, []) : []);
3737
}
3838

3939
public function getKeys(): array

src/Views/Traits/IsExternalArrayFilter.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
trait IsExternalArrayFilter
88
{
99
#[Modelable]
10-
public $value = [];
10+
public array $value = [];
1111

1212
public string $filterKey = '';
1313

@@ -24,12 +24,10 @@ trait IsExternalArrayFilter
2424
public array $selectOptions = [];
2525

2626
#[On('filter-was-set')]
27-
#[Renderless]
28-
public function setFilterValues($tableName, $filterKey, $value)
27+
public function setFilterValues(string $tableName, string $filterKey, array $value): void
2928
{
30-
if ($tableName == $this->tableName && $filterKey == $this->filterKey) {
29+
if ($tableName == $this->tableName && $filterKey == $this->filterKey && $this->selectedItems != $value) {
3130
$this->selectedItems = $value;
32-
$this->clearFilter();
3331
$this->needsUpdating = false;
3432

3533
}
@@ -38,37 +36,31 @@ public function setFilterValues($tableName, $filterKey, $value)
3836
protected function clearFilter() {}
3937

4038
#[Renderless]
41-
public function updatedSelectedItems($values)
39+
public function updatedSelectedItems(string $value): void
4240
{
43-
$this->needsUpdating = true;
44-
}
45-
46-
protected function enableUpdateDispatch(): void
47-
{
48-
$this->needsUpdating = true;
49-
}
41+
if (!$this->needsUpdating)
42+
{
43+
$this->needsUpdating = true;
5044

51-
protected function disableUpdateDispatch(): void
52-
{
53-
$this->needsUpdating = false;
45+
}
5446
}
5547

5648
#[Renderless]
57-
protected function sendUpdateDispatch(array $returnValues)
49+
protected function sendUpdateDispatch(array $returnValues): void
5850
{
5951
if ($this->needsUpdating) {
6052
if (! empty($returnValues)) {
61-
$this->dispatch('livewireArrayFilterUpdateValues', tableName: $this->tableName, filterKey: $this->filterKey, values: $returnValues)->to($this->tableComponent);
6253
$this->value = array_keys($returnValues);
6354
} else {
6455
$this->value = [];
6556
}
66-
$this->needsUpdating = false;
57+
$this->dispatch('livewireArrayFilterUpdateValues', tableName: $this->tableName, filterKey: $this->filterKey, values: $returnValues)->to($this->tableComponent);
6758

6859
}
6960
}
7061

71-
public function renderingIsExternalArrayFilter()
62+
#[Renderless]
63+
public function renderingIsExternalArrayFilter(): void
7264
{
7365
$returnValues = [];
7466

0 commit comments

Comments
 (0)