From e999ccba7c2de77e554a662c8f08cc6cf2a31b78 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Tue, 20 Jan 2026 23:46:05 -0500 Subject: [PATCH 1/2] implements #6: Add nav label and group customization --- README.md | 47 ++++++++++- src/CommandRunnerPlugin.php | 78 +++++++++++++++++++ .../CommandRuns/CommandRunResource.php | 32 +++++++- 3 files changed, 151 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 89d1b0c..420a16d 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,48 @@ $panel->plugin(CommandRunnerPlugin::make()); ## Customizations -1. Command Validation +### 1. Authorization + +You can restrict access to this plugin using the `authorize` method. This accepts a boolean or a closure that returns a boolean. + +```php +CommandRunnerPlugin::make()->authorize(fn () => auth()->user()->can('view-command-runner')) +``` + +### 2. Navigation Group + +You can change the navigation group using the `navigationGroup` method. This accepts a string, `UnitEnum`. + +```php +CommandRunnerPlugin::make()->navigationGroup('System') +``` + +### 3. Navigation Label + +You can customize the navigation label using the `navigationLabel` method. + +```php +CommandRunnerPlugin::make()->navigationLabel('Command Runner') +``` + +### 4. Navigation Icon + +You can change the navigation icon using the `navigationIcon` method. This accepts a Heroicon string or a `Heroicon` enum value. + +```php +CommandRunnerPlugin::make()->navigationIcon('heroicon-o-exclamation-triangle') +``` + +### 5. Navigation Sort Order + +You can change the navigation sort order using the `navigationSort` method. + +```php +CommandRunnerPlugin::make()->navigationSort(10) +``` + + +### 6. Command Validation You can define custom validation logic using the validateCommand() method. This is useful for restricting which commands can be run: @@ -81,7 +122,7 @@ $panel->plugin( ); ``` -2. Delete Command History +### 7. Delete Command History Control who can delete command history entries using a boolean or closure with `canDeleteCommandHistory()`: @@ -91,7 +132,7 @@ $panel->plugin( ); ``` -3. Purge Old Command History +### 8. Purge Old Command History Schedule the following artisan command to purge command history entries daily: diff --git a/src/CommandRunnerPlugin.php b/src/CommandRunnerPlugin.php index 7fe6662..4cc7716 100644 --- a/src/CommandRunnerPlugin.php +++ b/src/CommandRunnerPlugin.php @@ -5,18 +5,47 @@ use BinaryBuilds\CommandRunner\Resources\CommandRuns\CommandRunResource; use Filament\Contracts\Plugin; use Filament\Panel; +use Filament\Support\Icons\Heroicon; +use UnitEnum; +use BackedEnum; +use Closure; +use Filament\Support\Concerns\EvaluatesClosures; class CommandRunnerPlugin implements Plugin { + use EvaluatesClosures; + private $validationRule = null; private $deleteHistory = true; + private bool | Closure $authorized = true; + + private string | BackedEnum | null $navigationIcon = HeroIcon::OutlinedCommandLine; + + private string | UnitEnum | null $navigationGroup = 'Settings'; + + private string $navigationLabel = 'Command Runner'; + + private int | Closure $navigationSort = 9999; + public function getId(): string { return 'command-runner'; } + public function authorize(bool | Closure $callback): static + { + $this->authorized = $callback; + + return $this; + } + + public function isAuthorized(): bool + { + return (bool) $this->evaluate($this->authorized); + } + public function validateCommand(callable $commandRule): CommandRunnerPlugin { $this->validationRule = $commandRule; @@ -24,6 +53,55 @@ public function validateCommand(callable $commandRule): CommandRunnerPlugin return $this; } + public function navigationLabel(string $navigationLabel): static + { + $this->navigationLabel = $navigationLabel; + + return $this; + } + + public function getNavigationLabel(): string + { + return $this->navigationLabel; + } + + public function navigationGroup(string | UnitEnum | null $navigationGroup): static + { + $this->navigationGroup = $navigationGroup; + + return $this; + } + + public function getNavigationGroup(): string + { + return $this->navigationGroup; + } + + public function navigationSort(int | Closure $sort): static + { + $this->navigationSort = $sort; + + return $this; + } + + public function getNavigationSort(): int + { + /** @var int */ + return $this->evaluate($this->navigationSort); + } + + public function navigationIcon(string | BackedEnum | null $navigationIcon): static + { + $this->navigationIcon = $navigationIcon; + + return $this; + } + + public function getNavigationIcon(): string | Heroicon | null + { + return $this->navigationIcon; + } + public function canDeleteCommandHistory(callable | bool $deleteHistory): CommandRunnerPlugin { $this->deleteHistory = $deleteHistory; diff --git a/src/Resources/CommandRuns/CommandRunResource.php b/src/Resources/CommandRuns/CommandRunResource.php index 651e2a9..21a5c95 100644 --- a/src/Resources/CommandRuns/CommandRunResource.php +++ b/src/Resources/CommandRuns/CommandRunResource.php @@ -13,14 +13,42 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; +use BinaryBuilds\CommandRunner\CommandRunnerPlugin; +use UnitEnum; +use BackedEnum; class CommandRunResource extends Resource { protected static ?string $slug = 'command-runner'; + protected static function getPlugin(): CommandRunnerPlugin + { + return CommandRunnerPlugin::get(); + } + public static function getNavigationLabel(): string { - return __('Command Runner'); + return static::getPlugin()->getNavigationLabel(); + } + + public static function canAccess(): bool + { + return static::getPlugin()->isAuthorized(); + } + + public static function getNavigationGroup(): string | UnitEnum | null + { + return static::getPlugin()->getNavigationGroup(); + } + + public static function getNavigationSort(): ?int + { + return static::getPlugin()->getNavigationSort(); + } + + public static function getNavigationIcon(): string | BackedEnum | Heroicon | null + { + return static::getPlugin()->getNavigationIcon(); } public static function getBreadcrumb(): string @@ -30,8 +58,6 @@ public static function getBreadcrumb(): string protected static ?string $model = CommandRun::class; - protected static string | null | \BackedEnum $navigationIcon = Heroicon::OutlinedCommandLine; - public static function infolist(Schema $schema): Schema { return CommandRunInfolist::configure($schema); From b21bf396f6d799cbd6edfdb6afccbc8ecfba84be Mon Sep 17 00:00:00 2001 From: srinathreddydudi <10626045+srinathreddydudi@users.noreply.github.com> Date: Wed, 21 Jan 2026 04:46:26 +0000 Subject: [PATCH 2/2] Fix styling --- src/CommandRunnerPlugin.php | 6 +++--- src/Resources/CommandRuns/CommandRunResource.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CommandRunnerPlugin.php b/src/CommandRunnerPlugin.php index 4cc7716..a5256bf 100644 --- a/src/CommandRunnerPlugin.php +++ b/src/CommandRunnerPlugin.php @@ -2,14 +2,14 @@ namespace BinaryBuilds\CommandRunner; +use BackedEnum; use BinaryBuilds\CommandRunner\Resources\CommandRuns\CommandRunResource; +use Closure; use Filament\Contracts\Plugin; use Filament\Panel; +use Filament\Support\Concerns\EvaluatesClosures; use Filament\Support\Icons\Heroicon; use UnitEnum; -use BackedEnum; -use Closure; -use Filament\Support\Concerns\EvaluatesClosures; class CommandRunnerPlugin implements Plugin { diff --git a/src/Resources/CommandRuns/CommandRunResource.php b/src/Resources/CommandRuns/CommandRunResource.php index 21a5c95..26e3130 100644 --- a/src/Resources/CommandRuns/CommandRunResource.php +++ b/src/Resources/CommandRuns/CommandRunResource.php @@ -2,6 +2,8 @@ namespace BinaryBuilds\CommandRunner\Resources\CommandRuns; +use BackedEnum; +use BinaryBuilds\CommandRunner\CommandRunnerPlugin; use BinaryBuilds\CommandRunner\Models\CommandRun; use BinaryBuilds\CommandRunner\Resources\CommandRuns\Pages\ListCommandRuns; use BinaryBuilds\CommandRunner\Resources\CommandRuns\Pages\RunCommand; @@ -13,9 +15,7 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Filament\Tables\Table; -use BinaryBuilds\CommandRunner\CommandRunnerPlugin; use UnitEnum; -use BackedEnum; class CommandRunResource extends Resource {