TenantAtlas/apps/platform/app/Livewire/BulkOperationProgress.php
ahmido 2752515da5
Some checks failed
Main Confidence / confidence (push) Failing after 54s
Spec 235: harden baseline truth and onboarding flows (#271)
## Summary
- harden baseline capture truth, compare readiness, and monitoring explanations around latest inventory eligibility, blocked prerequisites, and zero-subject outcomes
- improve onboarding verification and bootstrap recovery handling, including admin-consent callback invalidation and queued execution legitimacy/report behavior
- align workspace findings/workspace overview signals and refresh the related spec, roadmap, and spec-candidate artifacts

## Validation
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/BaselineDriftEngine/BaselineCaptureAuditEventsTest.php tests/Feature/BaselineDriftEngine/BaselineSnapshotNoTenantIdentifiersTest.php tests/Feature/BaselineDriftEngine/CaptureBaselineContentTest.php tests/Feature/BaselineDriftEngine/CaptureBaselineFullContentOnDemandTest.php tests/Feature/BaselineDriftEngine/CaptureBaselineMetaFallbackTest.php tests/Feature/Baselines/BaselineCaptureTest.php tests/Feature/Baselines/BaselineCompareFindingsTest.php tests/Feature/Baselines/BaselineSnapshotBackfillTest.php tests/Feature/Filament/BaselineCaptureResultExplanationSurfaceTest.php tests/Feature/Filament/BaselineCompareLandingStartSurfaceTest.php tests/Feature/Filament/BaselineProfileCaptureStartSurfaceTest.php tests/Feature/Filament/OperationRunBaselineTruthSurfaceTest.php tests/Feature/Monitoring/AuditCoverageGovernanceTest.php tests/Feature/Monitoring/GovernanceOperationRunSummariesTest.php tests/Feature/Notifications/OperationRunNotificationTest.php tests/Feature/Authorization/OperatorExplanationSurfaceAuthorizationTest.php`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/AdminConsentCallbackTest.php tests/Feature/Filament/WorkspaceOverviewDbOnlyTest.php tests/Feature/Guards/Spec194GovernanceActionSemanticsGuardTest.php tests/Feature/ManagedTenantOnboardingWizardTest.php tests/Feature/Onboarding/OnboardingVerificationTest.php tests/Feature/Operations/QueuedExecutionAuditTrailTest.php tests/Unit/Operations/QueuedExecutionLegitimacyGateTest.php`

## Notes
- browser validation was not re-run in this pass

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #271
2026-04-24 05:44:54 +00:00

104 lines
2.5 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\OperationRun;
use App\Models\Tenant;
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
{
/**
* @var Collection<int, OperationRun>
*/
public Collection $runs;
public int $overflowCount = 0;
public bool $disabled = false;
public bool $hasActiveRuns = false;
public ?int $tenantId = null;
public function mount(): void
{
$this->runs = collect();
$tenant = Filament::getTenant();
$this->tenantId = $tenant instanceof Tenant ? (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()
{
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 Tenant ? (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;
$query = OperationRun::query()
->where('tenant_id', $tenantId)
->active()
->orderByDesc('created_at');
$activeCount = (clone $query)->count();
$this->runs = (clone $query)->limit(6)->get();
$this->overflowCount = max(0, $activeCount - 5);
$this->hasActiveRuns = $activeCount > 0;
}
public function render(): \Illuminate\Contracts\View\View
{
return view('livewire.bulk-operation-progress', [
'tenant' => Filament::getTenant(),
]);
}
}