From 16ff306d93c714ccd7d65eed994ae9bc1696cf7e Mon Sep 17 00:00:00 2001 From: noxoua Date: Fri, 22 Dec 2023 16:33:45 +0000 Subject: [PATCH 1/2] Apply style changes --- src/Services/Helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Services/Helper.php b/src/Services/Helper.php index eabf0d7..c8e13b8 100644 --- a/src/Services/Helper.php +++ b/src/Services/Helper.php @@ -23,15 +23,14 @@ public static function resolveEnum(string $enum, ?string $name): ?UnitEnum /** * @return class-string */ - public static function resolveLogger(string|Model $record, bool $force = false): ?string + public static function resolveLogger(string | Model $record, bool $force = false): ?string { $name = is_string($record) ? $record : get_class($record); return Loggers::getLoggerByModel($name, $force); } - - public static function resolveInlineField($logger, array $attributes, array $old = []): array|null + public static function resolveInlineField($logger, array $attributes, array $old = []): ?array { foreach ($attributes as $key => $newValue) { $field = $logger->getFieldByName($key); From a3ee9437241af632521cb8f5a9bbce484f91bf37 Mon Sep 17 00:00:00 2001 From: Noxo Date: Sat, 23 Dec 2023 16:42:01 +0200 Subject: [PATCH 2/2] fixed filters bug - #54 --- src/Pages/Concerns/HasListFilters.php | 49 ++++++++++++++++----------- src/Pages/ListActivities.php | 3 +- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/Pages/Concerns/HasListFilters.php b/src/Pages/Concerns/HasListFilters.php index d17b0d7..3d2a3d8 100644 --- a/src/Pages/Concerns/HasListFilters.php +++ b/src/Pages/Concerns/HasListFilters.php @@ -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( @@ -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'); }); diff --git a/src/Pages/ListActivities.php b/src/Pages/ListActivities.php index f29b9a2..d3ac720 100644 --- a/src/Pages/ListActivities.php +++ b/src/Pages/ListActivities.php @@ -55,8 +55,7 @@ public function form(Form $form): Form $this->getEventField(), ]), ]) - ->debounce() - ->statePath('filters'); + ->debounce(); } public function getActivities()