TenantAtlas/apps/platform/app/Support/OpsUx/OpsUxBrowserEvents.php
Ahmed Darrazi 4097778d96
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 57s
feat: implement operation run phase composite progress and baseline capture resume
2026-06-08 05:27:30 +02:00

56 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\OpsUx;
use App\Filament\Widgets\Inventory\InventoryKpiHeader;
use App\Livewire\BulkOperationProgress;
use App\Models\ManagedEnvironment;
use Filament\Facades\Filament;
final class OpsUxBrowserEvents
{
public const RunEnqueued = 'ops-ux:run-enqueued';
public static function dispatchRunEnqueued(mixed $livewire, ManagedEnvironment|int|null $tenant = null): void
{
if (! is_object($livewire)) {
return;
}
if (! method_exists($livewire, 'dispatch')) {
return;
}
$tenantId = self::resolveTenantId($tenant);
// In Livewire v4, dispatch() emits a DOM event that bubbles.
// Our progress widget is mounted outside the initiating component's DOM tree,
// so we target it explicitly to ensure it receives the event immediately.
$livewire->dispatch(self::RunEnqueued, tenantId: $tenantId)->to(BulkOperationProgress::class);
$livewire->dispatch(self::RunEnqueued, tenantId: $tenantId)->to(InventoryKpiHeader::class);
}
private static function resolveTenantId(ManagedEnvironment|int|null $tenant): ?int
{
if ($tenant instanceof ManagedEnvironment) {
return (int) $tenant->getKey();
}
if (is_int($tenant) && $tenant > 0) {
return $tenant;
}
$currentTenantId = Filament::getTenant()?->getKey();
if (! is_numeric($currentTenantId)) {
return null;
}
$currentTenantId = (int) $currentTenantId;
return $currentTenantId > 0 ? $currentTenantId : null;
}
}