importId = $importId ?: session('directadmin_migration.import_id'); } #[On('directadmin-config-updated')] #[On('directadmin-selection-updated')] public function refreshConfig(): void { $this->resetTable(); } public function makeFilamentTranslatableContentDriver(): ?TranslatableContentDriver { return null; } protected function getImport(): ?ServerImport { if (! $this->importId) { return null; } return ServerImport::find($this->importId); } /** * @return array */ protected function getSelectedAccountIds(): array { $selected = $this->getImport()?->selected_accounts ?? []; return array_values(array_filter(array_map('intval', is_array($selected) ? $selected : []))); } /** * @return \Illuminate\Support\Collection */ protected function getRecords() { if (! $this->importId) { return collect(); } $ids = $this->getSelectedAccountIds(); if ($ids === []) { return collect(); } return ServerImportAccount::query() ->where('server_import_id', $this->importId) ->whereIn('id', $ids) ->orderBy('source_username') ->get(); } public function table(Table $table): Table { return $table ->records(fn () => $this->getRecords()) ->columns([ IconColumn::make('target_user_exists') ->label(__('User')) ->boolean() ->trueIcon('heroicon-o-exclamation-triangle') ->falseIcon('heroicon-o-user-plus') ->trueColor('warning') ->falseColor('success') ->tooltip(fn (ServerImportAccount $record): string => User::where('username', $record->target_username)->exists() ? __('User exists - migration will restore into the existing account') : __('New user will be created')) ->getStateUsing(fn (ServerImportAccount $record): bool => User::where('username', $record->target_username)->exists()), TextColumn::make('source_username') ->label(__('Source')) ->weight('bold'), TextColumn::make('main_domain') ->label(__('Main Domain')) ->wrap(), TextInputColumn::make('target_username') ->label(__('Target Username')) ->rules([ 'required', 'max:32', 'regex:/^[a-z0-9_]+$/i', ]), TextInputColumn::make('email') ->label(__('Email')) ->rules([ 'nullable', 'email', 'max:255', ]), TextColumn::make('formatted_disk_usage') ->label(__('Disk')) ->toggleable(), ]) ->striped() ->paginated([10, 25, 50]) ->defaultPaginationPageOption(10) ->emptyStateHeading(__('No accounts selected')) ->emptyStateDescription(__('Go back and select accounts to migrate.')) ->emptyStateIcon('heroicon-o-user-group'); } public function render() { return $this->getTable()->render(); } }