Skip to content

Commit

Permalink
Merge pull request #42 from emilhorlyck/enable-navigation-with-closure
Browse files Browse the repository at this point in the history
Enable navigation with closure
  • Loading branch information
croustibat authored Jul 4, 2024
2 parents 2a1d6c5 + 3b1766c commit 3e9af0e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ This is a package to monitor background jobs for FilamentPHP. It is inspired by

Check your filamentPHP version before installing:

| Version | FilamentPHP | PHP |
|---------|-------------|-------------------------|
| 1.* | 2.* | 8.1.* |
| 2.* | 3.* | 8.1.* \| 8.2.* |
| Version | FilamentPHP | PHP |
| ------- | ----------- | -------------- |
| 1.* | 2.* | 8.1.* |
| 2.* | 3.* | 8.1.* \| 8.2.* |


Install the package via composer:
Expand Down Expand Up @@ -149,6 +149,33 @@ Then you can call your Job with the following code:
}
```

### Enabling navigation


````php
// AdminPanelProvider.php
->plugins([
// ...
FilamentJobsMonitorPlugin::make()
->enableNavigation(),
])
````

Or you can use a closure to enable navigation only for specific users:

```php

// AdminPanelProvider.php
->plugins([
// ...
FilamentJobsMonitorPlugin::make()
->enableNavigation(
fn () => auth()->user()->can('view_queue_job') || auth()->user()->can('view_any_queue_job)'),
),
])
```


## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
8 changes: 4 additions & 4 deletions src/FilamentJobsMonitorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FilamentJobsMonitorPlugin implements Plugin
/**
* The resource navigation status.
*/
protected ?bool $navigation = null;
protected bool|Closure $navigation = true;

/**
* The resource cluster.
Expand Down Expand Up @@ -247,15 +247,15 @@ public function navigationCountBadge(bool $navigationCountBadge = true): static
*/
public function shouldRegisterNavigation(): bool
{
return $this->navigation ?? config('filament-jobs-monitor.resources.enabled');
return $this->evaluate($this->navigation) === true ?? config('filament-jobs-monitor.resources.enabled');
}

/**
* Enable the resource navigation.
*/
public function enableNavigation(bool $status = true): static
public function enableNavigation(bool|Closure $callback = true): static
{
$this->navigation = $status;
$this->navigation = $callback;

return $this;
}
Expand Down

0 comments on commit 3e9af0e

Please sign in to comment.