@php use App\Filament\Pages\ChooseEnvironment; use App\Filament\Pages\ChooseWorkspace; use App\Models\ManagedEnvironment; use App\Models\User; use App\Support\OperateHub\OperateHubShell; use App\Support\Workspaces\WorkspaceContext; use Filament\Facades\Filament; /** @var WorkspaceContext $workspaceContext */ $workspaceContext = app(WorkspaceContext::class); $resolvedContext = app(OperateHubShell::class)->resolvedContext(request()); $workspace = $resolvedContext->workspace; $user = auth()->user(); $environments = collect(); if ($user instanceof User && $workspace) { $environments = collect($user->getTenants(Filament::getCurrentOrDefaultPanel())) ->filter(fn ($environment): bool => $environment instanceof ManagedEnvironment && (int) $environment->workspace_id === (int) $workspace->getKey()) ->values(); } $currentEnvironment = $resolvedContext->tenant; $currentEnvironmentId = $currentEnvironment instanceof ManagedEnvironment ? (int) $currentEnvironment->getKey() : null; $currentEnvironmentName = $currentEnvironment instanceof ManagedEnvironment ? $currentEnvironment->getFilamentName() : null; $lastEnvironmentId = $workspaceContext->lastEnvironmentId(request()); $canClearEnvironmentContext = $currentEnvironment instanceof ManagedEnvironment || $lastEnvironmentId !== null; @endphp @php $environmentLabel = $currentEnvironmentName ?? __('localization.shell.no_environment_selected'); $workspaceLabel = $workspace?->name ?? __('localization.shell.choose_workspace'); $hasActiveEnvironment = $currentEnvironmentName !== null; $managedEnvironmentsUrl = $workspace ? route('admin.workspace.managed-environments.index', ['workspace' => $workspace]) : route('admin.onboarding'); $workspaceUrl = $workspace ? route('admin.home') : ChooseWorkspace::getUrl(panel: 'admin'); $environmentTriggerLabel = $workspace ? $environmentLabel : __('localization.shell.choose_workspace'); $localePlane = 'admin'; @endphp
{{-- Workspace label: standalone link --}} {{ $workspaceLabel }} @if ($workspace) @endif {{-- Dropdown trigger: environment label + chevron --}}
@if ($resolvedContext->showsRecoveryNotice())
{{ __('localization.shell.context_unavailable') }}
@if ($workspace)
{{ __('localization.shell.context_unavailable_workspace') }}
@else
{{ __('localization.shell.context_unavailable_no_workspace') }}
@endif
@endif {{-- Workspace section --}} @if ($workspace)
{{-- Managed Environment section --}}
{{ __('localization.shell.selected_environment') }}
@if ($resolvedContext->pageCategory->requiresExplicitEnvironment() && $hasActiveEnvironment)
@if ($canClearEnvironmentContext)
@csrf
@endif
@else @if ($environments->isEmpty())
{{ __('localization.shell.no_active_environments') }}
{{ __('localization.shell.view_managed_environments') }}
@else @if (! $hasActiveEnvironment)
{{ __('localization.shell.workspace_wide_available_without_environment') }}
@endif
@foreach ($environments as $environment) @php $isActive = $currentEnvironmentId !== null && (int) $environment->getKey() === $currentEnvironmentId; @endphp
@csrf
@endforeach
@if ($canClearEnvironmentContext)
@csrf
@endif @endif @endif
@else
{{ __('localization.shell.choose_workspace_first') }}
@endif
@include('filament.partials.locale-switcher', ['plane' => $localePlane, 'showPreference' => true, 'embedded' => true])