From 156e11d17b0ed59d7813002d7de64591db580fa4 Mon Sep 17 00:00:00 2001 From: notCharles Date: Mon, 28 Oct 2024 18:23:02 -0400 Subject: [PATCH] Move these Move List/Create to their own pages to follow the flow of the other resources. --- app/Filament/Resources/WebhookResource.php | 45 +------------------ .../Pages/CreateWebhookConfiguration.php | 25 +++++++++++ .../Pages/ListWebhookConfigurations.php | 35 ++++++++++++++- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/app/Filament/Resources/WebhookResource.php b/app/Filament/Resources/WebhookResource.php index 804c0e078a..6ce5c963c8 100644 --- a/app/Filament/Resources/WebhookResource.php +++ b/app/Filament/Resources/WebhookResource.php @@ -4,13 +4,7 @@ use App\Filament\Resources\WebhookResource\Pages; use App\Models\WebhookConfiguration; -use Filament\Forms\Components\CheckboxList; -use Filament\Forms\Components\TextInput; -use Filament\Forms\Form; use Filament\Resources\Resource; -use Filament\Tables; -use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Table; class WebhookResource extends Resource { @@ -22,44 +16,9 @@ class WebhookResource extends Resource protected static ?string $label = 'Webhooks'; - public static function form(Form $form): Form + public static function getNavigationBadge(): ?string { - return $form - ->schema([ - TextInput::make('endpoint') - ->activeUrl() - ->required(), - TextInput::make('description') - ->required(), - CheckboxList::make('events') - ->lazy() - ->options(fn () => WebhookConfiguration::filamentCheckboxList()) - ->searchable() - ->bulkToggleable() - ->columns(3) - ->columnSpanFull() - ->gridDirection('row') - ->required(), - ]); - } - - public static function table(Table $table): Table - { - return $table - ->columns([ - TextColumn::make('description'), - TextColumn::make('endpoint'), - ]) - ->actions([ - Tables\Actions\EditAction::make(), - ]); - } - - public static function getRelations(): array - { - return [ - // - ]; + return static::getModel()::count() ?: null; } public static function getPages(): array diff --git a/app/Filament/Resources/WebhookResource/Pages/CreateWebhookConfiguration.php b/app/Filament/Resources/WebhookResource/Pages/CreateWebhookConfiguration.php index 96f45742c5..7d93801149 100644 --- a/app/Filament/Resources/WebhookResource/Pages/CreateWebhookConfiguration.php +++ b/app/Filament/Resources/WebhookResource/Pages/CreateWebhookConfiguration.php @@ -3,9 +3,34 @@ namespace App\Filament\Resources\WebhookResource\Pages; use App\Filament\Resources\WebhookResource; +use App\Models\WebhookConfiguration; +use Filament\Forms\Components\CheckboxList; +use Filament\Forms\Components\TextInput; +use Filament\Forms\Form; use Filament\Resources\Pages\CreateRecord; class CreateWebhookConfiguration extends CreateRecord { protected static string $resource = WebhookResource::class; + + public function form(Form $form): Form + { + return $form + ->schema([ + TextInput::make('endpoint') + ->activeUrl() + ->required(), + TextInput::make('description') + ->required(), + CheckboxList::make('events') + ->lazy() + ->options(fn () => WebhookConfiguration::filamentCheckboxList()) + ->searchable() + ->bulkToggleable() + ->columns(3) + ->columnSpanFull() + ->gridDirection('row') + ->required(), + ]); + } } diff --git a/app/Filament/Resources/WebhookResource/Pages/ListWebhookConfigurations.php b/app/Filament/Resources/WebhookResource/Pages/ListWebhookConfigurations.php index 40e67dfd0f..88bb40f741 100644 --- a/app/Filament/Resources/WebhookResource/Pages/ListWebhookConfigurations.php +++ b/app/Filament/Resources/WebhookResource/Pages/ListWebhookConfigurations.php @@ -3,17 +3,50 @@ namespace App\Filament\Resources\WebhookResource\Pages; use App\Filament\Resources\WebhookResource; +use App\Models\WebhookConfiguration; use Filament\Actions; use Filament\Resources\Pages\ListRecords; +use Filament\Tables\Actions\CreateAction; +use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Table; +use Filament\Tables\Actions\EditAction; +use Filament\Tables\Actions\DeleteAction; class ListWebhookConfigurations extends ListRecords { protected static string $resource = WebhookResource::class; + public function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('description') + ->label('Description'), + TextColumn::make('endpoint') + ->label('Endpoint'), + ]) + ->actions([ + DeleteAction::make() + ->label('Delete Webhook'), + EditAction::make() + ->label('Edit Webhook'), + ]) + ->emptyStateIcon('tabler-webhook') + ->emptyStateDescription('') + ->emptyStateHeading('No Webhooks') + ->emptyStateActions([ + CreateAction::make('create') + ->label('Create Webhook') + ->button(), + ]); + } + protected function getHeaderActions(): array { return [ - Actions\CreateAction::make(), + Actions\CreateAction::make() + ->label('Create Webhook') + ->hidden(fn () => WebhookConfiguration::count() <= 0), ]; } }