|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Backstage\Tools\Panel\Actions; |
| 4 | + |
| 5 | +use BackedEnum; |
| 6 | +use Filament\Actions\Action; |
| 7 | +use Filament\Schemas\Schema; |
| 8 | +use Backstage\Tools\ToolsPlugin; |
| 9 | +use Filament\Infolists\Components\TextEntry; |
| 10 | +use Illuminate\Support\Facades\App; |
| 11 | +use Filament\Support\Icons\Heroicon; |
| 12 | +use Filament\Schemas\Components\Grid; |
| 13 | +use Filament\Support\Enums\Alignment; |
| 14 | +use Illuminate\Support\Facades\Blade; |
| 15 | +use Filament\Schemas\Components\Section; |
| 16 | +use Filament\Support\Colors\Color; |
| 17 | +use Illuminate\Contracts\Support\Htmlable; |
| 18 | +use Illuminate\Support\Facades\Route; |
| 19 | +use Illuminate\Support\HtmlString; |
| 20 | +use Opcodes\LogViewer\Facades\LogViewer; |
| 21 | + |
| 22 | +class ToolsAction extends Action |
| 23 | +{ |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + parent::setUp(); |
| 27 | + |
| 28 | + $this->icon(fn(): BackedEnum => Heroicon::OutlinedGlobeAlt); |
| 29 | + |
| 30 | + $this->modal(fn() => true); |
| 31 | + |
| 32 | + $this->modalIcon(fn(): BackedEnum => $this->getIcon()); |
| 33 | + |
| 34 | + $this->modalHeading(fn(): string => __('Tools')); |
| 35 | + |
| 36 | + $this->modalDescription(fn(): string => __('Access various tools for application monitoring, health, and debugging.')); |
| 37 | + |
| 38 | + $this->modalSubmitAction(fn(Action $action) => $action->visible(false)); |
| 39 | + |
| 40 | + $this->modalCancelAction(fn(Action $action): Action => $action->icon(fn(): BackedEnum => Heroicon::XMark)->label(fn() => __('Close'))); |
| 41 | + |
| 42 | + $this->modalFooterActionsAlignment(Alignment::Center); |
| 43 | + } |
| 44 | + |
| 45 | + public static function getDefaultName(): ?string |
| 46 | + { |
| 47 | + return 'tools'; |
| 48 | + } |
| 49 | + |
| 50 | + public function getSchema(Schema $schema): ?Schema |
| 51 | + { |
| 52 | + $tools = [ |
| 53 | + [ |
| 54 | + 'color' => Color::hex('#7746ec'), |
| 55 | + 'description' => __('Monitor and manage queued jobs and background tasks in your Laravel application.'), |
| 56 | + 'icon' => 'tools-horizon', |
| 57 | + 'label' => 'Horizon', |
| 58 | + 'route' => 'horizon.index', |
| 59 | + 'visible' => ToolsPlugin::get()->isAccessible(), |
| 60 | + ], |
| 61 | + [ |
| 62 | + 'color' => Color::hex('#a855f7'), |
| 63 | + 'description' => __('Track real-time performance, resource usage, and system health of your application.'), |
| 64 | + 'icon' => 'tools-pulse', |
| 65 | + 'label' => 'Pulse', |
| 66 | + 'route' => 'pulse', |
| 67 | + 'visible' => ToolsPlugin::get()->isAccessible(), |
| 68 | + ], |
| 69 | + [ |
| 70 | + 'color' => Color::hex('#4040c8'), |
| 71 | + 'description' => __('Debug your application with deep insights into requests, jobs, queries, and more.'), |
| 72 | + 'icon' => 'tools-telescope', |
| 73 | + 'label' => 'Telescope', |
| 74 | + 'route' => 'telescope', |
| 75 | + 'disabled' => App::environment('production'), |
| 76 | + 'visible' => ToolsPlugin::get()->isAccessible() && App::isLocal(), |
| 77 | + ], |
| 78 | + ]; |
| 79 | + |
| 80 | + $toolSections = collect($tools) |
| 81 | + ->filter(fn($tool): bool => $tool['visible']) |
| 82 | + ->map(function ($tool): Section { |
| 83 | + return Section::make() |
| 84 | + ->heading(fn(): string => $tool['label']) |
| 85 | + ->icon(fn() => $tool['icon']) |
| 86 | + ->iconColor(fn(): array => $tool['color']) |
| 87 | + ->columnSpan(fn(): int => 1) |
| 88 | + ->columns(1) |
| 89 | + ->headerActions([ |
| 90 | + Action::make('open') |
| 91 | + ->hiddenLabel() |
| 92 | + ->outlined() |
| 93 | + ->color(fn(): array => $tool['color']) |
| 94 | + ->icon(fn(): BackedEnum => Heroicon::ArrowTopRightOnSquare) |
| 95 | + ->url(fn(): string => Route::has($tool['route']) ? route($tool['route']) : url($tool['route']), fn(): bool => true) |
| 96 | + ]) |
| 97 | + ->schema([ |
| 98 | + TextEntry::make('label') |
| 99 | + ->hiddenLabel() |
| 100 | + ->state(fn(): string => $tool['description']), |
| 101 | + ]); |
| 102 | + }); |
| 103 | + |
| 104 | + return $schema->schema([ |
| 105 | + Grid::make($toolSections->count()) |
| 106 | + ->schema([ |
| 107 | + ...$toolSections |
| 108 | + ]) |
| 109 | + ->columnSpanFull() |
| 110 | + ]); |
| 111 | + } |
| 112 | +} |
0 commit comments