103 lines
4.4 KiB
PHP
103 lines
4.4 KiB
PHP
@php
|
|
use App\Filament\Pages\ChooseWorkspace;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
|
|
/** @var WorkspaceContext $workspaceContext */
|
|
$workspaceContext = app(WorkspaceContext::class);
|
|
|
|
$workspace = $workspaceContext->currentWorkspace(request());
|
|
|
|
$user = auth()->user();
|
|
|
|
$tenants = collect();
|
|
if ($user instanceof User) {
|
|
$tenants = collect($user->getTenants(Filament::getCurrentOrDefaultPanel()));
|
|
}
|
|
|
|
$currentTenant = Filament::getTenant();
|
|
$currentTenantName = $currentTenant instanceof Tenant ? $currentTenant->getFilamentName() : null;
|
|
|
|
$lastTenantId = $workspaceContext->lastTenantId(request());
|
|
$canClearTenantContext = $currentTenantName !== null || $lastTenantId !== null;
|
|
@endphp
|
|
|
|
<div class="flex items-center gap-3">
|
|
<a
|
|
href="{{ ChooseWorkspace::getUrl() }}"
|
|
class="text-sm text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100"
|
|
>
|
|
<span class="font-medium">Workspace:</span>
|
|
<span>{{ $workspace?->name ?? '—' }}</span>
|
|
</a>
|
|
|
|
<div class="h-4 w-px bg-gray-200 dark:bg-gray-700"></div>
|
|
|
|
<x-filament::dropdown placement="bottom-start" teleport>
|
|
<x-slot name="trigger">
|
|
<button
|
|
type="button"
|
|
class="text-sm text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100"
|
|
>
|
|
<span class="font-medium">Tenant:</span>
|
|
<span>{{ $currentTenantName ?? '—' }}</span>
|
|
</button>
|
|
</x-slot>
|
|
|
|
<x-filament::dropdown.list>
|
|
<div class="px-3 py-2 space-y-2" x-data="{ query: '' }">
|
|
<div class="text-xs font-medium text-gray-500 dark:text-gray-400">Tenant context</div>
|
|
|
|
@if (! $workspace)
|
|
<div class="text-xs text-gray-500 dark:text-gray-400">Choose a workspace first.</div>
|
|
@elseif ($tenants->isEmpty())
|
|
<div class="text-xs text-gray-500 dark:text-gray-400">No tenants you can access in this workspace.</div>
|
|
@else
|
|
<div class="space-y-2">
|
|
<input
|
|
type="text"
|
|
class="fi-input fi-text-input w-full"
|
|
placeholder="Select tenant…"
|
|
x-model="query"
|
|
/>
|
|
|
|
<div class="max-h-64 overflow-auto rounded-lg border border-gray-200 dark:border-gray-700">
|
|
@foreach ($tenants as $tenant)
|
|
<form method="POST" action="{{ route('admin.select-tenant') }}">
|
|
@csrf
|
|
<input type="hidden" name="tenant_id" value="{{ (int) $tenant->getKey() }}" />
|
|
|
|
<button
|
|
type="submit"
|
|
class="w-full px-3 py-2 text-left text-sm hover:bg-gray-50 dark:hover:bg-gray-800"
|
|
data-search="{{ (string) str($tenant->getFilamentName())->lower() }}"
|
|
x-show="query === '' || ($el.dataset.search ?? '').includes(query.toLowerCase())"
|
|
>
|
|
{{ $tenant->getFilamentName() }}
|
|
</button>
|
|
</form>
|
|
@endforeach
|
|
</div>
|
|
|
|
@if ($canClearTenantContext)
|
|
<form method="POST" action="{{ route('admin.clear-tenant-context') }}">
|
|
@csrf
|
|
|
|
<x-filament::button color="gray" size="sm" outlined>
|
|
Clear tenant context
|
|
</x-filament::button>
|
|
</form>
|
|
@endif
|
|
|
|
<div class="text-xs text-gray-500 dark:text-gray-400">
|
|
Switching tenants is explicit. Canonical monitoring URLs do not change tenant context.
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</x-filament::dropdown.list>
|
|
</x-filament::dropdown>
|
|
</div>
|