importId = $importId ?: session('directadmin_self_migration.import_id'); } #[On('directadmin-self-status-updated')] public function refreshStatus(): void { $this->resetTable(); } public function makeFilamentTranslatableContentDriver(): ?TranslatableContentDriver { return null; } protected function getImport(): ?ServerImport { if (! $this->importId) { return null; } return ServerImport::find($this->importId); } /** * @return \Illuminate\Support\Collection */ protected function getRecords() { if (! $this->importId) { return collect(); } return ServerImportAccount::query() ->where('server_import_id', $this->importId) ->orderBy('source_username') ->get(); } protected function shouldPoll(): bool { $import = $this->getImport(); if (! $import) { return false; } if (in_array($import->status, ['discovering', 'importing'], true)) { return true; } foreach ($this->getRecords() as $record) { if (! in_array($record->status, ['completed', 'failed', 'skipped'], true)) { return true; } } return false; } protected function getStatusText(string $status): string { return match ($status) { 'pending' => __('Waiting...'), 'importing' => __('Importing...'), 'completed' => __('Completed'), 'failed' => __('Failed'), 'skipped' => __('Skipped'), default => __('Unknown'), }; } public function table(Table $table): Table { return $table ->records(fn () => $this->getRecords()) ->columns([ IconColumn::make('status_icon') ->label('') ->icon(fn (ServerImportAccount $record): string => match ($record->status) { 'pending' => 'heroicon-o-clock', 'importing' => 'heroicon-o-arrow-path', 'completed' => 'heroicon-o-check-circle', 'failed' => 'heroicon-o-x-circle', 'skipped' => 'heroicon-o-minus-circle', default => 'heroicon-o-question-mark-circle', }) ->color(fn (ServerImportAccount $record): string => match ($record->status) { 'pending' => 'gray', 'importing' => 'warning', 'completed' => 'success', 'failed' => 'danger', 'skipped' => 'gray', default => 'gray', }) ->size(IconSize::Small) ->extraAttributes(fn (ServerImportAccount $record): array => $record->status === 'importing' ? ['class' => 'animate-spin'] : []), TextColumn::make('source_username') ->label(__('Account')) ->weight(FontWeight::Bold) ->searchable(), TextColumn::make('status') ->label(__('Status')) ->badge() ->formatStateUsing(fn (string $state): string => $this->getStatusText($state)) ->color(fn (ServerImportAccount $record): string => match ($record->status) { 'pending' => 'gray', 'importing' => 'warning', 'completed' => 'success', 'failed' => 'danger', 'skipped' => 'gray', default => 'gray', }), TextColumn::make('current_task') ->label(__('Current Task')) ->wrap() ->limit(80) ->default(__('Waiting...')), TextColumn::make('progress') ->label(__('Progress')) ->suffix('%') ->toggleable(), ]) ->striped() ->paginated(false) ->poll($this->shouldPoll() ? '3s' : null) ->emptyStateHeading(__('No migration activity')) ->emptyStateDescription(__('Discover an account and start migration.')) ->emptyStateIcon('heroicon-o-queue-list'); } public function render() { return $this->getTable()->render(); } }