Skip to content

Commit

Permalink
Move these
Browse files Browse the repository at this point in the history
Move List/Create to their own pages to follow the flow of the other resources.
  • Loading branch information
notAreYouScared committed Oct 28, 2024
1 parent 1a3dc5c commit 156e11d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
45 changes: 2 additions & 43 deletions app/Filament/Resources/WebhookResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
}
}

0 comments on commit 156e11d

Please sign in to comment.