Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
@php
use Eclipse\Core\Services\Registry;
use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Model;
use Eclipse\Core\Filament\Pages\Dashboard;

$appName = Registry::getSite()->name ?? config('app.name');
$hasSpaMode = Filament::getCurrentPanel()->hasSpaMode();
$dashboardUrl = '/' . trim(Filament::getCurrentPanel()->getPath(), '/');

$currentTenant = filament()->getTenant();
$currentTenantName = $currentTenant ? filament()->getTenantName($currentTenant) : null;

$tenants = [];
$canSwitchTenants = false;

if (config('eclipse.multi_site', false) && filament()->auth()->check()) {
$tenants = array_filter(
filament()->getUserTenants(filament()->auth()->user()),
fn(Model $tenant): bool => !$tenant->is($currentTenant),
);
$canSwitchTenants = count($tenants) > 0;
}

$hasFrontend = collect(filament()->getPanels())->has('frontend');
Comment thread
SlimDeluxe marked this conversation as resolved.
Outdated
$frontendUrl = config('app.url');

if ($hasFrontend) {
try {
if ($currentTenant && $currentTenant->domain) {
$frontendUrl = "https://{$currentTenant->domain}";
} else {
$frontendUrl = Dashboard::getUrl();
}
} catch (Exception $e) {
$frontendUrl = config('app.url');
}
}
Comment thread
SlimDeluxe marked this conversation as resolved.
Outdated
@endphp

@if ($canSwitchTenants || $hasFrontend)
<div class="flex items-center gap-x-2">
<a @if ($hasSpaMode) wire:navigate @endif href="{{ $dashboardUrl }}" class="flex-1">
<div class="fi-logo flex text-xl font-bold leading-5 tracking-tight text-gray-950 dark:text-white">
{{ $appName }}
@if ($currentTenant && $currentTenantName !== $appName)
<span class="text-gray-500 dark:text-gray-400 text-sm font-normal ml-2">
- {{ $currentTenantName }}
</span>
@endif
</div>
</a>

<x-filament::dropdown teleport>
<x-slot name="trigger">
<button type="button"
class="fi-tenant-menu-trigger group flex items-center justify-center rounded-lg p-1.5 text-sm font-medium outline-none transition duration-75 hover:bg-gray-100 focus-visible:bg-gray-100 dark:hover:bg-white/5 dark:focus-visible:bg-white/5">
<x-filament::icon icon="heroicon-m-chevron-down" alias="panels::brand-tenant-menu.toggle-button"
class="h-4 w-4 text-gray-400 transition duration-75 group-hover:text-gray-500 group-focus-visible:text-gray-500 dark:text-gray-500 dark:group-hover:text-gray-400 dark:group-focus-visible:text-gray-400" />
</button>
</x-slot>

<x-filament::dropdown.list>
@if ($canSwitchTenants)
@foreach ($tenants as $tenant)
<x-filament::dropdown.list.item :href="route('filament.admin.pages.dashboard', ['tenant' => $tenant])" :image="filament()->getTenantAvatarUrl($tenant)" tag="a">
{{ filament()->getTenantName($tenant) }}
</x-filament::dropdown.list.item>
@endforeach
@endif

@if ($hasFrontend)
@if ($canSwitchTenants)
<x-filament::dropdown.list.item tag="div"
class="border-t border-gray-200 dark:border-gray-700 my-1"></x-filament::dropdown.list.item>
@endif

