Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion resources/views/components/dropdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
'dropdownClass' => '',
'trigger' => '',
'desktopHref' => null, // string | null
'forceHref' => false,
])

<?php
use App\Actions\GetUserDeviceKindAction;

$id = uniqid();

$canUseDesktopHref = (new GetUserDeviceKindAction())->execute() === 'desktop';
$canUseDesktopHref = $forceHref || (new GetUserDeviceKindAction())->execute() === 'desktop';
?>

<div class="dropdown {{ $class ?? '' }} {{ ($active ?? false) ? 'active' : '' }}">
Expand Down
13 changes: 13 additions & 0 deletions resources/views/components/menu/management.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@
$tools = $settings['tools'] ?? [];
$visibleTools = collect($tools)->filter(fn($tool) => $user?->can($tool['abilities']));

$anyDropdownItems =
$visibleTools->isNotEmpty() ||
$user?->can('develop') ||
$user?->can('manage', App\Models\Ticket::class) ||
$user?->can('manage', App\Models\AchievementSetClaim::class) ||
$user?->can('manage', App\Models\GameHash::class) ||
Comment on lines +14 to +17

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: For users whose permissions pass these checks but are still blocked by the later nesting, $anyDropdownItems will technically become true even though no item is rendered.

For example, a Junior Developer can manage tickets/claims per the policy classes, but they fail the outer @can('develop') on line 41. Therefore, assuming I have my boolean math correct, the mobile Manage trigger still renders as a non-link button with an empty dropdown instead of forcing the Filament dashboard href.

$user->Permissions >= Permissions::Developer ||
$user?->can('manage', App\Models\News::class) ||
$user->can('manage', User::class) ||
$user->Permissions === Permissions::Moderator ||
$user->can('tool');

?>

<x-nav-dropdown
:class="$class ?? ''"
dropdown-class="dropdown-menu-right"
:title="__('Manage')"
:desktopHref="route('filament.admin.pages.dashboard')"
:force-href="!$anyDropdownItems"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Better to call this something like shouldForceHref. At the moment, it's almost indistinguishable in purpose between desktopHref unless the reader looks around to see what the type of $anyDropdownItems is.

Might be a good idea to rename $anyDropdownItems too to something like $hasAnyDropdownItems.

>
<x-slot name="trigger">
<x-fas-toolbox />
Expand Down
2 changes: 2 additions & 0 deletions resources/views/components/nav-dropdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'title' => '',
'trigger' => '',
'triggerClass' => '',
'forceHref' => false,
])

<x-dropdown
Expand All @@ -15,6 +16,7 @@ class="nav-item {{ $class ?? '' }}"
:active="$active ?? false"
:title="$title ?? ''"
:desktopHref="$desktopHref"
:force-href="$forceHref"
>
<x-slot name="trigger">{{ $trigger }}</x-slot>
{{ $slot }}
Expand Down
Loading