Skip to content

Commit 1c4ef53

Browse files
committed
fixed an issue where menu item was attempting to render in panels where the plugin was not enabled
1 parent d16f93f commit 1c4ef53

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/FilamentDeveloperLoginsServiceProvider.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use DutchCodingCompany\FilamentDeveloperLogins\Livewire\MenuLogins;
66
use DutchCodingCompany\FilamentDeveloperLogins\View\Components\DeveloperLogins;
7+
use Filament\Panel;
78
use Filament\Facades\Filament;
89
use Filament\Support\Concerns\EvaluatesClosures;
910
use Filament\Support\Facades\FilamentView;
@@ -45,7 +46,8 @@ public function packageBooted(): void
4546
protected static function registerRenderHooks(): void
4647
{
4748
$panel = Filament::getCurrentPanel();
48-
if (is_null($panel) || ! $panel->hasPlugin('filament-developer-logins')) {
49+
50+
if(! self::enabledForPanel($panel)) {
4951
return;
5052
}
5153

@@ -55,7 +57,8 @@ protected static function registerRenderHooks(): void
5557
FilamentView::registerRenderHook(
5658
PanelsRenderHook::AUTH_LOGIN_FORM_AFTER,
5759
static function () use ($plugin) : ?string {
58-
if (! $plugin->getEnabled()) {
60+
61+
if (! $plugin->getEnabled() || ! self::enabledForPanel(Filament::getCurrentPanel())) {
5962
return null;
6063
}
6164

@@ -66,12 +69,17 @@ static function () use ($plugin) : ?string {
6669
FilamentView::registerRenderHook(
6770
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
6871
static function () use ($plugin) : ?string {
69-
if (! $plugin->getEnabled() || ! $plugin->getSwitchable()) {
72+
if (! $plugin->getEnabled() || ! $plugin->getSwitchable() || ! self::enabledForPanel(Filament::getCurrentPanel())) {
7073
return null;
7174
}
7275

7376
return Blade::render('@livewire(\'menu-logins\')');
7477
},
7578
);
7679
}
80+
81+
protected static function enabledForPanel(?Panel $panel)
82+
{
83+
return ! is_null($panel) && $panel->hasPlugin('filament-developer-logins');
84+
}
7785
}

tests/Feature/MenuLoginsTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DutchCodingCompany\FilamentDeveloperLogins\Tests\TestCase;
99
use Filament\Facades\Filament;
1010
use Filament\Pages\Dashboard;
11+
use Filament\Panel;
1112
use Livewire\Livewire;
1213

1314
final class MenuLoginsTest extends TestCase
@@ -80,4 +81,39 @@ public function test_forbidden_is_returned_when_enabled_or_switchable_is_false()
8081
->call('loginAs', '[email protected]')
8182
->assertForbidden();
8283
}
84+
85+
public function test_component_is_only_rendered_in_panel_with_plugin(): void
86+
{
87+
88+
$user = TestUser::factory()->create();
89+
90+
$this->actingAs($user)
91+
->get(Dashboard::getUrl(panel: $this->panelName))
92+
->assertSuccessful()
93+
->assertSeeLivewire(MenuLogins::class);
94+
95+
96+
$this->actingAs($user)
97+
->get(Dashboard::getUrl(panel: $this->panelName . '-other' ))
98+
->assertSuccessful()
99+
->assertDontSeeLivewire(MenuLogins::class);
100+
}
101+
102+
protected function registerTestPanel(): void
103+
{
104+
parent::registerTestPanel();
105+
Filament::registerPanel(fn() => Panel::make()
106+
->darkMode(false)
107+
->id($this->panelName . '-other')
108+
->path($this->panelName . '-other')
109+
->login()
110+
->pages([
111+
Dashboard::class,
112+
])
113+
->plugins([
114+
]),
115+
);
116+
}
117+
118+
83119
}

0 commit comments

Comments
 (0)