Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
199ocero authored and github-actions[bot] committed Jan 17, 2024
1 parent c69b16f commit 80e05c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/Concerns/CanModifyState.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

trait CanModifyState
{

protected $state;

public function modifyState(Closure $callback): static
Expand All @@ -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);
}
Expand Down
35 changes: 16 additions & 19 deletions src/Concerns/HasSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
},
]
],
];
}

Expand Down Expand Up @@ -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 <strong>%s</strong> was <strong>%s</strong> by <strong>%s</strong>.", $className, $state['event'], $causerName));

return new HtmlString(sprintf('The <strong>%s</strong> was <strong>%s</strong> by <strong>%s</strong>.', $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'];
Expand All @@ -164,18 +161,18 @@ private function modifiedState(): array

foreach ($newValues as $key => $newValue) {
if (isset($oldValues[$key]) && $oldValues[$key] != $newValue) {
$changes[] = "- {$key} from <strong>" . htmlspecialchars($oldValues[$key]) . "</strong> to <strong>" . htmlspecialchars($newValue) . "</strong>";
$changes[] = "- {$key} from <strong>".htmlspecialchars($oldValues[$key]).'</strong> to <strong>'.htmlspecialchars($newValue).'</strong>';
}
}

$causerName = $state['causer']->name ?? $state['causer']->first_name ?? $state['causer']->last_name ?? $state['causer']->username ?? 'Unknown';
return new HtmlString(sprintf("%s %s the following: <br>%s", $causerName, $state['event'], implode('<br>', $changes)));
}

return new HtmlString(sprintf('%s %s the following: <br>%s', $causerName, $state['event'], implode('<br>', $changes)));
}

return null;
}
]
},
],
];
}
}
6 changes: 3 additions & 3 deletions src/Pages/ActivityTimelinePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 80e05c5

Please sign in to comment.