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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
1 change: 1 addition & 0 deletions config/filament-webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@

'model' => InboundWebhook::class,
'providers_enum' => InboundWebhookSource::class,
'view_any' => true,
];
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,4 +77,16 @@
{
return [];
}

public static function getWidgets(): array
{
return [

Check failure on line 83 in src/Filament/Admin/Resources/InboundWebhook/InboundWebhookResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\InboundWebhookResource::getWidgets() should return array<class-string<Filament\Widgets\Widget>> but returns array{Filament\Widgets\WidgetConfiguration}.
InboundWebhookStatsBySource::make(),
];
}

public static function canViewAny(): bool
{
return config('filament-webhooks.view_any', true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -54,4 +46,11 @@ public function table(Table $table): Table
]),
]);
}

protected function getHeaderWidgets(): array
{
return [
InboundWebhookStatsBySource::make(),
];
}
}
7 changes: 5 additions & 2 deletions src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

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
final class InboundWebhookStatsBySource extends StatsOverviewWidget
{
protected function getStats(): array
{
Expand All @@ -22,11 +24,12 @@ private function getInboundWebhooksStats(): array
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}%")
$stats[] = Stat::make("{$source->name}", "{$percentage}%")
->descriptionIcon($source->getIcon())
->description("{$count} de {$totalWebhooks} webhooks")
->color($source->getColor());
}

return $stats;
}
}
5 changes: 0 additions & 5 deletions src/FilamentWebhookPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

public function boot(Panel $panel): void {}
Expand Down
11 changes: 5 additions & 6 deletions src/Models/InboundWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


final class InboundWebhook extends Model
{
use HasFactory;
Expand All @@ -24,6 +23,11 @@ final class InboundWebhook extends Model
'payload',
];

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

protected function casts(): array
{
return [
Expand All @@ -32,9 +36,4 @@ protected function casts(): array
'source' => config('filament-webhooks.providers_enum'),
];
}

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