Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages;

use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\InboundWebhookResource;
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsByProviderPercentage;
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
Expand All @@ -20,6 +22,13 @@ final class ListInboundWebhooks extends ListRecords
{
protected static string $resource = InboundWebhookResource::class;

protected function getHeaderWidgets(): array
{
return [
InboundWebhookStatsBySource::make(),
];
}

public function table(Table $table): Table
{
return $table
Expand Down
32 changes: 32 additions & 0 deletions src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Basement\Webhooks\Filament\Admin\Widgets;

use Basement\Webhooks\Enums\InboundWebhookSource;
use Basement\Webhooks\Models\InboundWebhook;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class InboundWebhookStatsBySource extends StatsOverviewWidget
{
protected function getStats(): array
{
return $this->getInboundWebhooksStats();
}

private function getInboundWebhooksStats(): array
{
$totalWebhooks = InboundWebhook::count();
$stats = [];

foreach (InboundWebhookSource::cases() as $source) {
$count = InboundWebhook::where('source', $source->value)->count();
$percentage = $totalWebhooks > 0 ? round(($count / $totalWebhooks) * 100, 2) : 0;
$stats[] = Stat::make("{$source->name}","{$percentage}%")
->descriptionIcon($source->getIcon())
->description("{$count} de {$totalWebhooks} webhooks")
->color($source->getColor());
}
return $stats;
}
}
5 changes: 5 additions & 0 deletions src/FilamentWebhookPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Basement\Webhooks;

use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\InboundWebhookResource;
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsByProviderPercentage;
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
use Filament\Contracts\Plugin;
use Filament\Panel;

Expand All @@ -25,6 +27,9 @@ public function register(Panel $panel): void
$panel->resources([
InboundWebhookResource::class,
]);
$panel->widgets([
InboundWebhookStatsBySource::make(),
]);
}

public function boot(Panel $panel): void {}
Expand Down
7 changes: 7 additions & 0 deletions src/Models/InboundWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Basement\Webhooks\Models;

use Basement\Webhooks\Database\Factories\InboundWebhookFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


final class InboundWebhook extends Model
{
use HasFactory;
Expand All @@ -30,4 +32,9 @@ protected function casts(): array
'source' => config('filament-webhooks.providers_enum'),
];
}

protected static function newFactory(): InboundWebhookFactory
{
return InboundWebhookFactory::new();
}
}
Loading