diff --git a/packages/panels/resources/views/components/sidebar/group.blade.php b/packages/panels/resources/views/components/sidebar/group.blade.php index 1d81af574e..43b3c61323 100644 --- a/packages/panels/resources/views/components/sidebar/group.blade.php +++ b/packages/panels/resources/views/components/sidebar/group.blade.php @@ -66,10 +66,6 @@ class="fi-sidebar-group-items flex flex-col gap-y-1" > @foreach ($items as $item) - @if ($item->isHidden()) - @continue - @endif - */ protected array $groups = []; - /** @var NavigationItem[] */ + /** @var array */ protected array $items = []; /** @@ -66,18 +67,32 @@ class NavigationBuilder */ public function getNavigation(): array { - $navigation = collect(); + $items = array_filter( + $this->items, + fn (NavigationItem $item): bool => $item->isVisible(), + ); - $items = $this->items; + return collect($this->groups) + ->filter(function (NavigationGroup $group): bool { + $visibleGroupItems = array_filter( + $group->getItems(), + fn (NavigationItem $item): bool => $item->isVisible(), + ); - if (count($items)) { - $navigation->push( - NavigationGroup::make()->items($items), - ); - } + if (empty($visibleGroupItems)) { + return false; + } - return $navigation - ->merge($this->groups) + $group->items($visibleGroupItems); + + return true; + }) + ->when( + count($items), + fn (Collection $groups): Collection => $groups->prepend( + NavigationGroup::make()->items($items), + ), + ) ->all(); } } diff --git a/tests/src/Panels/Navigation/NavigationBuilderTest.php b/tests/src/Panels/Navigation/NavigationBuilderTest.php index 5189edee15..16925aef38 100644 --- a/tests/src/Panels/Navigation/NavigationBuilderTest.php +++ b/tests/src/Panels/Navigation/NavigationBuilderTest.php @@ -105,50 +105,3 @@ it('can register navigation groups individually', function () { ->each->toBeInstanceOf(NavigationItem::class), ); }); - -it('can register navigation groups with hidden items', function () { - Filament::getCurrentPanel()->navigation(function (NavigationBuilder $navigation): NavigationBuilder { - return $navigation - ->items([ - NavigationItem::make('Products') - ->visible(false) - ->label('Products'), - NavigationItem::make('Orders') - ->hidden(fn (): bool => true) - ->label('Orders'), - ...Dashboard::getNavigationItems(), - ...UserResource::getNavigationItems(), - ...Settings::getNavigationItems(), - ]); - }); - - expect(Filament::getNavigation()) - ->sequence( - fn ($group) => $group - ->toBeInstanceOf(NavigationGroup::class) - ->getLabel()->toBeNull() - ->getItems() - ->sequence( - fn ($item) => $item - ->getLabel()->toBe('Products') - ->isVisible()->toBeFalse(), - fn ($item) => $item - ->getLabel()->toBe('Orders') - ->isHidden()->toBeTrue(), - fn ($item) => $item - ->getLabel()->toBe('Dashboard') - ->getIcon()->toBe('heroicon-o-home') - ->isVisible()->toBeTrue(), - fn ($item) => $item - ->getLabel()->toBe('Users') - ->getIcon()->toBe('heroicon-o-user') - ->isHidden()->toBeFalse(), - fn ($item) => $item - ->getLabel()->toBe('Settings') - ->getIcon()->toBe('heroicon-o-cog-6-tooth') - ->isVisible()->toBeTrue() - ->isHidden()->toBeFalse(), - ) - ->each->toBeInstanceOf(NavigationItem::class), - ); -});