Kurzbeschreibung Implementiert Feature 055 — Ops‑UX Constitution Rollout v1.3.0. Behebt: globales BulkOperationProgress-Widget benötigt keinen manuellen Refresh mehr; ETA/Elapsed aktualisieren korrekt; Widget verschwindet automatisch. Verbesserungen: zuverlässiges polling (Alpine factory + Livewire fallback), sofortiger Enqueue‑Signal-Dispatch, Failure‑Message‑Sanitization, neue Guard‑ und Regressionstests, Specs/Tasks aktualisiert. Was geändert wurde (Auszug) InventoryLanding.php bulk-operation-progress.blade.php OperationUxPresenter.php SyncRestoreRunToOperationRun.php PolicyResource.php PolicyVersionResource.php RestoreRunResource.php tests/Feature/OpsUx/* (PollerRegistration, TerminalNotificationFailureMessageTest, CanonicalViewRunLinksTest, OperationCatalogCoverageTest, UnknownOperationTypeLabelTest) InventorySyncButtonTest.php tasks.md Tests Neue Tests hinzugefügt; php artisan test --group=ops-ux lokal grün (alle relevanten Tests laufen). How to verify manually Auf Branch wechseln: 055-ops-ux-rollout In Filament: Inventory → Sync (oder relevante Bulk‑Aktion) auslösen. Beobachten: Progress‑Widget erscheint sofort, ETA/Elapsed aktualisiert, Widget verschwindet nach Fertigstellung ohne Browser‑Refresh. Optional: ./vendor/bin/sail exec app php artisan test --filter=OpsUx oder php artisan test --group=ops-ux Besonderheiten / Hinweise Einzelne, synchrone Policy‑Actions (ignore/restore/PolicyVersion single archive/restore/forceDelete) sind absichtlich inline und erzeugen kein OperationRun. Bulk‑Aktionen und restore.execute werden als Runs modelliert. Wenn gewünscht, kann ich die inline‑Actions auf OperationRunService umstellen, damit sie in Monitoring → Operations sichtbar werden. Remote: Branch ist bereits gepusht (origin/055-ops-ux-rollout). PR kann in Gitea erstellt werden. Links Specs & tasks: tasks.md Monitoring page: Operations.php Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #64
112 lines
3.3 KiB
PHP
112 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\OpsUx;
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Support\OperationCatalog;
|
|
use Filament\Notifications\Notification as FilamentNotification;
|
|
use Illuminate\Support\Str;
|
|
|
|
final class OperationUxPresenter
|
|
{
|
|
public const int QUEUED_TOAST_DURATION_MS = 4000;
|
|
|
|
public const int FAILURE_MESSAGE_MAX_CHARS = 140;
|
|
|
|
/**
|
|
* Queued intent feedback toast (ephemeral, not persisted).
|
|
*/
|
|
public static function queuedToast(string $operationType): FilamentNotification
|
|
{
|
|
$operationLabel = OperationCatalog::label($operationType);
|
|
|
|
return FilamentNotification::make()
|
|
->title("{$operationLabel} queued")
|
|
->body('Running in the background.')
|
|
->warning()
|
|
->duration(self::QUEUED_TOAST_DURATION_MS);
|
|
}
|
|
|
|
/**
|
|
* Terminal DB notification payload.
|
|
*
|
|
* Note: We intentionally return the built Filament notification builder to
|
|
* keep DB formatting consistent with existing Notification classes.
|
|
*/
|
|
public static function terminalDatabaseNotification(OperationRun $run, ?Tenant $tenant = null): FilamentNotification
|
|
{
|
|
$operationLabel = OperationCatalog::label((string) $run->type);
|
|
|
|
$uxStatus = OperationStatusNormalizer::toUxStatus($run->status, $run->outcome);
|
|
|
|
$titleSuffix = match ($uxStatus) {
|
|
'succeeded' => 'completed',
|
|
'partial' => 'completed with warnings',
|
|
default => 'failed',
|
|
};
|
|
|
|
$body = match ($uxStatus) {
|
|
'succeeded' => 'Completed successfully.',
|
|
'partial' => 'Completed with warnings.',
|
|
default => 'Failed.',
|
|
};
|
|
|
|
if ($uxStatus === 'failed') {
|
|
$failureMessage = (string) (($run->failure_summary[0]['message'] ?? '') ?? '');
|
|
|
|
$failureMessage = self::sanitizeFailureMessage($failureMessage);
|
|
|
|
if ($failureMessage !== null) {
|
|
$body = $body.' '.$failureMessage;
|
|
}
|
|
}
|
|
|
|
$summary = SummaryCountsNormalizer::renderSummaryLine(is_array($run->summary_counts) ? $run->summary_counts : []);
|
|
if ($summary !== null) {
|
|
$body = $body."\n".$summary;
|
|
}
|
|
|
|
$status = match ($uxStatus) {
|
|
'succeeded' => 'success',
|
|
'partial' => 'warning',
|
|
default => 'danger',
|
|
};
|
|
|
|
$notification = FilamentNotification::make()
|
|
->title("{$operationLabel} {$titleSuffix}")
|
|
->body($body)
|
|
->status($status);
|
|
|
|
if ($tenant instanceof Tenant) {
|
|
$notification->actions([
|
|
\Filament\Actions\Action::make('view')
|
|
->label('View run')
|
|
->url(OperationRunUrl::view($run, $tenant)),
|
|
]);
|
|
}
|
|
|
|
return $notification;
|
|
}
|
|
|
|
private static function sanitizeFailureMessage(string $failureMessage): ?string
|
|
{
|
|
$failureMessage = trim($failureMessage);
|
|
|
|
if ($failureMessage === '') {
|
|
return null;
|
|
}
|
|
|
|
$failureMessage = Str::of($failureMessage)
|
|
->replace(["\r", "\n"], ' ')
|
|
->squish()
|
|
->toString();
|
|
|
|
$failureMessage = Str::limit($failureMessage, self::FAILURE_MESSAGE_MAX_CHARS, '…');
|
|
|
|
return $failureMessage !== '' ? $failureMessage : null;
|
|
}
|
|
}
|