Skip to content

Commit 19142fa

Browse files
committed
feat: adding flag to see resource
1 parent a898ee6 commit 19142fa

7 files changed

Lines changed: 35 additions & 21 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ The package auto-registers its service provider via the `extra.laravel.providers
3232
### Migrations
3333
This package discovers and loads its migrations. Run your app migrations after installing:
3434

35+
```bash
36+
php artisan vendor:publish --tag="filament-webhooks-migrations"
37+
```
38+
3539
```bash
3640
php artisan migrate
3741
```

config/filament-webhooks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515

1616
'model' => InboundWebhook::class,
1717
'providers_enum' => InboundWebhookSource::class,
18+
'view_any' => true,
1819
];

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use BackedEnum;
88
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages\ListInboundWebhooks;
99
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages\ViewInboundWebhook;
10+
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
1011
use Basement\Webhooks\Models\InboundWebhook;
1112
use Filament\Resources\Resource;
1213
use Filament\Support\Icons\Heroicon;
@@ -76,4 +77,16 @@ public static function getGloballySearchableAttributes(): array
7677
{
7778
return [];
7879
}
80+
81+
public static function getWidgets(): array
82+
{
83+
return [
84+
InboundWebhookStatsBySource::make(),
85+
];
86+
}
87+
88+
public static function canViewAny(): bool
89+
{
90+
return config('filament-webhooks.view_any', true);
91+
}
7992
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\Pages;
66

77
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\InboundWebhookResource;
8-
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsByProviderPercentage;
98
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
109
use Filament\Actions\BulkActionGroup;
1110
use Filament\Actions\DeleteAction;
@@ -22,13 +21,6 @@ final class ListInboundWebhooks extends ListRecords
2221
{
2322
protected static string $resource = InboundWebhookResource::class;
2423

25-
protected function getHeaderWidgets(): array
26-
{
27-
return [
28-
InboundWebhookStatsBySource::make(),
29-
];
30-
}
31-
3224
public function table(Table $table): Table
3325
{
3426
return $table
@@ -54,4 +46,11 @@ public function table(Table $table): Table
5446
]),
5547
]);
5648
}
49+
50+
protected function getHeaderWidgets(): array
51+
{
52+
return [
53+
InboundWebhookStatsBySource::make(),
54+
];
55+
}
5756
}

src/Filament/Admin/Widgets/InboundWebhookStatsBySource.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Basement\Webhooks\Filament\Admin\Widgets;
46

57
use Basement\Webhooks\Enums\InboundWebhookSource;
68
use Basement\Webhooks\Models\InboundWebhook;
79
use Filament\Widgets\StatsOverviewWidget;
810
use Filament\Widgets\StatsOverviewWidget\Stat;
911

10-
class InboundWebhookStatsBySource extends StatsOverviewWidget
12+
final class InboundWebhookStatsBySource extends StatsOverviewWidget
1113
{
1214
protected function getStats(): array
1315
{
@@ -22,11 +24,12 @@ private function getInboundWebhooksStats(): array
2224
foreach (InboundWebhookSource::cases() as $source) {
2325
$count = InboundWebhook::where('source', $source->value)->count();
2426
$percentage = $totalWebhooks > 0 ? round(($count / $totalWebhooks) * 100, 2) : 0;
25-
$stats[] = Stat::make("{$source->name}","{$percentage}%")
27+
$stats[] = Stat::make("{$source->name}", "{$percentage}%")
2628
->descriptionIcon($source->getIcon())
2729
->description("{$count} de {$totalWebhooks} webhooks")
2830
->color($source->getColor());
2931
}
32+
3033
return $stats;
3134
}
3235
}

src/FilamentWebhookPlugin.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace Basement\Webhooks;
66

77
use Basement\Webhooks\Filament\Admin\Resources\InboundWebhook\InboundWebhookResource;
8-
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsByProviderPercentage;
9-
use Basement\Webhooks\Filament\Admin\Widgets\InboundWebhookStatsBySource;
108
use Filament\Contracts\Plugin;
119
use Filament\Panel;
1210

@@ -27,9 +25,6 @@ public function register(Panel $panel): void
2725
$panel->resources([
2826
InboundWebhookResource::class,
2927
]);
30-
$panel->widgets([
31-
InboundWebhookStatsBySource::make(),
32-
]);
3328
}
3429

3530
public function boot(Panel $panel): void {}

src/Models/InboundWebhook.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Illuminate\Database\Eloquent\Model;
1111
use Illuminate\Database\Eloquent\SoftDeletes;
1212

13-
1413
final class InboundWebhook extends Model
1514
{
1615
use HasFactory;
@@ -24,6 +23,11 @@ final class InboundWebhook extends Model
2423
'payload',
2524
];
2625

26+
protected static function newFactory(): InboundWebhookFactory
27+
{
28+
return InboundWebhookFactory::new();
29+
}
30+
2731
protected function casts(): array
2832
{
2933
return [
@@ -32,9 +36,4 @@ protected function casts(): array
3236
'source' => config('filament-webhooks.providers_enum'),
3337
];
3438
}
35-
36-
protected static function newFactory(): InboundWebhookFactory
37-
{
38-
return InboundWebhookFactory::new();
39-
}
4039
}

0 commit comments

Comments
 (0)