diff --git a/README.md b/README.md index e311d44..d779249 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ The package auto-registers its service provider via the `extra.laravel.providers ### Migrations This package discovers and loads its migrations. Run your app migrations after installing: +```bash +php artisan vendor:publish --tag="filament-webhooks-migrations" +``` + ```bash php artisan migrate ``` diff --git a/config/filament-webhooks.php b/config/filament-webhooks.php index d80d367..04ee23c 100644 --- a/config/filament-webhooks.php +++ b/config/filament-webhooks.php @@ -15,4 +15,5 @@ 'model' => InboundWebhook::class, 'providers_enum' => InboundWebhookSource::class, + 'view_any' => true, ]; diff --git a/src/Filament/Admin/Resources/InboundWebhook/InboundWebhookResource.php b/src/Filament/Admin/Resources/InboundWebhook/InboundWebhookResource.php index 46bcd0e..00f0bc0 100644 --- a/src/Filament/Admin/Resources/InboundWebhook/InboundWebhookResource.php +++ b/src/Filament/Admin/Resources/InboundWebhook/InboundWebhookResource.php @@ -7,6 +7,7 @@ use BackedEnum; use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages\ListInboundWebhooks; use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages\ViewInboundWebhook; +use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource; use Basement\Webhooks\Models\InboundWebhook; use Filament\Resources\Resource; use Filament\Support\Icons\Heroicon; @@ -76,4 +77,16 @@ public static function getGloballySearchableAttributes(): array { return []; } + + public static function getWidgets(): array + { + return [ + InboundWebhookStatsBySource::make(), + ]; + } + + public static function canViewAny(): bool + { + return config('filament-webhooks.view_any', true); + } } diff --git a/src/Filament/Admin/Resources/InboundWebhook/Pages/ListInboundWebhooks.php b/src/Filament/Admin/Resources/InboundWebhook/Pages/ListInboundWebhooks.php index 407b99e..aa5da64 100644 --- a/src/Filament/Admin/Resources/InboundWebhook/Pages/ListInboundWebhooks.php +++ b/src/Filament/Admin/Resources/InboundWebhook/Pages/ListInboundWebhooks.php @@ -5,7 +5,6 @@ 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; @@ -22,13 +21,6 @@ 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 @@ -54,4 +46,11 @@ public function table(Table $table): Table ]), ]); } + + protected function getHeaderWidgets(): array + { + return [ + InboundWebhookStatsBySource::make(), + ]; + } } diff --git a/src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php b/src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php index f833cdb..2671b63 100644 --- a/src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php +++ b/src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php @@ -1,5 +1,7 @@ value)->count(); $percentage = $totalWebhooks > 0 ? round(($count / $totalWebhooks) * 100, 2) : 0; - $stats[] = Stat::make("{$source->name}","{$percentage}%") + $stats[] = Stat::make("{$source->name}", "{$percentage}%") ->descriptionIcon($source->getIcon()) ->description("{$count} de {$totalWebhooks} webhooks") ->color($source->getColor()); } + return $stats; } } diff --git a/src/FilamentWebhookPlugin.php b/src/FilamentWebhookPlugin.php index 88b1201..e35ca0e 100644 --- a/src/FilamentWebhookPlugin.php +++ b/src/FilamentWebhookPlugin.php @@ -5,8 +5,6 @@ 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; @@ -27,9 +25,6 @@ public function register(Panel $panel): void $panel->resources([ InboundWebhookResource::class, ]); - $panel->widgets([ - InboundWebhookStatsBySource::make(), - ]); } public function boot(Panel $panel): void {} diff --git a/src/Models/InboundWebhook.php b/src/Models/InboundWebhook.php index a90cfb6..51ba350 100644 --- a/src/Models/InboundWebhook.php +++ b/src/Models/InboundWebhook.php @@ -10,7 +10,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; - final class InboundWebhook extends Model { use HasFactory; @@ -24,6 +23,11 @@ final class InboundWebhook extends Model 'payload', ]; + protected static function newFactory(): InboundWebhookFactory + { + return InboundWebhookFactory::new(); + } + protected function casts(): array { return [ @@ -32,9 +36,4 @@ protected function casts(): array 'source' => config('filament-webhooks.providers_enum'), ]; } - - protected static function newFactory(): InboundWebhookFactory - { - return InboundWebhookFactory::new(); - } }