aymanalhattami / filament-page-with-sidebar

Organize pages in the sidebar in order to make navigation between pages more comfortable.
https://github.com/aymanalhattami/filament-page-with-sidebar
MIT License
175 stars 22 forks source link

Allow PageNavigationItem::label closure #20

Closed Thiktak closed 1 year ago

Thiktak commented 1 year ago

Hello,

It's not possible, to use dynamic closure on the label attribute of PageNavigationItem.

    public static function sidebar(Model $record): FilamentPageSidebar
    {
        return FilamentPageSidebar::make()
            ->setTitle($record)
            ->setDescription('Long text')
            ->setNavigationItems([
                PageNavigationItem::make('Dashboard')
                    ->label(fn () => __($record->kind . ' dashboard')) // Dynamic label
                    ->label(fn () => static::getUrl('view', ['record' => $record->id]) );
                    ->icon('heroicon-o-bookmark'),

                PageNavigationItem::make('Organization')
                    ->label('Organization') // Fixed string label
                    ->label(fn () => static::getUrl('org', ['record' => $record->id]) );
                    ->icon('heroicon-o-user-group'),
            ]);
    }

Calling the parent method, to benefit of evaluate method (NavigationItem::getLabel).

image

By the way, maybe evaluate can be used for isHiddenWhen ?

    public function isHiddenWhen(Closure|bool $condition): static
    {
        $this->isHidden = $this->evaluate($condition);

        return $this;
    }
sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Thiktak commented 1 year ago

Added also for FilamentPageSidebar getTitle & getDescription