Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/panels/src/Clusters/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public static function getClusteredComponents(): array
return Filament::getClusteredComponents(static::class);
}

/**
* @return array<string | int, array<class-string> | class-string>
*/
public static function getClusteredComponentsConfigured(): array
{
return Filament::getClusteredComponentsConfigured(static::class);
}

public static function canAccessClusteredComponents(): bool
{
foreach (static::getClusteredComponents() as $component) {
Expand Down
8 changes: 8 additions & 0 deletions packages/panels/src/FilamentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ public function getClusteredComponents(?string $cluster): array
return $this->getCurrentOrDefaultPanel()->getClusteredComponents($cluster);
}

/**
* @return array<string | int, array<class-string> | class-string>
*/
public function getClusteredComponentsConfigured(?string $cluster): array
{
return $this->getCurrentOrDefaultPanel()->getClusteredComponentsConfigured($cluster);
}

/**
* @return array<class-string>
*/
Expand Down
50 changes: 50 additions & 0 deletions packages/panels/src/Pages/Concerns/HasSubNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,56 @@ public function generateNavigationItems(array $components): array
return $items;
}

/**
* @param array<class-string, array<string>> $components
* @return array<NavigationItem>
*/
public function generateNavigationItemsConfigured(array $components): array
{
$parameters = $this->getSubNavigationParameters();

$items = [];

foreach ($components as $component => $configurations) {
foreach ($configurations as $configurationKey) {
Filament::setCurrentResourceConfigurationKey($configurationKey);

$isResourcePage = is_subclass_of($component, ResourcePage::class);

$shouldRegisterNavigation = $isResourcePage ?
$component::shouldRegisterNavigation($parameters) :
$component::shouldRegisterNavigation();

if (! $shouldRegisterNavigation) {
Filament::setCurrentResourceConfigurationKey(null);

continue;
}

$canAccess = $isResourcePage ?
$component::canAccess($parameters) :
$component::canAccess();

if (! $canAccess) {
continue;
}

$pageItems = $isResourcePage ?
$component::getNavigationItems($parameters) :
$component::getNavigationItems();

Filament::setCurrentResourceConfigurationKey(null);

$items = [
...$items,
...$pageItems,
];
}
}

return $items;
}

/**
* @return array<string, mixed>
*/
Expand Down
47 changes: 44 additions & 3 deletions packages/panels/src/Panel/Concerns/HasComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ trait HasComponents
*/
protected array $clusteredComponents = [];

/**
* @var array<class-string<Cluster>, array<class-string, array<string>>>
*/
protected array $clusteredComponentsConfigured = [];

/**
* @var array<class-string>
*/
Expand Down Expand Up @@ -143,14 +148,17 @@ public function pages(array $pages): static
$this->pageConfigurations[$page->page][$page->getKey()] = $page;

$pageClass = $page->page;

$this->registerToClusterConfigured($pageClass, $page->getKey());
} else {
$this->pages[] = $page;

$pageClass = $page;

$this->registerToCluster($pageClass);
}

$this->queueLivewireComponentForRegistration($pageClass);
$this->registerToCluster($pageClass);
}

return $this;
Expand Down Expand Up @@ -182,13 +190,15 @@ public function resources(array $resources): static
$this->resourceConfigurations[$resource->resource][$resource->getKey()] = $resource;

$resourceClass = $resource->resource;

$this->registerToClusterConfigured($resourceClass, $resource->getKey());
} else {
$this->resources[] = $resource;

$resourceClass = $resource;
}

$this->registerToCluster($resourceClass);
$this->registerToCluster($resourceClass);
}
}

return $this;
Expand Down Expand Up @@ -676,6 +686,25 @@ protected function registerToCluster(string $component): void
$this->clusteredComponents[$cluster][] = $component;
}

protected function registerToClusterConfigured(string $component, string $key): void
{
if (! method_exists($component, 'getCluster')) {
return;
}

if (is_subclass_of($component, ResourcePage::class)) {
return;
}

$cluster = $component::getCluster();

if (blank($cluster)) {
return;
}

$this->clusteredComponentsConfigured[$cluster][$component][] = $key;
}

protected function queueLivewireComponentForRegistration(string $component): void
{
$componentName = app(ComponentRegistry::class)->getName($component);
Expand Down Expand Up @@ -707,6 +736,18 @@ public function getClusteredComponents(?string $cluster = null): array
return $this->clusteredComponents[$cluster] ?? [];
}

/**
* @return array<class-string<Cluster>, array<class-string, array<string>>> | array<class-string, array<string>>
*/
public function getClusteredComponentsConfigured(?string $cluster = null): array
{
if (blank($cluster)) {
return $this->clusteredComponentsConfigured;
}

return $this->clusteredComponentsConfigured[$cluster] ?? [];
}

public function hasCachedComponents(): bool
{
return $this->hasCachedComponents ??= ((! app()->runningInConsole()) && app(Filesystem::class)->exists($this->getComponentCachePath()));
Expand Down
5 changes: 4 additions & 1 deletion packages/panels/src/Resources/Pages/ListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ protected function getTableQuery(): Builder | Relation | null
public function getSubNavigation(): array
{
if (filled($cluster = static::getCluster()) && $cluster::shouldRegisterSubNavigation()) {
return $this->generateNavigationItems($cluster::getClusteredComponents());
return [
...$this->generateNavigationItems($cluster::getClusteredComponents()),
...$this->generateNavigationItemsConfigured($cluster::getClusteredComponentsConfigured()),
];
}

return [];
Expand Down
Loading