diff --git a/src/Concerns/CanModifyState.php b/src/Concerns/CanModifyState.php index c7acbd8..5ffa672 100644 --- a/src/Concerns/CanModifyState.php +++ b/src/Concerns/CanModifyState.php @@ -7,7 +7,6 @@ trait CanModifyState { - protected $state; public function modifyState(Closure $callback): static @@ -17,7 +16,7 @@ public function modifyState(Closure $callback): static return $this; } - public function getModifiedState(): HtmlString | null + public function getModifiedState(): ?HtmlString { return $this->evaluate($this->state); } diff --git a/src/Concerns/HasSetting.php b/src/Concerns/HasSetting.php index a9561cb..12c272c 100644 --- a/src/Concerns/HasSetting.php +++ b/src/Concerns/HasSetting.php @@ -2,20 +2,15 @@ namespace JaOcero\ActivityTimeline\Concerns; -use Livewire\Livewire; -use Filament\Forms\Get; -use Illuminate\Support\Str; use Filament\Infolists\Infolist; use Illuminate\Support\Collection; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Facades\Log; use Illuminate\Support\HtmlString; -use Spatie\Activitylog\Models\Activity; +use Illuminate\Support\Str; use JaOcero\ActivityTimeline\Components\ActivityDate; +use JaOcero\ActivityTimeline\Components\ActivityDescription; use JaOcero\ActivityTimeline\Components\ActivityIcon; -use JaOcero\ActivityTimeline\Components\ActivityTitle; use JaOcero\ActivityTimeline\Components\ActivitySection; -use JaOcero\ActivityTimeline\Components\ActivityDescription; +use JaOcero\ActivityTimeline\Components\ActivityTitle; trait HasSetting { @@ -48,13 +43,13 @@ protected function configuration(): array 'placeholder' => 'No date is set', ], 'activity_icon' => [ - 'icon' => fn (string | null $state): string | null => match ($state) { + 'icon' => fn (?string $state): ?string => match ($state) { default => null }, - 'color' => fn (string | null $state): string | null => match ($state) { + 'color' => fn (?string $state): ?string => match ($state) { default => null }, - ] + ], ]; } @@ -145,17 +140,19 @@ private function modifiedState(): array if ($state['description'] == $state['event']) { $className = Str::lower(Str::snake(class_basename($state['subject']), ' ')); $causerName = $state['causer']->name ?? $state['causer']->first_name ?? $state['causer']->last_name ?? $state['causer']->username ?? 'Unknown'; - return new HtmlString(sprintf("The %s was %s by %s.", $className, $state['event'], $causerName)); + + return new HtmlString(sprintf('The %s was %s by %s.', $className, $state['event'], $causerName)); } + return new HtmlString($state['description']); - } + }, ], 'activity_description' => [ 'modify_state' => function (array $state) { $properties = $state['properties']; - if (!empty($properties) && isset($properties['old']) && isset($properties['attributes'])) { + if (! empty($properties) && isset($properties['old']) && isset($properties['attributes'])) { $oldValues = $properties['old']; $newValues = $properties['attributes']; @@ -164,18 +161,18 @@ private function modifiedState(): array foreach ($newValues as $key => $newValue) { if (isset($oldValues[$key]) && $oldValues[$key] != $newValue) { - $changes[] = "- {$key} from " . htmlspecialchars($oldValues[$key]) . " to " . htmlspecialchars($newValue) . ""; + $changes[] = "- {$key} from ".htmlspecialchars($oldValues[$key]).' to '.htmlspecialchars($newValue).''; } } $causerName = $state['causer']->name ?? $state['causer']->first_name ?? $state['causer']->last_name ?? $state['causer']->username ?? 'Unknown'; - return new HtmlString(sprintf("%s %s the following:
%s", $causerName, $state['event'], implode('
', $changes))); - } + return new HtmlString(sprintf('%s %s the following:
%s', $causerName, $state['event'], implode('
', $changes))); + } return null; - } - ] + }, + ], ]; } } diff --git a/src/Pages/ActivityTimelinePage.php b/src/Pages/ActivityTimelinePage.php index 432627a..d1330c7 100644 --- a/src/Pages/ActivityTimelinePage.php +++ b/src/Pages/ActivityTimelinePage.php @@ -2,17 +2,17 @@ namespace JaOcero\ActivityTimeline\Pages; -use Filament\Resources\Pages\Page; use Filament\Resources\Pages\Concerns\InteractsWithRecord; +use Filament\Resources\Pages\Page; use JaOcero\ActivityTimeline\Concerns\HasSetting; class ActivityTimelinePage extends Page { - use InteractsWithRecord, HasSetting; + use HasSetting, InteractsWithRecord; protected static string $view = 'activity-timeline::pages.view-activities'; - public function mount(int | string $record): void + public function mount(int|string $record): void { static::authorizeResourceAccess();