TenantAtlas/apps/platform/app/Livewire/BulkOperationProgress.php
ahmido e64bae9cfc feat: cut over tenant core to managed environments (#335)
## Summary
- replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership
- propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths
- add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`

## Notes
- branch pushed from commit `1123b122`
- browser smoke test file was added but not run in this pass

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #335
2026-05-07 06:38:14 +00:00

110 lines
2.8 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\OperationRun;
use App\Models\ManagedEnvironment;
use App\Support\OpsUx\ActiveRuns;
use App\Support\OpsUx\OpsUxBrowserEvents;
use Filament\Facades\Filament;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\On;
use Livewire\Component;
class BulkOperationProgress extends Component
{
private const VISIBLE_RUN_LIMIT = 3;
/**
* @var Collection<int, OperationRun>
*/
public Collection $runs;
public int $overflowCount = 0;
public bool $disabled = false;
public bool $hasActiveRuns = false;
public bool $hasVisibleRuns = false;
public int $activeRunCount = 0;
public ?int $tenantId = null;
public function mount(): void
{
$this->runs = collect();
$tenant = Filament::getTenant();
$this->tenantId = $tenant instanceof ManagedEnvironment ? (int) $tenant->id : null;
$this->refreshRuns();
}
#[On(OpsUxBrowserEvents::RunEnqueued)]
public function onRunEnqueued(?int $tenantId = null): void
{
if ($tenantId !== null) {
$this->tenantId = $tenantId;
}
$this->refreshRuns();
}
#[Computed]
public function activeRuns(): Collection
{
return $this->runs;
}
public function refreshRuns(): void
{
$tenantId = $this->tenantId;
// Best-effort: if we're mounted on a tenant page, capture it once.
if ($tenantId === null) {
$tenant = Filament::getTenant();
$tenantId = $tenant instanceof ManagedEnvironment ? (int) $tenant->id : null;
$this->tenantId = $tenantId;
}
if ($tenantId === null) {
$this->disabled = true;
$this->runs = collect();
$this->overflowCount = 0;
$this->hasActiveRuns = false;
return;
}
if (! auth()->user()?->can('viewAny', OperationRun::class)) {
$this->disabled = true;
$this->runs = collect();
$this->overflowCount = 0;
$this->hasActiveRuns = false;
return;
}
$this->disabled = false;
$activeCount = ActiveRuns::countForTenantId($tenantId);
$visibleCount = ActiveRuns::shellVisibleCountForTenantId($tenantId);
$this->activeRunCount = $activeCount;
$this->runs = ActiveRuns::shellVisibleForTenantId($tenantId, self::VISIBLE_RUN_LIMIT);
$this->overflowCount = max(0, $visibleCount - self::VISIBLE_RUN_LIMIT);
$this->hasActiveRuns = $activeCount > 0;
$this->hasVisibleRuns = $visibleCount > 0;
}
public function render(): \Illuminate\Contracts\View\View
{
return view('livewire.bulk-operation-progress', [
'tenant' => Filament::getTenant(),
]);
}
}