Skip to content

Commit

Permalink
Adjust wire attributes for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Dec 15, 2023
1 parent ffbc583 commit 05fb3bb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Components/Filters/FilterBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function getWireAttributes(string $field, string $title): array
return collect()
->put('selectAttributes', new ComponentAttributeBag([
'wire:input.blur' => 'filterBoolean(\'' . $field . '\', $event.target.value, \'' . $title . '\')',
'wire:model.blur' => 'filters.boolean.' . $field,
'wire:model' => 'filters.boolean.' . $field,
]))->toArray();
}
}
8 changes: 4 additions & 4 deletions src/Components/Filters/FilterInputText.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public static function getWireAttributes(string $field, string $title): array
{
return collect()
->put('selectAttributes', new ComponentAttributeBag([
'wire:model.live' => 'filters.input_text_options.' . $field,
'wire:input.live' => 'filterInputTextOptions(\'' . $field . '\', $event.target.value)',
'wire:model' => 'filters.input_text_options.' . $field,
'wire:input.debounce.600ms' => 'filterInputTextOptions(\'' . $field . '\', $event.target.value)',
]))
->put('inputAttributes', new ComponentAttributeBag([
'wire:model.live.debounce.700ms' => 'filters.input_text.' . $field,
'wire:input.debounce.700ms' => 'filterInputText(\'' . $field . '\', $event.target.value, \'' . $title . '\')',
'wire:model' => 'filters.input_text.' . $field,
'wire:input.debounce.600ms' => 'filterInputText(\'' . $field . '\', $event.target.value, \'' . $title . '\')',
]))
->toArray();
}
Expand Down
6 changes: 4 additions & 2 deletions src/Components/Filters/FilterNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public static function getWireAttributes(string $field, array $filter): array
{
return collect()
->put('inputStartAttributes', new ComponentAttributeBag([
'wire:input.live.debounce.800ms' => 'filterNumberStart(\'' . $field . '\', ' . Js::from($filter) . ', $event.target.value)',
'wire:model' => 'filters.number.' . $field . '.start',
'wire:input.live.debounce.600ms' => 'filterNumberStart(\'' . $field . '\', ' . Js::from($filter) . ', $event.target.value)',
]))
->put('inputEndAttributes', new ComponentAttributeBag([
'wire:input.live.debounce.800ms' => 'filterNumberEnd(\'' . $field . '\', ' . Js::from($filter) . ', $event.target.value)',
'wire:model' => 'filters.number.' . $field . '.end',
'wire:input.live.debounce.600ms' => 'filterNumberEnd(\'' . $field . '\', ' . Js::from($filter) . ', $event.target.value)',
]))
->toArray();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Filters/FilterSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static function getWireAttributes(string $field, string $title): array
{
return collect()
->put('selectAttributes', new ComponentAttributeBag([
'wire:model.live.debounce.500ms' => 'filters.select.' . $field,
'wire:input.debounce.500ms' => 'filterSelect(\'' . $field . '\', \'' . $title . '\')',
'wire:model' => 'filters.select.' . $field,
'wire:input.debounce.600ms' => 'filterSelect(\'' . $field . '\', \'' . $title . '\')',
]))
->toArray();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/HasFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ private function resolveFilters(): void
{
$filters = collect($this->filters());

if ($filters->isEmpty()) {
return;
}

/** @var Column $column */
foreach ($this->columns as $column) {
if (str(strval(data_get($column, 'dataField')))->contains('.')) {
Expand Down Expand Up @@ -283,8 +287,6 @@ public function filterNumberStart(string $field, array $params, string $value):

$this->resetPage();

$this->filters['number'][$field]['start'] = $value;

store($this)->set('filters.number.' . $field . '.thousands', $thousands);
store($this)->set('filters.number.' . $field . '.decimal', $decimal);

Expand All @@ -309,8 +311,6 @@ public function filterNumberEnd(string $field, array $params, string $value): vo
store($this)->set('filters.number.' . $field . '.thousands', $thousands);
store($this)->set('filters.number.' . $field . '.decimal', $decimal);

$this->filters['number'][$field]['end'] = $value;

$this->enabledFilters[$field]['id'] = $field;
$this->enabledFilters[$field]['label'] = $title;

Expand Down

0 comments on commit 05fb3bb

Please sign in to comment.