*/ public array $features = []; public string $search = ''; /** * @var array */ public array $viewModel = []; public static function canAccess(): bool { $tenant = Tenant::current(); $user = auth()->user(); if (! $tenant instanceof Tenant || ! $user instanceof User) { return false; } /** @var CapabilityResolver $resolver */ $resolver = app(CapabilityResolver::class); return $resolver->can($user, $tenant, Capabilities::TENANT_VIEW); } public function mount(): void { $queryFeatures = request()->query('features', $this->features); $state = TenantRequiredPermissionsViewModelBuilder::normalizeFilterState([ 'status' => request()->query('status', $this->status), 'type' => request()->query('type', $this->type), 'features' => is_array($queryFeatures) ? $queryFeatures : [], 'search' => request()->query('search', $this->search), ]); $this->status = $state['status']; $this->type = $state['type']; $this->features = $state['features']; $this->search = $state['search']; $this->refreshViewModel(); } public function updatedStatus(): void { $this->refreshViewModel(); } public function updatedType(): void { $this->refreshViewModel(); } public function updatedFeatures(): void { $this->refreshViewModel(); } public function updatedSearch(): void { $this->refreshViewModel(); } public function applyFeatureFilter(string $feature): void { $feature = trim($feature); if ($feature === '') { return; } if (in_array($feature, $this->features, true)) { $this->features = array_values(array_filter( $this->features, static fn (string $value): bool => $value !== $feature, )); } else { $this->features[] = $feature; } $this->features = array_values(array_unique($this->features)); $this->refreshViewModel(); } public function clearFeatureFilter(): void { $this->features = []; $this->refreshViewModel(); } public function resetFilters(): void { $this->status = 'missing'; $this->type = 'all'; $this->features = []; $this->search = ''; $this->refreshViewModel(); } private function refreshViewModel(): void { $tenant = Tenant::current(); if (! $tenant instanceof Tenant) { $this->viewModel = []; return; } $builder = app(TenantRequiredPermissionsViewModelBuilder::class); $this->viewModel = $builder->build($tenant, [ 'status' => $this->status, 'type' => $this->type, 'features' => $this->features, 'search' => $this->search, ]); $filters = $this->viewModel['filters'] ?? null; if (is_array($filters)) { $this->status = (string) ($filters['status'] ?? $this->status); $this->type = (string) ($filters['type'] ?? $this->type); $this->features = is_array($filters['features'] ?? null) ? $filters['features'] : $this->features; $this->search = (string) ($filters['search'] ?? $this->search); } } public function reRunVerificationUrl(): ?string { $tenant = Tenant::current(); if (! $tenant instanceof Tenant) { return null; } $connectionId = ProviderConnection::query() ->where('tenant_id', (int) $tenant->getKey()) ->orderByDesc('is_default') ->orderByDesc('id') ->value('id'); if (! is_int($connectionId)) { return ProviderConnectionResource::getUrl('index', tenant: $tenant); } return ProviderConnectionResource::getUrl('edit', ['record' => $connectionId], tenant: $tenant); } }