Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow conditional control over lazy-loading database notifications #14597

Merged
merged 10 commits into from
Oct 23, 2024
12 changes: 7 additions & 5 deletions packages/forms/resources/views/components/wizard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ class="h-full w-full text-gray-200 dark:text-white/5 rtl:rotate-180"
<span
x-cloak
@if (! $nextAction->isDisabled())
x-on:click="$wire.dispatchFormEvent(
'wizard::nextStep',
'{{ $statePath }}',
getStepIndex(step),
)"
x-on:click="
$wire.dispatchFormEvent(
'wizard::nextStep',
'{{ $statePath }}',
getStepIndex(step),
)
"
@endif
x-show="! isLastStep()"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
class="absolute end-0 top-0 flex h-16 items-center gap-x-4 pe-4 md:pe-6 lg:pe-8"
>
@if (filament()->hasDatabaseNotifications())
@livewire(Filament\Livewire\DatabaseNotifications::class, ['lazy' => true])
@livewire(Filament\Livewire\DatabaseNotifications::class, [
'lazy' => filament()->hasLazyLoadedDatabaseNotifications()
])
@endif

<x-filament-panels::user-menu />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
'navigation',
])

<div {{ $attributes->class(['fi-page-sub-navigation-sidebar-ctn hidden w-72 flex-col md:flex']) }}>
<div
{{ $attributes->class(['fi-page-sub-navigation-sidebar-ctn hidden w-72 flex-col md:flex']) }}
>
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SIDEBAR_BEFORE, scopes: $this->getRenderHookScopes()) }}

<ul
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ class="ms-auto flex items-center gap-x-4"

@if (filament()->auth()->check())
@if (filament()->hasDatabaseNotifications())
@livewire(Filament\Livewire\DatabaseNotifications::class, ['lazy' => true])
@livewire(Filament\Livewire\DatabaseNotifications::class, [
'lazy' => filament()->hasLazyLoadedDatabaseNotifications(),
])
@endif

<x-filament-panels::user-menu />
Expand Down
1 change: 1 addition & 0 deletions packages/panels/src/Facades/Filament.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
* @method static bool hasDarkMode()
* @method static bool hasDarkModeForced()
* @method static bool hasDatabaseNotifications()
* @method static bool hasLazyLoadedDatabaseNotifications()
* @method static bool hasEmailVerification()
* @method static bool hasLogin()
* @method static bool hasNavigation()
Expand Down
5 changes: 5 additions & 0 deletions packages/panels/src/FilamentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ public function hasDatabaseNotifications(): bool
return $this->getCurrentPanel()->hasDatabaseNotifications();
}

public function hasLazyLoadedDatabaseNotifications(): bool
{
return $this->getCurrentPanel()->hasLazyLoadedDatabaseNotifications();
}

public function hasEmailVerification(): bool
{
return $this->getCurrentPanel()->hasEmailVerification();
Expand Down
17 changes: 16 additions & 1 deletion packages/panels/src/Panel/Concerns/HasNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ trait HasNotifications
{
protected bool | Closure $hasDatabaseNotifications = false;

protected bool | Closure $hasLazyLoadedDatabaseNotifications = true;

protected string | Closure | null $databaseNotificationsPolling = '30s';

public function databaseNotifications(bool | Closure $condition = true): static
public function databaseNotifications(bool | Closure $condition = true, bool | Closure $isLazy = true): static
{
$this->hasDatabaseNotifications = $condition;
$this->lazyLoadedDatabaseNotifications($isLazy);

return $this;
}

public function lazyLoadedDatabaseNotifications(bool | Closure $condition = true): static
{
$this->hasLazyLoadedDatabaseNotifications = $condition;

return $this;
}
Expand All @@ -29,6 +39,11 @@ public function hasDatabaseNotifications(): bool
return (bool) $this->evaluate($this->hasDatabaseNotifications);
}

public function hasLazyLoadedDatabaseNotifications(): bool
{
return (bool) $this->evaluate($this->hasLazyLoadedDatabaseNotifications);
}

public function getDatabaseNotificationsPollingInterval(): ?string
{
return $this->evaluate($this->databaseNotificationsPolling);
Expand Down
Loading