File tree Expand file tree Collapse file tree
Resources/InboundWebhook/Pages Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55namespace Basement \Webhooks \Filament \Admin \Resources \InboundWebhook \Pages ;
66
77use Basement \Webhooks \Filament \Admin \Resources \InboundWebhook \InboundWebhookResource ;
8+ use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookStatsByProviderPercentage ;
9+ use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookStatsBySource ;
810use Filament \Actions \BulkActionGroup ;
911use Filament \Actions \DeleteAction ;
1012use Filament \Actions \DeleteBulkAction ;
@@ -20,6 +22,13 @@ final class ListInboundWebhooks extends ListRecords
2022{
2123 protected static string $ resource = InboundWebhookResource::class;
2224
25+ protected function getHeaderWidgets (): array
26+ {
27+ return [
28+ InboundWebhookStatsBySource::make (),
29+ ];
30+ }
31+
2332 public function table (Table $ table ): Table
2433 {
2534 return $ table
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Basement \Webhooks \Filament \Admin \Widgets ;
4+
5+ use Basement \Webhooks \Enums \InboundWebhookSource ;
6+ use Basement \Webhooks \Models \InboundWebhook ;
7+ use Filament \Widgets \StatsOverviewWidget ;
8+ use Filament \Widgets \StatsOverviewWidget \Stat ;
9+
10+ class InboundWebhookStatsBySource extends StatsOverviewWidget
11+ {
12+ protected function getStats (): array
13+ {
14+ return $ this ->getInboundWebhooksStats ();
15+ }
16+
17+ private function getInboundWebhooksStats (): array
18+ {
19+ $ totalWebhooks = InboundWebhook::count ();
20+ $ stats = [];
21+
22+ foreach (InboundWebhookSource::cases () as $ source ) {
23+ $ count = InboundWebhook::where ('source ' , $ source ->value )->count ();
24+ $ percentage = $ totalWebhooks > 0 ? round (($ count / $ totalWebhooks ) * 100 , 2 ) : 0 ;
25+ $ stats [] = Stat::make ("{$ source ->name }" ,"{$ percentage }% " )
26+ ->descriptionIcon ($ source ->getIcon ())
27+ ->description ("{$ count } de {$ totalWebhooks } webhooks " )
28+ ->color ($ source ->getColor ());
29+ }
30+ return $ stats ;
31+ }
32+ }
Original file line number Diff line number Diff line change 55namespace Basement \Webhooks ;
66
77use Basement \Webhooks \Filament \Admin \Resources \InboundWebhook \InboundWebhookResource ;
8+ use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookStatsByProviderPercentage ;
9+ use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookStatsBySource ;
810use Filament \Contracts \Plugin ;
911use Filament \Panel ;
1012
@@ -25,6 +27,9 @@ public function register(Panel $panel): void
2527 $ panel ->resources ([
2628 InboundWebhookResource::class,
2729 ]);
30+ $ panel ->widgets ([
31+ InboundWebhookStatsBySource::make (),
32+ ]);
2833 }
2934
3035 public function boot (Panel $ panel ): void {}
Original file line number Diff line number Diff line change 44
55namespace Basement \Webhooks \Models ;
66
7+ use Basement \Webhooks \Database \Factories \InboundWebhookFactory ;
78use Illuminate \Database \Eloquent \Concerns \HasUuids ;
89use Illuminate \Database \Eloquent \Factories \HasFactory ;
910use Illuminate \Database \Eloquent \Model ;
1011use Illuminate \Database \Eloquent \SoftDeletes ;
1112
13+
1214final class InboundWebhook extends Model
1315{
1416 use HasFactory;
@@ -30,4 +32,9 @@ protected function casts(): array
3032 'source ' => config ('filament-webhooks.providers_enum ' ),
3133 ];
3234 }
35+
36+ protected static function newFactory (): InboundWebhookFactory
37+ {
38+ return InboundWebhookFactory::new ();
39+ }
3340}
You can’t perform that action at this time.
0 commit comments