## Summary - enforce the canonical workspace/environment scope contract for workspace hubs and environment-owned surfaces - replace first-party Operations deep links that leaked Filament `tableFilters[...]` internals with stable product-level query behavior - add the sidebar scope indicator and split environment-page navigation into explicit `Workspace-wide` and `Workspace admin` groups - remove redundant tenantless `All environments` scope badges from workspace-wide pages while preserving explicit environment filter affordances - include the Spec 338 artifacts, guard tests, and browser smoke coverage for the new contract ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Navigation/Spec338EnvironmentSidebarSeparationTest.php tests/Feature/Navigation/Spec338OperationRunLinksQueryContractTest.php tests/Feature/Navigation/Spec338SidebarScopeIndicatorTest.php tests/Feature/Filament/PanelNavigationSegregationTest.php` - `cd apps/platform && ./vendor/bin/sail php vendor/bin/pest tests/Browser/Spec338ScopeContractSmokeTest.php --compact` ## Notes - Livewire v4 compliance unchanged - Filament provider registration remains in `bootstrap/providers.php` - no destructive action behavior changed - no migrations, env var changes, or new Filament asset registration Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #409
81 lines
3.7 KiB
PHP
81 lines
3.7 KiB
PHP
@php
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\User;
|
|
use App\Support\ManagedEnvironmentLinks;
|
|
use App\Support\OperateHub\OperateHubShell;
|
|
use Filament\Facades\Filament;
|
|
|
|
$resolvedContext = app(OperateHubShell::class)->resolvedContext(request());
|
|
$workspace = $resolvedContext->workspace;
|
|
$environment = $resolvedContext->tenant;
|
|
$isEnvironmentScope = $resolvedContext->pageCategory->requiresExplicitEnvironment()
|
|
&& $environment instanceof ManagedEnvironment;
|
|
|
|
$environmentDisplayName = static function (ManagedEnvironment $environment): string {
|
|
$displayName = trim((string) ($environment->display_name ?: $environment->name ?: $environment->external_id ?: ''));
|
|
|
|
return $displayName !== '' ? $displayName : 'Environment #'.$environment->getKey();
|
|
};
|
|
|
|
$scopeUrl = $isEnvironmentScope
|
|
? ManagedEnvironmentLinks::viewUrl($environment)
|
|
: route('admin.home');
|
|
|
|
$scopeKind = $isEnvironmentScope
|
|
? __('localization.shell.environment_scope_short')
|
|
: __('localization.shell.workspace_scope_short');
|
|
|
|
$scopeName = $isEnvironmentScope ? $environmentDisplayName($environment) : $workspace?->name;
|
|
|
|
$workspaceEnvironmentCount = 0;
|
|
$sidebarUser = auth()->user();
|
|
if ($sidebarUser instanceof User && $workspace) {
|
|
$workspaceEnvironmentCount = collect($sidebarUser->getTenants(Filament::getCurrentOrDefaultPanel()))
|
|
->filter(fn ($candidate): bool => $candidate instanceof ManagedEnvironment && (int) $candidate->workspace_id === (int) $workspace->getKey())
|
|
->count();
|
|
}
|
|
|
|
$scopeDescription = $isEnvironmentScope
|
|
? __('localization.shell.workspace_context_label', ['workspace' => $workspace?->name])
|
|
: trans_choice('localization.shell.environment_count', $workspaceEnvironmentCount, ['count' => $workspaceEnvironmentCount]);
|
|
|
|
$scopeActionLabel = __('localization.shell.scope_indicator_action', ['scope' => $scopeName]);
|
|
@endphp
|
|
|
|
@if ($workspace)
|
|
<a
|
|
href="{{ $scopeUrl }}"
|
|
wire:navigate
|
|
data-testid="admin-sidebar-scope-indicator"
|
|
aria-label="{{ $scopeKind }}: {{ $scopeName }}"
|
|
title="{{ $scopeActionLabel }}"
|
|
class="group mx-3 mb-4 flex min-w-0 items-center gap-3 rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-start shadow-xs transition hover:border-gray-300 hover:bg-gray-50 dark:border-white/10 dark:bg-white/5 dark:hover:border-white/20 dark:hover:bg-white/10"
|
|
>
|
|
<span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border {{ $isEnvironmentScope ? 'border-primary-200 bg-primary-50 text-primary-600 dark:border-primary-800 dark:bg-primary-950/40 dark:text-primary-300' : 'border-gray-200 bg-gray-50 text-gray-500 dark:border-white/10 dark:bg-white/5 dark:text-gray-300' }}">
|
|
<x-filament::icon
|
|
:icon="$isEnvironmentScope ? 'heroicon-o-building-office-2' : 'heroicon-o-squares-2x2'"
|
|
class="h-4 w-4"
|
|
/>
|
|
</span>
|
|
|
|
<span class="min-w-0 flex-1">
|
|
<span class="block text-[0.6875rem] font-semibold uppercase text-gray-500 dark:text-gray-400">
|
|
{{ $scopeKind }}
|
|
</span>
|
|
|
|
<span class="mt-0.5 block truncate text-sm font-semibold text-gray-950 dark:text-white" title="{{ $scopeName }}">
|
|
{{ $scopeName }}
|
|
</span>
|
|
|
|
<span class="mt-0.5 block truncate text-xs text-gray-500 dark:text-gray-400">
|
|
{{ $scopeDescription }}
|
|
</span>
|
|
</span>
|
|
|
|
<x-filament::icon
|
|
icon="heroicon-m-chevron-right"
|
|
class="h-4 w-4 shrink-0 text-gray-300 transition group-hover:text-gray-400 dark:text-gray-600 dark:group-hover:text-gray-400"
|
|
/>
|
|
</a>
|
|
@endif
|