File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88use Basement \Webhooks \Filament \Admin \Resources \InboundWebhook \Pages \ListInboundWebhooks ;
99use Basement \Webhooks \Filament \Admin \Resources \InboundWebhook \Pages \ViewInboundWebhook ;
1010use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookStatsBySource ;
11+ use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookTimeline ;
1112use Basement \Webhooks \Models \InboundWebhook ;
1213use Filament \Resources \Resource ;
1314use Filament \Support \Icons \Heroicon ;
@@ -92,6 +93,7 @@ public static function getWidgets(): array
9293 {
9394 return [
9495 InboundWebhookStatsBySource::class,
96+ InboundWebhookTimeline::class,
9597 ];
9698 }
9799
Original file line number Diff line number Diff line change 99use Basement \Webhooks \Events \InboundWebhookReceived ;
1010use Basement \Webhooks \Filament \Admin \Resources \InboundWebhook \InboundWebhookResource ;
1111use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookStatsBySource ;
12+ use Basement \Webhooks \Filament \Admin \Widgets \InboundWebhookTimeline ;
1213use Basement \Webhooks \Models \InboundWebhook ;
1314use Filament \Actions \Action ;
1415use Filament \Actions \ActionGroup ;
@@ -173,6 +174,7 @@ protected function getHeaderWidgets(): array
173174 {
174175 return [
175176 InboundWebhookStatsBySource::make (),
177+ InboundWebhookTimeline::make (),
176178 ];
177179 }
178180}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Basement \Webhooks \Filament \Admin \Widgets ;
6+
7+ use Basement \Webhooks \Models \InboundWebhook ;
8+ use Filament \Widgets \ChartWidget ;
9+ use Illuminate \Support \Carbon ;
10+
11+ final class InboundWebhookTimeline extends ChartWidget
12+ {
13+ protected ?string $ heading = 'Webhook Volume (Last 30 Days) ' ;
14+
15+ protected string $ color = 'primary ' ;
16+
17+ protected function getType (): string
18+ {
19+ return 'line ' ;
20+ }
21+
22+ protected function getData (): array
23+ {
24+ /** @var class-string<InboundWebhook> $modelClass */
25+ $ modelClass = config ('filament-webhooks.model ' , InboundWebhook::class);
26+
27+ $ startDate = Carbon::now ()->subDays (29 )->startOfDay ();
28+
29+ $ counts = $ modelClass ::query ()
30+ ->where ('created_at ' , '>= ' , $ startDate )
31+ ->selectRaw ('DATE(created_at) as date, COUNT(*) as total ' )
32+ ->groupBy ('date ' )
33+ ->orderBy ('date ' )
34+ ->pluck ('total ' , 'date ' );
35+
36+ $ labels = [];
37+ $ data = [];
38+
39+ for ($ i = 0 ; $ i < 30 ; $ i ++) {
40+ $ date = $ startDate ->copy ()->addDays ($ i );
41+ $ key = $ date ->format ('Y-m-d ' );
42+ $ labels [] = $ date ->format ('M d ' );
43+ $ data [] = (int ) ($ counts [$ key ] ?? 0 );
44+ }
45+
46+ return [
47+ 'datasets ' => [
48+ [
49+ 'label ' => 'Webhooks ' ,
50+ 'data ' => $ data ,
51+ ],
52+ ],
53+ 'labels ' => $ labels ,
54+ ];
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments