Adds a tenant-scoped dashboard page (KPIs, Needs Attention, Recent Drift Findings, Recent Operations) with polling only while active runs exist. Guardrails: DB-only render (no outbound HTTP) + tenant isolation. Tests: ActiveRunsTest, TenantDashboardDbOnlyTest, TenantDashboardTenantScopeTest. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #68
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets\Dashboard;
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Support\OperationCatalog;
|
|
use App\Support\OperationRunLinks;
|
|
use App\Support\OpsUx\ActiveRuns;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Widgets\Widget;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class RecentOperations extends Widget
|
|
{
|
|
protected static bool $isLazy = false;
|
|
|
|
protected string $view = 'filament.widgets.dashboard.recent-operations';
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function getViewData(): array
|
|
{
|
|
$tenant = Filament::getTenant();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return [
|
|
'pollingInterval' => null,
|
|
'runs' => collect(),
|
|
'viewRunBaseUrl' => null,
|
|
];
|
|
}
|
|
|
|
$tenantId = (int) $tenant->getKey();
|
|
|
|
/** @var Collection<int, OperationRun> $runs */
|
|
$runs = OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->latest('created_at')
|
|
->limit(10)
|
|
->get()
|
|
->each(function (OperationRun $run) use ($tenant): void {
|
|
$run->setAttribute('type_label', OperationCatalog::label((string) $run->type));
|
|
$run->setAttribute('view_url', OperationRunLinks::view($run, $tenant));
|
|
});
|
|
|
|
return [
|
|
'pollingInterval' => ActiveRuns::existForTenant($tenant) ? '10s' : null,
|
|
'runs' => $runs,
|
|
];
|
|
}
|
|
}
|