mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
wip
This commit is contained in:
@@ -66,10 +66,6 @@
|
||||
class="fi-sidebar-group-items flex flex-col gap-y-1"
|
||||
>
|
||||
@foreach ($items as $item)
|
||||
@if ($item->isHidden())
|
||||
@continue
|
||||
@endif
|
||||
|
||||
<x-filament-panels::sidebar.item
|
||||
:active="$item->isActive()"
|
||||
:active-child-items="$item->isChildItemsActive()"
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
namespace Filament\Navigation;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Traits\Conditionable;
|
||||
|
||||
class NavigationBuilder
|
||||
{
|
||||
use Conditionable;
|
||||
|
||||
/** @var NavigationGroup[] */
|
||||
/** @var array<NavigationGroup> */
|
||||
protected array $groups = [];
|
||||
|
||||
/** @var NavigationItem[] */
|
||||
/** @var array<NavigationItem> */
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user