Enhance AuditLogResource by adding getNavigationItems method to categorize navigation items under the System group. Remove unused Auth facade import in AppServiceProvider and clean up navigation group assignment in AdminPanelProvider for improved clarity and organization.
This commit is contained in:
1 parent
3504e39646
commit
3cdbeda805
4 files changed
+50
-2
No files matched your search
@@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
namespace App\Filament\ActivityTimeline;
|
namespace App\Filament\ActivityTimeline;
|
||||||
|
|
||||||
|
use App\Enums\NavigationGroup;
|
||||||
use App\Filament\Concerns\HasHrResourceLabels;
|
use App\Filament\Concerns\HasHrResourceLabels;
|
||||||
use BokshornIt\FilamentActivityTimeline\Resources\ActivityResource;
|
use BokshornIt\FilamentActivityTimeline\Resources\ActivityResource;
|
||||||
|
use Filament\Navigation\NavigationItem;
|
||||||
|
|
||||||
class AuditLogResource extends ActivityResource
|
class AuditLogResource extends ActivityResource
|
||||||
{
|
{
|
||||||
@@ -21,4 +23,15 @@ protected static function hrLabelKeys(): array
|
|||||||
'navigation' => 'audit_log',
|
'navigation' => 'audit_log',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<NavigationItem>
|
||||||
|
*/
|
||||||
|
public static function getNavigationItems(): array
|
||||||
|
{
|
||||||
|
return array_map(
|
||||||
|
fn (NavigationItem $item): NavigationItem => $item->group(NavigationGroup::System),
|
||||||
|
parent::getNavigationItems(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,6 @@
|
|||||||
use App\Policies\VacationPolicy;
|
use App\Policies\VacationPolicy;
|
||||||
use BezhanSalleh\LanguageSwitch\Events\LocaleChanged;
|
use BezhanSalleh\LanguageSwitch\Events\LocaleChanged;
|
||||||
use BezhanSalleh\LanguageSwitch\LanguageSwitch;
|
use BezhanSalleh\LanguageSwitch\LanguageSwitch;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ public function panel(Panel $panel): Panel
|
|||||||
->navigationGroup(NavigationGroupEnum::System),
|
->navigationGroup(NavigationGroupEnum::System),
|
||||||
ActivityTimelinePlugin::make()
|
ActivityTimelinePlugin::make()
|
||||||
->resource(AuditLogResource::class)
|
->resource(AuditLogResource::class)
|
||||||
->navigationGroup(fn (): string => NavigationGroupEnum::System->getLabel())
|
|
||||||
->navigationIcon('heroicon-o-clipboard-document-list')
|
->navigationIcon('heroicon-o-clipboard-document-list')
|
||||||
->navigationSort(3)
|
->navigationSort(3)
|
||||||
->causerIcons([
|
->causerIcons([
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Navigation\NavigationManager;
|
||||||
|
|
||||||
|
it('shows audit log only once in the system navigation group', function (): void {
|
||||||
|
$admin = createAdminUser(['locale' => 'tk']);
|
||||||
|
|
||||||
|
$this->actingAs($admin);
|
||||||
|
app()->setLocale('tk');
|
||||||
|
Filament::setCurrentPanel(Filament::getPanel('admin'));
|
||||||
|
|
||||||
|
$response = $this->get('/admin');
|
||||||
|
$response->assertSuccessful();
|
||||||
|
|
||||||
|
$auditLabel = 'Audit žurnaly';
|
||||||
|
$occurrences = substr_count($response->getContent(), $auditLabel);
|
||||||
|
|
||||||
|
$nm = app(NavigationManager::class);
|
||||||
|
$nav = $nm->get();
|
||||||
|
|
||||||
|
$systemGroups = collect($nav)->filter(
|
||||||
|
fn ($group): bool => $group->getLabel() === __('hr.navigation.system'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$auditNavItems = $systemGroups->flatMap(
|
||||||
|
fn ($group) => $group->getItems()->filter(
|
||||||
|
fn ($item): bool => $item->getLabel() === $auditLabel,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect($occurrences)->toBe(1)
|
||||||
|
->and($systemGroups->count())->toBe(1)
|
||||||
|
->and($auditNavItems->count())->toBe(1);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user