|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Usamamuneerchaudhary\Commentify\Filament\Resources\CommentResource\RelationManagers; |
|
4
|
|
|
|
|
5
|
|
|
use Filament\Forms; |
|
|
|
|
|
|
6
|
|
|
use Filament\Resources\RelationManagers\RelationManager; |
|
|
|
|
|
|
7
|
|
|
use Filament\Schemas\Schema; |
|
|
|
|
|
|
8
|
|
|
use Filament\Tables; |
|
|
|
|
|
|
9
|
|
|
use Filament\Tables\Table; |
|
|
|
|
|
|
10
|
|
|
use Usamamuneerchaudhary\Commentify\Models\CommentReport; |
|
11
|
|
|
|
|
12
|
|
|
class ReportsRelationManager extends RelationManager |
|
13
|
|
|
{ |
|
14
|
|
|
protected static string $relationship = 'reports'; |
|
15
|
|
|
|
|
16
|
|
|
protected static ?string $title = 'Reports'; |
|
17
|
|
|
|
|
18
|
|
|
protected static ?string $recordTitleAttribute = 'id'; |
|
19
|
|
|
|
|
20
|
|
|
public function form(Schema $schema): Schema |
|
21
|
|
|
{ |
|
22
|
|
|
return $schema |
|
23
|
|
|
->schema([ |
|
24
|
|
|
Forms\Components\Select::make('user_id') |
|
|
|
|
|
|
25
|
|
|
->relationship('user', 'name') |
|
26
|
|
|
->searchable() |
|
27
|
|
|
->nullable() |
|
28
|
|
|
->disabled(), |
|
29
|
|
|
Forms\Components\TextInput::make('ip') |
|
|
|
|
|
|
30
|
|
|
->label('IP Address') |
|
31
|
|
|
->disabled(), |
|
32
|
|
|
Forms\Components\Textarea::make('reason') |
|
|
|
|
|
|
33
|
|
|
->required() |
|
34
|
|
|
->maxLength(1000) |
|
35
|
|
|
->rows(4) |
|
36
|
|
|
->columnSpanFull() |
|
37
|
|
|
->disabled(), |
|
38
|
|
|
Forms\Components\Select::make('status') |
|
39
|
|
|
->options([ |
|
40
|
|
|
'pending' => 'Pending', |
|
41
|
|
|
'reviewed' => 'Reviewed', |
|
42
|
|
|
'dismissed' => 'Dismissed', |
|
43
|
|
|
]) |
|
44
|
|
|
->required() |
|
45
|
|
|
->default('pending'), |
|
46
|
|
|
Forms\Components\Select::make('reviewed_by') |
|
47
|
|
|
->relationship('reviewer', 'name') |
|
48
|
|
|
->searchable() |
|
49
|
|
|
->nullable() |
|
50
|
|
|
->visible(fn ($get) => $get('status') !== 'pending'), |
|
51
|
|
|
Forms\Components\DateTimePicker::make('reviewed_at') |
|
|
|
|
|
|
52
|
|
|
->visible(fn ($get) => $get('status') !== 'pending'), |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function table(Table $table): Table |
|
57
|
|
|
{ |
|
58
|
|
|
return $table |
|
59
|
|
|
->recordTitleAttribute('id') |
|
60
|
|
|
->columns([ |
|
61
|
|
|
Tables\Columns\TextColumn::make('id') |
|
|
|
|
|
|
62
|
|
|
->label('ID') |
|
63
|
|
|
->sortable(), |
|
64
|
|
|
Tables\Columns\TextColumn::make('user.name') |
|
65
|
|
|
->label('Reporter') |
|
66
|
|
|
->sortable() |
|
67
|
|
|
->searchable() |
|
68
|
|
|
->default('Guest'), |
|
69
|
|
|
Tables\Columns\TextColumn::make('ip') |
|
70
|
|
|
->label('IP Address') |
|
71
|
|
|
->searchable() |
|
72
|
|
|
->toggleable(), |
|
73
|
|
|
Tables\Columns\TextColumn::make('reason') |
|
74
|
|
|
->label('Reason') |
|
75
|
|
|
->limit(50) |
|
76
|
|
|
->wrap() |
|
77
|
|
|
->searchable(), |
|
78
|
|
|
Tables\Columns\TextColumn::make('status') |
|
79
|
|
|
->badge() |
|
80
|
|
|
->color(fn (string $state): string => match ($state) { |
|
81
|
|
|
'pending' => 'warning', |
|
82
|
|
|
'reviewed' => 'success', |
|
83
|
|
|
'dismissed' => 'danger', |
|
84
|
|
|
default => 'gray', |
|
85
|
|
|
}) |
|
86
|
|
|
->sortable(), |
|
87
|
|
|
Tables\Columns\TextColumn::make('reviewer.name') |
|
88
|
|
|
->label('Reviewed By') |
|
89
|
|
|
->sortable() |
|
90
|
|
|
->toggleable(), |
|
91
|
|
|
Tables\Columns\TextColumn::make('reviewed_at') |
|
92
|
|
|
->dateTime() |
|
93
|
|
|
->sortable() |
|
94
|
|
|
->toggleable(), |
|
95
|
|
|
Tables\Columns\TextColumn::make('created_at') |
|
96
|
|
|
->dateTime() |
|
97
|
|
|
->sortable(), |
|
98
|
|
|
]) |
|
99
|
|
|
->filters([ |
|
100
|
|
|
Tables\Filters\SelectFilter::make('status') |
|
|
|
|
|
|
101
|
|
|
->options([ |
|
102
|
|
|
'pending' => 'Pending', |
|
103
|
|
|
'reviewed' => 'Reviewed', |
|
104
|
|
|
'dismissed' => 'Dismissed', |
|
105
|
|
|
]), |
|
106
|
|
|
]) |
|
107
|
|
|
->headerActions([ |
|
108
|
|
|
// Tables\Actions\CreateAction::make(), |
|
109
|
|
|
]) |
|
110
|
|
|
->recordActions([ |
|
111
|
|
|
\Filament\Actions\ViewAction::make(), |
|
|
|
|
|
|
112
|
|
|
\Filament\Actions\EditAction::make(), |
|
|
|
|
|
|
113
|
|
|
\Filament\Actions\Action::make('review') |
|
|
|
|
|
|
114
|
|
|
->label('Mark as Reviewed') |
|
115
|
|
|
->icon('heroicon-o-check-circle') |
|
116
|
|
|
->color('success') |
|
117
|
|
|
->requiresConfirmation() |
|
118
|
|
|
->visible(fn (CommentReport $record) => $record->status === 'pending') |
|
119
|
|
|
->action(function (CommentReport $record) { |
|
120
|
|
|
$record->update([ |
|
121
|
|
|
'status' => 'reviewed', |
|
122
|
|
|
'reviewed_by' => auth()->id(), |
|
123
|
|
|
'reviewed_at' => now(), |
|
124
|
|
|
]); |
|
125
|
|
|
}), |
|
126
|
|
|
\Filament\Actions\Action::make('dismiss') |
|
127
|
|
|
->label('Dismiss') |
|
128
|
|
|
->icon('heroicon-o-x-circle') |
|
129
|
|
|
->color('danger') |
|
130
|
|
|
->requiresConfirmation() |
|
131
|
|
|
->visible(fn (CommentReport $record) => $record->status === 'pending') |
|
132
|
|
|
->action(function (CommentReport $record) { |
|
133
|
|
|
$record->update([ |
|
134
|
|
|
'status' => 'dismissed', |
|
135
|
|
|
'reviewed_by' => auth()->id(), |
|
136
|
|
|
'reviewed_at' => now(), |
|
137
|
|
|
]); |
|
138
|
|
|
}), |
|
139
|
|
|
]) |
|
140
|
|
|
->toolbarActions([ |
|
141
|
|
|
\Filament\Actions\BulkActionGroup::make([ |
|
|
|
|
|
|
142
|
|
|
\Filament\Actions\BulkAction::make('mark_reviewed') |
|
|
|
|
|
|
143
|
|
|
->label('Mark as Reviewed') |
|
144
|
|
|
->icon('heroicon-o-check-circle') |
|
145
|
|
|
->color('success') |
|
146
|
|
|
->requiresConfirmation() |
|
147
|
|
|
->action(function ($records) { |
|
148
|
|
|
$records->each(function (CommentReport $record) { |
|
149
|
|
|
$record->update([ |
|
150
|
|
|
'status' => 'reviewed', |
|
151
|
|
|
'reviewed_by' => auth()->id(), |
|
152
|
|
|
'reviewed_at' => now(), |
|
153
|
|
|
]); |
|
154
|
|
|
}); |
|
155
|
|
|
}), |
|
156
|
|
|
\Filament\Actions\DeleteBulkAction::make(), |
|
|
|
|
|
|
157
|
|
|
]), |
|
158
|
|
|
]) |
|
159
|
|
|
->defaultSort('created_at', 'desc'); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths