Skip to content

Commit

Permalink
Check if metadata exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Sep 6, 2024
1 parent ff3129f commit 4bfd810
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Resources/EventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('type')
->label(__('Type'))
->badge()
->color(fn (WebhookEventType $state): string => match ($state) {
->color(fn(WebhookEventType $state): string => match ($state) {
WebhookEventType::DELIVERY => 'success',
WebhookEventType::CLICK => 'clicked',
WebhookEventType::OPEN => 'success',
Expand Down Expand Up @@ -114,7 +114,7 @@ public static function infolist(Infolist $infolist): Infolist
->default(__('Unknown'))
->label(__('User Agent'))
->limit(50)
->tooltip(fn ($state) => $state),
->tooltip(fn($state) => $state),
]),
]),
Section::make(__('Location'))
Expand All @@ -141,7 +141,7 @@ public static function infolist(Infolist $infolist): Infolist
->default(__('Unknown'))
->label(__('Link'))
->limit(50)
->url(fn ($state) => $state)
->url(fn($state) => $state)
->openUrlInNewTab(),
TextEntry::make('tag')
->default(__('Unknown'))
Expand All @@ -159,6 +159,12 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('payload')
->label(__('Metadata'))
->formatStateUsing(function ($state) {
if (
!is_object($state) || !property_exists($state, 'Metadata') || empty($state->Metadata)
) {
return __('No metadata available');
}

$metadata = (array) json_decode(json_encode($state->Metadata), true);
unset($metadata[config('mails.headers.uuid')]);

Expand All @@ -184,7 +190,7 @@ public static function table(Table $table): Table
->label(__('Type'))
->sortable()
->badge()
->color(fn (WebhookEventType $state): string => match ($state) {
->color(fn(WebhookEventType $state): string => match ($state) {
WebhookEventType::DELIVERY => 'success',
WebhookEventType::CLICK => 'clicked',
WebhookEventType::OPEN => 'success',
Expand All @@ -197,14 +203,14 @@ public static function table(Table $table): Table
})
->searchable(),
Tables\Columns\TextColumn::make('mail.subject')
->url(fn (MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.view', $record->mail))
->url(fn(MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.view', $record->mail))
->label(__('Subject'))
->searchable(),
Tables\Columns\TextColumn::make('occurred_at')
->label(__('Occurred At'))
->dateTime('d-m-Y H:i')
->since()
->tooltip(fn (MailEvent $record) => $record->occurred_at?->format('d-m-Y H:i'))
->tooltip(fn(MailEvent $record) => $record->occurred_at?->format('d-m-Y H:i'))
->sortable()
->searchable(),
])
Expand Down Expand Up @@ -232,4 +238,4 @@ public static function getPages(): array
'view' => ViewEvent::route('/{record}/view'),
];
}
}
}

0 comments on commit 4bfd810

Please sign in to comment.