Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
dansysanalyst committed May 23, 2024
1 parent c5010b2 commit f761a41
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/Concerns/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTimeZone;
use Illuminate\Support\{Arr, Carbon, Collection};
use Livewire\Attributes\On;
use PowerComponents\LivewirePowerGrid\Column;

trait Filter
{
Expand Down Expand Up @@ -330,19 +331,21 @@ public function addEnabledFilters(string $field, ?string $label): void
}
}

//@TODO REFACTOR
public function ____COLUMNS_FOR_QUERY_STRING(): Collection
public function listColumnForFilters(): Collection
{
$columns = collect();

collect($this->columns())
->each(function ($column) use (&$columns) {
if (isset($column->dataField)) {
$columns[$column->dataField] = $column->title ?? $column->dataField;
}
->ensure([Column::class])
->each(function ($column) use (&$columns) {
if (isset($column->dataField)) {
$columns->put($column->dataField, $column->title ?? $column->dataField);
}

$columns[$column->field] = $column->title ?? $column->field;
});
$columns->put($column->field, $column->title ?? $column->field);
});

return collect($columns);
return $columns;
}

/*
Expand All @@ -352,12 +355,12 @@ protected function powerGridQueryString(): array
{
$queryString = [];

$columns = $this->____COLUMNS_FOR_QUERY_STRING();
$columns = $this->listColumnForFilters();

foreach (Arr::dot($this->filters()) as $filter) {
$as = str($filter->field)->replace('.', '_');

if (!is_null(request()->get($as))) {
if (!empty(request()->get($as))) {
$this->addEnabledFilters($filter->field, strval($columns->get($filter->field, $filter->field)));
}

Expand Down

0 comments on commit f761a41

Please sign in to comment.