Kurzbeschreibung Filament-native UI-Polish für das Tenant-Dashboard und zugehörige Inventory/Operations-Ansichten; entfernt alte custom Blade‑Panel-Wrapper (die die dicken Rahmen erzeugten) und ersetzt sie durch Filament‑Widgets (StatsOverview / TableWidget). Keine DB-Migrationen. Änderungen (Kurz) Dashboard: KPI‑Kacheln als StatsOverviewWidget (4 Tiles). Needs‑Attention: sinnvolle Leerstaat‑UI (3 Health‑Checks + Links) und begrenzte, badge‑gestützte Issue‑Liste. Recent Drift Findings & Recent Operations: Filament TableWidget (10 Zeilen), badge‑Spalten für Severity/Status/Outcome, kurze copyable IDs, freundliche Subject‑Labels statt roher UUIDs. Entfernen der alten Blade-Wrapper, die ring- / shadow Klassen erzeugten. Tests aktualisiert/ergänzt, um Tenant‑Scope und DB‑only Garantien zu prüfen. Kleinigkeiten / UI‑Polish in Inventory/Operations-Listen und Panel‑Provider. Wichtige Dateien (Auswahl) DashboardKpis.php NeedsAttention.php RecentDriftFindings.php RecentOperations.php needs-attention.blade.php Tests: TenantDashboardTenantScopeTest.php, inventory/operations test updates Testing / Verifikation Lokale Tests (empfohlen, vor Merge ausführen): Formatter: Filament assets (falls panel assets geändert wurden): Review‑Hinweise (Was prüfen) UI: Dashboard sieht visuell wie Filament‑Demo‑Widgets aus (keine dicken ring- Rahmen mehr). Tables: Primary text zeigt freundliche Labels, nicht UUIDs; IDs sind copyable und kurz dargestellt. Needs‑Attention: Leerstaat zeigt die 3 Health‑Checks + korrekte Links; bei Issues sind Badges und Farben korrekt. Tenant‑Scope: Keine Daten von anderen Tenants leakieren (prüfe die aktualisierten TenantScope‑Tests). Polling: Widgets poll nur wenn nötig (z.B. aktive Runs existieren). Keine externen HTTP‑Calls oder ungeprüfte Jobs während Dashboard‑Rendering. Deployment / Migrations Keine Datenbankmigrationen. Empfohlen: nach Merge ./vendor/bin/sail artisan filament:assets in Deployment‑Pipeline prüfen, falls neue panel assets registriert wurden. Zusammenfassung für den Reviewer Zweck: Entfernen der alten, handgebauten Panel‑Wrappers und Vereinheitlichung der Dashboard‑UX mit Filament‑nativen Komponenten; kleinere UI‑Polish in Inventory/Operations. Tests: Unit/Feature tests für Tenant‑Scope und DB‑only Verhalten wurden aktualisiert; bitte laufen lassen. Merge: Branch 058-tenant-ui-polish → dev (protected) via Pull Request in Gitea. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #70
137 lines
4.2 KiB
PHP
137 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets\Operations;
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\OpsUx\ActiveRuns;
|
|
use Carbon\CarbonInterval;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Widgets\StatsOverviewWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class OperationsKpiHeader extends StatsOverviewWidget
|
|
{
|
|
protected static bool $isLazy = false;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
protected function getPollingInterval(): ?string
|
|
{
|
|
$tenant = Filament::getTenant();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return null;
|
|
}
|
|
|
|
return ActiveRuns::existForTenant($tenant) ? '10s' : null;
|
|
}
|
|
|
|
/**
|
|
* @return array<Stat>
|
|
*/
|
|
protected function getStats(): array
|
|
{
|
|
$tenant = Filament::getTenant();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return [
|
|
Stat::make('Total Runs (30 days)', 0),
|
|
Stat::make('Active Runs', 0),
|
|
Stat::make('Failed/Partial (7 days)', 0),
|
|
Stat::make('Avg Duration (7 days)', '—'),
|
|
];
|
|
}
|
|
|
|
$tenantId = (int) $tenant->getKey();
|
|
|
|
$totalRuns30Days = (int) OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('created_at', '>=', now()->subDays(30))
|
|
->count();
|
|
|
|
$activeRuns = (int) OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->whereIn('status', [
|
|
OperationRunStatus::Queued->value,
|
|
OperationRunStatus::Running->value,
|
|
])
|
|
->count();
|
|
|
|
$failedOrPartial7Days = (int) OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->whereIn('outcome', [
|
|
OperationRunOutcome::Failed->value,
|
|
OperationRunOutcome::PartiallySucceeded->value,
|
|
])
|
|
->where('completed_at', '>=', now()->subDays(7))
|
|
->count();
|
|
|
|
/** @var Collection<int, OperationRun> $recentCompletedRuns */
|
|
$recentCompletedRuns = OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('status', OperationRunStatus::Completed->value)
|
|
->whereNotNull('started_at')
|
|
->whereNotNull('completed_at')
|
|
->where('completed_at', '>=', now()->subDays(7))
|
|
->latest('id')
|
|
->limit(200)
|
|
->get(['started_at', 'completed_at']);
|
|
|
|
$durations = $recentCompletedRuns
|
|
->map(function (OperationRun $run): ?int {
|
|
if (! $run->started_at || ! $run->completed_at) {
|
|
return null;
|
|
}
|
|
|
|
$seconds = $run->completed_at->diffInSeconds($run->started_at);
|
|
|
|
if (is_int($seconds)) {
|
|
return $seconds;
|
|
}
|
|
|
|
return (int) round((float) $seconds);
|
|
})
|
|
->filter(fn (?int $seconds): bool => is_int($seconds) && $seconds > 0)
|
|
->values();
|
|
|
|
$avgDuration7Days = '—';
|
|
if ($durations->isNotEmpty()) {
|
|
$avgDurationSeconds = (int) round($durations->avg() ?? 0);
|
|
$avgDuration7Days = self::formatDurationSeconds($avgDurationSeconds);
|
|
}
|
|
|
|
return [
|
|
Stat::make('Total Runs (30 days)', $totalRuns30Days),
|
|
Stat::make('Active Runs', $activeRuns),
|
|
Stat::make('Failed/Partial (7 days)', $failedOrPartial7Days),
|
|
Stat::make('Avg Duration (7 days)', $avgDuration7Days),
|
|
];
|
|
}
|
|
|
|
private static function formatDurationSeconds(int $seconds): string
|
|
{
|
|
if ($seconds <= 0) {
|
|
return '—';
|
|
}
|
|
|
|
if ($seconds < 60) {
|
|
return $seconds.'s';
|
|
}
|
|
|
|
$interval = CarbonInterval::seconds($seconds)->cascade();
|
|
|
|
if ($seconds < 3600) {
|
|
return sprintf('%dm %ds', $interval->minutes, $interval->seconds);
|
|
}
|
|
|
|
return sprintf('%dh %dm', $interval->hours, $interval->minutes);
|
|
}
|
|
}
|