68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\BackupScheduleResource\Pages;
|
|
|
|
use App\Filament\Resources\BackupScheduleResource;
|
|
use App\Support\Filament\CanonicalAdminTenantFilterState;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
class ListBackupSchedules extends ListRecords
|
|
{
|
|
protected static string $resource = BackupScheduleResource::class;
|
|
|
|
/**
|
|
* @param array<string, mixed> $arguments
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
public function mountAction(string $name, array $arguments = [], array $context = []): mixed
|
|
{
|
|
if (($context['table'] ?? false) === true && filled($context['recordKey'] ?? null) && in_array($name, ['archive', 'restore', 'forceDelete'], true)) {
|
|
try {
|
|
BackupScheduleResource::resolveScopedRecordOrFail($context['recordKey']);
|
|
} catch (ModelNotFoundException) {
|
|
abort(404);
|
|
}
|
|
}
|
|
|
|
return parent::mountAction($name, $arguments, $context);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->syncCanonicalAdminTenantFilterState();
|
|
|
|
parent::mount();
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
BackupScheduleResource::makeCreateAction()
|
|
->visible(fn (): bool => $this->tableHasRecords()),
|
|
];
|
|
}
|
|
|
|
protected function getTableEmptyStateActions(): array
|
|
{
|
|
return [
|
|
BackupScheduleResource::makeCreateAction(),
|
|
];
|
|
}
|
|
|
|
private function tableHasRecords(): bool
|
|
{
|
|
return $this->getTableRecords()->count() > 0;
|
|
}
|
|
|
|
private function syncCanonicalAdminTenantFilterState(): void
|
|
{
|
|
app(CanonicalAdminTenantFilterState::class)->sync(
|
|
$this->getTableFiltersSessionKey(),
|
|
tenantSensitiveFilters: [],
|
|
request: request(),
|
|
tenantFilterName: null,
|
|
);
|
|
}
|
|
}
|