|
2 | 2 |
|
3 | 3 | namespace Backstage\Filament\Users\Resources\UserResource\Pages; |
4 | 4 |
|
5 | | -use BackedEnum; |
6 | 5 | use Backstage\Filament\Users\Actions\GenerateSignedRegistrationUri; |
7 | 6 | use Backstage\Filament\Users\Models\User; |
8 | 7 | use Backstage\Filament\Users\Resources\UserResource\UserResource; |
9 | | -use Backstage\Laravel\Users\Eloquent\Models\UserTraffic; |
10 | 8 | use Filament\Actions; |
11 | | -use Filament\Actions\Action; |
12 | 9 | use Filament\Auth\Notifications\ResetPassword; |
13 | 10 | use Filament\Auth\Notifications\VerifyEmail; |
14 | 11 | use Filament\Facades\Filament; |
15 | | -use Filament\Infolists\Components\KeyValueEntry; |
16 | | -use Filament\Infolists\Components\TextEntry; |
17 | 12 | use Filament\Resources\Pages\ViewRecord; |
18 | | -use Filament\Schemas\Components\Grid; |
19 | | -use Filament\Schemas\Components\Section; |
20 | | -use Filament\Support\Enums\Alignment; |
21 | | -use Filament\Support\Icons\Heroicon; |
22 | | -use Filament\Tables\Columns\TextColumn; |
23 | | -use Filament\Tables\Concerns\InteractsWithTable; |
24 | | -use Filament\Tables\Contracts\HasTable; |
25 | | -use Filament\Tables\Table; |
26 | 13 | use Illuminate\Contracts\Support\Htmlable; |
27 | | -use Illuminate\Database\Eloquent\Builder; |
28 | 14 | use Illuminate\Database\Eloquent\Model; |
29 | 15 | use Illuminate\Support\Facades\Blade; |
30 | 16 | use Illuminate\Support\HtmlString; |
31 | 17 |
|
32 | | -class ViewUser extends ViewRecord implements HasTable |
| 18 | +class ViewUser extends ViewRecord |
33 | 19 | { |
34 | | - use InteractsWithTable { |
35 | | - makeTable as makeBaseTable; |
36 | | - } |
37 | | - |
38 | 20 | protected static string $resource = UserResource::class; |
39 | 21 |
|
40 | 22 | protected function getHeaderActions(): array |
@@ -121,142 +103,4 @@ public function getSubheading(): string | Htmlable | null |
121 | 103 |
|
122 | 104 | return new HtmlString(Blade::render($string->toString())); |
123 | 105 | } |
124 | | - |
125 | | - public function table(Table $table): Table |
126 | | - { |
127 | | - return $table |
128 | | - ->query(fn (): Builder => $this->record->traffic()->whereNot('path', 'livewire/update')->orderByDesc('created_at')->getQuery()) |
129 | | - ->heading(fn ($table): Htmlable => new HtmlString(Blade::render('<filament::icon icon="heroicon-m-user"/>' . __('User Traffic (:count)', [ |
130 | | - 'count' => $table->getQuery()->count(), |
131 | | - ])))) |
132 | | - ->searchable($table->getQuery()->count() > 0) |
133 | | - ->paginated([4]) |
134 | | - ->columns([ |
135 | | - TextColumn::make('path') |
136 | | - ->label(__('Path')) |
137 | | - ->searchable(), |
138 | | - ]) |
139 | | - ->headerActions([ |
140 | | - Action::make('reset') |
141 | | - ->label(__('Reset position')) |
142 | | - ->icon(fn (): BackedEnum => Heroicon::ArrowUturnLeft) |
143 | | - ->url(fn (): string => $this->getUrl([ |
144 | | - 'record' => $this->record, |
145 | | - ])) |
146 | | - ->visible(function () { |
147 | | - $tableRecords = $this->getTableRecords(); |
148 | | - |
149 | | - $firstFourRecords = $this->getTable()->getQuery()->take(4)->get(); |
150 | | - |
151 | | - $recordIds = $firstFourRecords->pluck('id')->toArray(); |
152 | | - $tableRecords = $tableRecords->pluck('id')->toArray(); |
153 | | - |
154 | | - if ($tableRecords === $recordIds) { |
155 | | - return false; |
156 | | - } |
157 | | - |
158 | | - return true; |
159 | | - }), |
160 | | - |
161 | | - Action::make('clear_activity') |
162 | | - ->label(__('Clear Activity')) |
163 | | - ->color(fn (): string => 'danger') |
164 | | - ->icon(fn (): BackedEnum => Heroicon::Trash) |
165 | | - ->action(function (Model $record): void { |
166 | | - $record->traffic()->delete(); |
167 | | - }) |
168 | | - ->requiresConfirmation() |
169 | | - ->modalDescription(__('This action will delete all traffic records for this user. This action cannot be undone.')) |
170 | | - ->visible(fn (User $record): bool => $record->traffic()->exists() && $record->traffic()->whereNot('path', 'livewire/update')->exists()), |
171 | | - ]) |
172 | | - ->recordAction('view') |
173 | | - ->recordActions([ |
174 | | - Action::make('visit') |
175 | | - ->button() |
176 | | - ->hiddenLabel() |
177 | | - ->color(fn (): string => 'primary') |
178 | | - ->tooltip(fn (): string => __('Visit Path')) |
179 | | - ->icon(fn (): BackedEnum => Heroicon::ArrowTopRightOnSquare) |
180 | | - ->url(fn (UserTraffic $record): string => $record->getAttribute('full_url'), true), |
181 | | - |
182 | | - Action::make('view') |
183 | | - ->button() |
184 | | - ->hiddenLabel() |
185 | | - ->color(fn (): string => 'gray') |
186 | | - ->tooltip(fn (): string => __('View Traffic')) |
187 | | - ->icon(fn (): BackedEnum => Heroicon::Eye) |
188 | | - ->slideOver() |
189 | | - ->modal() |
190 | | - ->modalIcon(fn (): BackedEnum => Heroicon::Eye) |
191 | | - ->modalHeading(fn (): string => __('Traffic Details')) |
192 | | - ->modalDescription(fn (UserTraffic $record): Htmlable => new HtmlString(__('Traffic details for :path', [ |
193 | | - 'path' => '<a href="' . e($record->getAttribute('full_url')) . '" target="_blank" class="text-primary-600 underline">' . e($record->getAttribute('path')) . '</a>', |
194 | | - ]))) |
195 | | - ->schema([ |
196 | | - Section::make(__('Request Information')) |
197 | | - ->description(__('Details about the HTTP request.')) |
198 | | - ->icon('heroicon-o-globe-alt') |
199 | | - ->schema([ |
200 | | - Grid::make(3) |
201 | | - ->schema([ |
202 | | - TextEntry::make('method') |
203 | | - ->label(__('Method')) |
204 | | - ->badge() |
205 | | - ->color(fn (string $state): string => match ($state) { |
206 | | - 'GET' => 'success', |
207 | | - 'POST' => 'primary', |
208 | | - 'PUT' => 'warning', |
209 | | - 'DELETE' => 'danger', |
210 | | - default => 'gray', |
211 | | - }) |
212 | | - ->copyable(), |
213 | | - |
214 | | - TextEntry::make('ip') |
215 | | - ->label(__('IP Address')) |
216 | | - ->copyable(), |
217 | | - |
218 | | - TextEntry::make('user_agent') |
219 | | - ->label(__('User Agent')) |
220 | | - ->copyable(), |
221 | | - ]) |
222 | | - ->columnSpanFull(), |
223 | | - |
224 | | - Grid::make(2) |
225 | | - ->schema([ |
226 | | - TextEntry::make('full_url') |
227 | | - ->label(__('Full URL')) |
228 | | - ->copyable(), |
229 | | - |
230 | | - TextEntry::make('referer') |
231 | | - ->label(__('Source Referer')) |
232 | | - ->copyable(), |
233 | | - ]) |
234 | | - ->columnSpanFull(), |
235 | | - ]) |
236 | | - ->columns(1), |
237 | | - |
238 | | - Section::make(__('Route Details')) |
239 | | - ->description(__('Matched route and resolved parameters.')) |
240 | | - ->icon('heroicon-o-arrow-path') |
241 | | - ->schema([ |
242 | | - TextEntry::make('route_name') |
243 | | - ->label(__('Route Name')) |
244 | | - ->columnSpan(1), |
245 | | - |
246 | | - TextEntry::make('route_action') |
247 | | - ->label(__('Route Action')) |
248 | | - ->columnSpan(1), |
249 | | - |
250 | | - KeyValueEntry::make('route_parameters') |
251 | | - ->label(__('Route Parameters')) |
252 | | - ->columnSpanFull(), |
253 | | - ]) |
254 | | - ->columns(2), |
255 | | - |
256 | | - ]) |
257 | | - ->modalFooterActionsAlignment(Alignment::Center) |
258 | | - ->modalSubmitAction(fn (Action $action) => $action->visible(false)) |
259 | | - ->modalCancelActionLabel(fn (): string => __('Close')), |
260 | | - ]); |
261 | | - } |
262 | 106 | } |
0 commit comments