Skip to content

Commit 6ff9466

Browse files
committed
feat: add webhook volume timeline chart widget
Line chart showing daily webhook count over the last 30 days. Registered on the list page header alongside the existing stats widget. Uses configurable model from config.
1 parent c99d53a commit 6ff9466

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/Filament/Admin/Resources/InboundWebhook/InboundWebhookResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages\ListInboundWebhooks;
99
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages\ViewInboundWebhook;
1010
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
11+
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookTimeline;
1112
use Basement\Webhooks\Models\InboundWebhook;
1213
use Filament\Resources\Resource;
1314
use 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

src/Filament/Admin/Resources/InboundWebhook/Pages/ListInboundWebhooks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Basement\Webhooks\Events\InboundWebhookReceived;
1010
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\InboundWebhookResource;
1111
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
12+
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookTimeline;
1213
use Basement\Webhooks\Models\InboundWebhook;
1314
use Filament\Actions\Action;
1415
use Filament\Actions\ActionGroup;
@@ -173,6 +174,7 @@ protected function getHeaderWidgets(): array
173174
{
174175
return [
175176
InboundWebhookStatsBySource::make(),
177+
InboundWebhookTimeline::make(),
176178
];
177179
}
178180
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

0 commit comments

Comments
 (0)