Skip to content

Commit

Permalink
Merge pull request #13973 from bumbummen99/patch-5
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Oct 23, 2024
1 parent 6ab7628 commit 1d17d65
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 28 deletions.
14 changes: 7 additions & 7 deletions docs/03-resources/02-listing-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Listing records
You can add tabs above the table, which can be used to filter the records based on some predefined conditions. Each tab can scope the Eloquent query of the table in a different way. To register tabs, add a `getTabs()` method to the List page class, and return an array of `Tab` objects:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use Filament\Resources\Components\Tab;
use Illuminate\Database\Eloquent\Builder;

public function getTabs(): array
Expand All @@ -27,7 +27,7 @@ public function getTabs(): array
The keys of the array will be used as identifiers for the tabs, so they can be persisted in the URL's query string. The label of each tab is also generated from the key, but you can override that by passing a label into the `make()` method of the tab:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use Filament\Resources\Components\Tab;
use Illuminate\Database\Eloquent\Builder;

public function getTabs(): array
Expand All @@ -47,7 +47,7 @@ public function getTabs(): array
You can add icons to the tabs by passing an [icon](https://blade-ui-kit.com/blade-icons?set=1#search) into the `icon()` method of the tab:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use use Filament\Resources\Components\Tab;

Tab::make()
->icon('heroicon-m-user-group')
Expand All @@ -68,7 +68,7 @@ Tab::make()
You can add badges to the tabs by passing a string into the `badge()` method of the tab:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use Filament\Resources\Components\Tab;

Tab::make()
->badge(Customer::query()->where('active', true)->count())
Expand All @@ -79,7 +79,7 @@ Tab::make()
The color of a badge may be changed using the `badgeColor()` method:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use Filament\Resources\Components\Tab;

Tab::make()
->badge(Customer::query()->where('active', true)->count())
Expand All @@ -91,7 +91,7 @@ Tab::make()
You may also pass extra HTML attributes to filter tabs using `extraAttributes()`:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use Filament\Resources\Components\Tab;

Tab::make()
->extraAttributes(['data-cy' => 'statement-confirmed-tab'])
Expand All @@ -102,7 +102,7 @@ Tab::make()
To customize the default tab that is selected when the page is loaded, you can return the array key of the tab from the `getDefaultActiveTab()` method:

```php
use Filament\Resources\Pages\ListRecords\Tab;
use Filament\Resources\Components\Tab;

public function getTabs(): array
{
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/layout/simple.blade.php
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
8 changes: 6 additions & 2 deletions resources/views/components/page/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@
])
>
@if ($subNavigation)
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SELECT_BEFORE, scopes: $this->getRenderHookScopes()) }}
<div class="md:hidden">
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SELECT_BEFORE, scopes: $this->getRenderHookScopes()) }}
</div>

<x-filament-panels::page.sub-navigation.select
:navigation="$subNavigation"
/>

{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SELECT_AFTER, scopes: $this->getRenderHookScopes()) }}
<div class="md:hidden">
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SELECT_AFTER, scopes: $this->getRenderHookScopes()) }}
</div>

@if ($subNavigationPosition === SubNavigationPosition::Start)
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_START_BEFORE, scopes: $this->getRenderHookScopes()) }}
Expand Down
40 changes: 24 additions & 16 deletions resources/views/components/page/sub-navigation/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
'navigation',
])

<ul
wire:ignore
{{ $attributes->class(['fi-page-sub-navigation-sidebar hidden w-72 flex-col gap-y-7 md:flex']) }}
<div
{{ $attributes->class(['fi-page-sub-navigation-sidebar-ctn hidden w-72 flex-col md:flex']) }}
>
@foreach ($navigation as $navigationGroup)
<x-filament-panels::sidebar.group
:active="$navigationGroup->isActive()"
:collapsible="$navigationGroup->isCollapsible()"
:icon="$navigationGroup->getIcon()"
:items="$navigationGroup->getItems()"
:label="$navigationGroup->getLabel()"
:sidebar-collapsible="false"
sub-navigation
:attributes="\Filament\Support\prepare_inherited_attributes($navigationGroup->getExtraSidebarAttributeBag())"
/>
@endforeach
</ul>
{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SIDEBAR_BEFORE, scopes: $this->getRenderHookScopes()) }}

<ul
wire:ignore
class="fi-page-sub-navigation-sidebar flex flex-col gap-y-7"
>
@foreach ($navigation as $navigationGroup)
<x-filament-panels::sidebar.group
:active="$navigationGroup->isActive()"
:collapsible="$navigationGroup->isCollapsible()"
:icon="$navigationGroup->getIcon()"
:items="$navigationGroup->getItems()"
:label="$navigationGroup->getLabel()"
:sidebar-collapsible="false"
sub-navigation
:attributes="\Filament\Support\prepare_inherited_attributes($navigationGroup->getExtraSidebarAttributeBag())"
/>
@endforeach
</ul>

{{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::PAGE_SUB_NAVIGATION_SIDEBAR_AFTER, scopes: $this->getRenderHookScopes()) }}
</div>
4 changes: 3 additions & 1 deletion resources/views/components/topbar/index.blade.php
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 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 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 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
4 changes: 4 additions & 0 deletions src/View/PanelsRenderHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class PanelsRenderHook

const PAGE_SUB_NAVIGATION_SELECT_BEFORE = 'panels::page.sub-navigation.select.before';

const PAGE_SUB_NAVIGATION_SIDEBAR_AFTER = 'panels::page.sub-navigation.sidebar.after';

const PAGE_SUB_NAVIGATION_SIDEBAR_BEFORE = 'panels::page.sub-navigation.sidebar.before';

const PAGE_SUB_NAVIGATION_START_AFTER = 'panels::page.sub-navigation.start.after';

const PAGE_SUB_NAVIGATION_START_BEFORE = 'panels::page.sub-navigation.start.before';
Expand Down

0 comments on commit 1d17d65

Please # to comment.