Skip to content

Commit af12f8f

Browse files
committed
wip
1 parent 215393f commit af12f8f

8 files changed

Lines changed: 141 additions & 67 deletions

File tree

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 3 additions & 3 deletions
Loading

resources/views/livewire/tools.blade.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Livewire/Components/Tools.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Panel/Actions/ToolsAction.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
}

src/ToolsPlugin.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace Backstage\Tools;
44

5-
use Backstage\Tools\Http\Middleware\AuthorizeToolsMiddleware;
6-
use Backstage\Tools\Http\Middleware\MustBeLocalMiddleware;
75
use Closure;
8-
use Filament\Contracts\Plugin;
96
use Filament\Panel;
7+
use Filament\Contracts\Plugin;
8+
use Illuminate\Support\Facades\Route;
9+
use Backstage\Tools\Panel\Actions\ToolsAction;
1010
use Filament\Support\Concerns\EvaluatesClosures;
11-
use Filament\View\PanelsRenderHook;
12-
use Illuminate\Support\Facades\Blade;
11+
use Backstage\Tools\Http\Middleware\MustBeLocalMiddleware;
12+
use Backstage\Tools\Http\Middleware\AuthorizeToolsMiddleware;
13+
use Opcodes\LogViewer\Http\Controllers\IndexController;
1314

1415
class ToolsPlugin implements Plugin
1516
{
@@ -27,6 +28,7 @@ public function register(Panel $panel): void
2728
app()->register(\Backstage\Tools\Providers\HorizonServiceProvider::class);
2829
app()->register(\Backstage\Tools\Providers\PulseServiceProvider::class);
2930
app()->register(\Backstage\Tools\Providers\TelescopeServiceProvider::class);
31+
// app()->register(\Backstage\Tools\Providers\LogViewerServiceProvider::class);
3032

3133
if (! empty($panel->getPath())) {
3234
config([
@@ -68,10 +70,16 @@ public function register(Panel $panel): void
6870
],
6971
]);
7072

71-
$panel->renderHook(
72-
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
73-
fn (): string => Blade::render('@livewire(\'backstage/tools::tools\')'),
74-
);
73+
config([
74+
'log-viewer' => [
75+
'path' => $panel->getPath() . '/logs',
76+
]
77+
]);
78+
79+
$panel->userMenuItems([
80+
ToolsAction::make(),
81+
82+
]);
7583
}
7684

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

src/ToolsServiceProvider.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
use Backstage\Tools\Commands\ToolsCommand;
66
use Backstage\Tools\Testing\TestsTools;
7+
use BladeUI\Icons\Factory;
78
use Filament\Support\Assets\AlpineComponent;
89
use Filament\Support\Assets\Asset;
910
use Filament\Support\Assets\Css;
1011
use Filament\Support\Assets\Js;
1112
use Filament\Support\Facades\FilamentAsset;
12-
use Filament\Support\Facades\FilamentIcon;
13+
use Illuminate\Contracts\Container\Container;
1314
use Illuminate\Filesystem\Filesystem;
1415
use Livewire\Features\SupportTesting\Testable;
15-
use Livewire\Livewire;
1616
use Spatie\LaravelPackageTools\Commands\InstallCommand;
1717
use Spatie\LaravelPackageTools\Package;
1818
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -88,8 +88,11 @@ public function packageBooted(): void
8888
$this->getAssetPackageName()
8989
);
9090

91-
// Icon Registration
92-
FilamentIcon::register($this->getIcons());
91+
$this->callAfterResolving(Factory::class, function (Factory $factory, Container $container) {
92+
$factory->add('tools', array_merge(['path' => __DIR__ . '/../resources/svg'], [
93+
'prefix' => 'tools',
94+
]));
95+
});
9396

9497
// Handle Stubs
9598
if (app()->runningInConsole()) {
@@ -102,8 +105,6 @@ public function packageBooted(): void
102105

103106
// Testing
104107
Testable::mixin(new TestsTools);
105-
106-
Livewire::component('backstage/tools::tools', \Backstage\Tools\Livewire\Components\Tools::class);
107108
}
108109

109110
protected function getAssetPackageName(): ?string

0 commit comments

Comments
 (0)