<x-filament::dropdown.list.item :href="$frontendUrl" tag="a" target="_blank"
class="font-medium">
<div class="flex items-center gap-2">
<x-filament::icon icon="heroicon-s-globe-alt"
class="h-4 w-4 text-gray-500 dark:text-gray-400" />
Frontend
<x-filament::icon icon="heroicon-s-arrow-top-right-on-square"
class="h-3 w-3 text-gray-400 dark:text-gray-500 ml-auto" />
</div>
</x-filament::dropdown.list.item>
@endif
</x-filament::dropdown.list>
</x-filament::dropdown>
</div>
@else
<div class="fi-logo flex text-xl font-bold leading-5 tracking-tight text-gray-950 dark:text-white">
{{ $appName }}
@if ($currentTenant && $currentTenantName !== $appName)
<span class="text-gray-500 dark:text-gray-400 text-sm font-normal ml-2">
- {{ $currentTenantName }}
</span>
@endif
</div>
@endif
35 changes: 12 additions & 23 deletions src/Providers/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use BezhanSalleh\FilamentShield\Facades\FilamentShield;
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
use BezhanSalleh\FilamentShield\Middleware\SyncShieldTenant;
use BezhanSalleh\PanelSwitch\PanelSwitch;
use BezhanSalleh\PanelSwitch\Facades\PanelSwitch;
use DutchCodingCompany\FilamentDeveloperLogins\FilamentDeveloperLoginsPlugin;
use Eclipse\Common\CommonPlugin;
use Eclipse\Common\Providers\GlobalSearchProvider;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function panel(Panel $panel): Panel
])
->topNavigation()
->brandLogo(
fn (): View => view('eclipse::filament.components.brand')
fn (): View => view('eclipse::filament.components.brand-with-tenant-switcher')
)
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverResources(in: $package_src.'Filament/Resources', for: 'Eclipse\\Core\\Filament\\Resources')
Expand Down Expand Up @@ -171,13 +171,6 @@ public function panel(Panel $panel): Panel
fn () => view('eclipse::filament.components.my-settings')
);

if ($hasTenantMenu) {
$panel->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_END,
fn () => view('eclipse::filament.components.tenant-menu')
);
}

// If the Pro version of the Spotlight plugin is installed, use that, otherwise use the free version
if (class_exists(\pxlrbt\FilamentSpotlightPro\SpotlightPlugin::class)) {
/** @noinspection PhpFullyQualifiedNameUsageInspection */
Expand Down Expand Up @@ -243,19 +236,15 @@ public function boot(): void
// Load customized translations for Filament Shield
$this->loadTranslationsFrom(__DIR__.'/../../resources/lang/vendor/filament-shield', 'filament-shield');

// Configure Panel Switch
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch
->simple()
->icons([
'admin' => 'heroicon-s-cog-6-tooth',
'frontend' => 'heroicon-s-globe-alt',
])
->labels([
'admin' => 'Admin Panel',
'frontend' => 'Frontend',
])
->visible(fn (): bool => auth()->check());
});
PanelSwitch::simple()
->icons([
'admin' => 'heroicon-s-cog-6-tooth',
'frontend' => 'heroicon-s-globe-alt',
])
->labels([
'admin' => 'Admin Panel',
'frontend' => 'Frontend',
])
->visible(fn (): bool => auth()->check());
Comment thread
SlimDeluxe marked this conversation as resolved.
Outdated
}
}
25 changes: 25 additions & 0 deletions tests/Feature/Filament/BrandWithTenantSwitcherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

test('brand component renders without tenants', function () {
$response = $this->get('/admin/login');

$response->assertStatus(200);
$response->assertSee(config('app.name'));
});

test('brand component renders with multi-site enabled', function () {
config(['eclipse.multi_site' => true]);

$response = $this->get('/admin/login');
$response->assertStatus(200);
$response->assertSee(config('app.name'));
});

test('brand component shows app name consistently', function () {
config(['eclipse.multi_site' => true]);

$response = $this->get('/admin/login');

$response->assertStatus(200);
$response->assertSee(config('app.name'));
});
Comment thread
SlimDeluxe marked this conversation as resolved.
15 changes: 15 additions & 0 deletions workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Workbench\App\Providers;

use BezhanSalleh\PanelSwitch\PanelSwitchServiceProvider;
use Eclipse\Common\CommonServiceProvider;
use Illuminate\Support\ServiceProvider;
use Nben\FilamentRecordNav\FilamentRecordNavServiceProvider;

class WorkbenchServiceProvider extends ServiceProvider
{
Expand All @@ -11,6 +14,18 @@ class WorkbenchServiceProvider extends ServiceProvider
*/
public function register(): void
{
if (class_exists(CommonServiceProvider::class)) {
$this->app->register(CommonServiceProvider::class);
}

if (class_exists(PanelSwitchServiceProvider::class)) {
$this->app->register(PanelSwitchServiceProvider::class);
}

if (class_exists(FilamentRecordNavServiceProvider::class)) {
$this->app->register(FilamentRecordNavServiceProvider::class);
}

$this->app->register(\Eclipse\Core\Providers\AdminPanelProvider::class);
}

Expand Down