100 lines
3.1 KiB
PHP
100 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Pages\Monitoring;
|
|
|
|
use App\Filament\Resources\OperationRunResource;
|
|
use App\Filament\Widgets\Operations\OperationsKpiHeader;
|
|
use App\Models\OperationRun;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use BackedEnum;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Contracts\HasForms;
|
|
use Filament\Pages\Page;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use UnitEnum;
|
|
|
|
class Operations extends Page implements HasForms, HasTable
|
|
{
|
|
use InteractsWithForms;
|
|
use InteractsWithTable;
|
|
|
|
public string $activeTab = 'all';
|
|
|
|
protected static bool $isDiscovered = false;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-queue-list';
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Monitoring';
|
|
|
|
protected static ?string $title = 'Operations';
|
|
|
|
// Must be non-static
|
|
protected string $view = 'filament.pages.monitoring.operations';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mountInteractsWithTable();
|
|
}
|
|
|
|
protected function getHeaderWidgets(): array
|
|
{
|
|
return [
|
|
OperationsKpiHeader::class,
|
|
];
|
|
}
|
|
|
|
public function updatedActiveTab(): void
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return OperationRunResource::table($table)
|
|
->query(function (): Builder {
|
|
$workspaceId = app(WorkspaceContext::class)->currentWorkspaceId(request());
|
|
|
|
$query = OperationRun::query()
|
|
->with('user')
|
|
->latest('id')
|
|
->when(
|
|
$workspaceId,
|
|
fn (Builder $query): Builder => $query->where('workspace_id', (int) $workspaceId),
|
|
)
|
|
->when(
|
|
! $workspaceId,
|
|
fn (Builder $query): Builder => $query->whereRaw('1 = 0'),
|
|
);
|
|
|
|
return $this->applyActiveTab($query);
|
|
});
|
|
}
|
|
|
|
private function applyActiveTab(Builder $query): Builder
|
|
{
|
|
return match ($this->activeTab) {
|
|
'active' => $query->whereIn('status', [
|
|
OperationRunStatus::Queued->value,
|
|
OperationRunStatus::Running->value,
|
|
]),
|
|
'succeeded' => $query
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->where('outcome', OperationRunOutcome::Succeeded->value),
|
|
'partial' => $query
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->where('outcome', OperationRunOutcome::PartiallySucceeded->value),
|
|
'failed' => $query
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->where('outcome', OperationRunOutcome::Failed->value),
|
|
default => $query,
|
|
};
|
|
}
|
|
}
|