Skip to content

Commit

Permalink
Merge pull request #55 from noxoua/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
noxoua authored Dec 23, 2023
2 parents 453e8c2 + a3ee943 commit 4debb48
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
49 changes: 30 additions & 19 deletions src/Pages/Concerns/HasListFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,45 @@

trait HasListFilters
{
public ?array $filters = [
'date_range' => null,
'causer' => null,
'subject_type' => null,
'subject_id' => null,
'event' => null,
public ?string $date_range = null;
public ?string $causer = null;
public ?string $subject_type = null;
public ?string $subject_id = null;
public ?string $event = null;

protected $queryString = [
'date_range' => ['except' => null],
'causer' => ['except' => null],
'subject_type' => ['except' => null],
'subject_id' => ['except' => null],
'event' => ['except' => null],
];

protected function queryString()
public function resetFiltersForm(): void
{
$queryString = [];
foreach (array_keys($this->filters) as $filter) {
$queryString["filters.{$filter}"] = ['except' => null, 'as' => $filter];
}

return $queryString;
$this->form->fill();
}

public function resetFiltersForm(): void
public function getFilters(): array
{
$this->form->fill();
return [
'date_range' => $this->date_range,
'causer' => $this->causer,
'subject_type' => $this->subject_type,
'subject_id' => $this->subject_id,
'event' => $this->event,
];
}

public function hasActiveFilters(): bool
{
return count(array_filter($this->filters)) > 0;
return count(array_filter($this->getFilters())) > 0;
}

public function fillFilters(): void
{
$values = request()->only(
array_keys($this->filters),
array_keys($this->getFilters()),
);

$this->form->fill(
Expand All @@ -58,13 +65,17 @@ public function fillFilters(): void
public function applyFilters(Builder $query): Builder
{
$state = $this->form->getState();

$causer = with($state['causer'], function ($causer) {
if (empty($causer) || ! str_contains($causer, ':')) {
return null;
}

[$causer_type, $causer_id] = explode(':', $causer);
$parts = explode(':', $causer);
if (count($parts) !== 2) {
return null;
}

[$causer_type, $causer_id] = $parts;

return compact('causer_type', 'causer_id');
});
Expand Down
3 changes: 1 addition & 2 deletions src/Pages/ListActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function form(Form $form): Form
$this->getEventField(),
]),
])
->debounce()
->statePath('filters');
->debounce();
}

public function getActivities()
Expand Down

0 comments on commit 4debb48

Please sign in to comment.