File tree Expand file tree Collapse file tree 9 files changed +66
-12
lines changed
forms/resources/views/components Expand file tree Collapse file tree 9 files changed +66
-12
lines changed Original file line number Diff line number Diff line change 61
61
FilePond.registerPlugin(FilePondPluginImageTransform)
62
62
63
63
let config = {
64
- acceptedFileTypes: @json ($formComponent -> acceptedFileTypes ),
64
+ acceptedFileTypes: {{ json_encode ($formComponent -> acceptedFileTypes ) } } ,
65
65
files: [],
66
66
{{ $formComponent -> imageCropAspectRatio !== null ? " imageCropAspectRatio: '{$formComponent -> imageCropAspectRatio }'," : null } }
67
67
{{ $formComponent -> imagePreviewHeight !== null ? " imagePreviewHeight: {$formComponent -> imagePreviewHeight }," : null } }
Original file line number Diff line number Diff line change 13
13
@endphp
14
14
15
15
@if ($iconToShow )
16
- @if ($column -> action )
16
+ @if ($column -> getAction ( $record ) !== null )
17
17
<button
18
- wire:click =" {{ $column -> action } } ('{{ $record -> getKey () } } ')"
18
+ wire:click =" {{ $column -> getAction ( $record ) } } ('{{ $record -> getKey () } } ')"
19
19
type =" button"
20
20
>
21
21
<x-dynamic-component :component =" $iconToShow" class =" {{ $classes ?? null } } w-6 h-6" />
22
22
</button >
23
- @elseif ($column -> url )
23
+ @elseif ($column -> getUrl ( $record ) !== null )
24
24
<a
25
25
href =" {{ $column -> getUrl ($record ) } }"
26
26
@if ($column -> shouldOpenUrlInNewTab )
27
- target =" _blank"
28
- rel =" noopener noreferrer"
27
+ target =" _blank"
28
+ rel =" noopener noreferrer"
29
29
@endif
30
30
>
31
31
<x-dynamic-component :component =" $iconToShow" class =" {{ $classes ?? null } } w-6 h-6" />
Original file line number Diff line number Diff line change 1
- @if ($column -> action )
1
+ @if ($column -> getAction ( $record ) !== null )
2
2
<button
3
- wire:click =" {{ $column -> action } } ('{{ $record -> getKey () } } ')"
3
+ wire:click =" {{ $column -> getAction ( $record ) } } ('{{ $record -> getKey () } } ')"
4
4
type =" button"
5
5
>
6
6
<img
@@ -12,7 +12,7 @@ class="{{ $column->rounded ? 'rounded-full' : null }}"
12
12
"
13
13
/>
14
14
</button >
15
- @elseif ($column -> url )
15
+ @elseif ($column -> getUrl ( $record ) !== null )
16
16
<a
17
17
href =" {{ $column -> getUrl ($record ) } }"
18
18
@if ($column -> shouldOpenUrlInNewTab )
Original file line number Diff line number Diff line change 3
3
@endphp
4
4
5
5
<div class =" py-4" >
6
- @if ($column -> action )
6
+ @if ($column -> getAction ( $record ) !== null )
7
7
<button
8
- wire:click =" {{ $column -> action } } ('{{ $record -> getKey () } } ')"
8
+ wire:click =" {{ $column -> getAction ( $record ) } } ('{{ $record -> getKey () } } ')"
9
9
type =" button"
10
10
class =" {{ $primaryClasses } } hover:underline hover:text-primary-600 transition-colors duration-200"
11
11
>
12
12
{{ $column -> getValue ($record ) } }
13
13
</button >
14
- @elseif ($column -> url )
14
+ @elseif ($column -> getUrl ( $record ) !== null )
15
15
<a
16
16
href =" {{ $column -> getUrl ($record ) } }"
17
17
class =" {{ $primaryClasses } } hover:underline hover:text-primary-600 transition-colors duration-200"
Original file line number Diff line number Diff line change @@ -12,4 +12,17 @@ public function action($action)
12
12
13
13
return $ this ;
14
14
}
15
+
16
+ public function getAction ($ record )
17
+ {
18
+ if ($ this ->action === null ) return null ;
19
+
20
+ if (is_callable ($ this ->action )) {
21
+ $ callback = $ this ->action ;
22
+
23
+ return $ callback ($ record );
24
+ }
25
+
26
+ return $ this ->action ;
27
+ }
15
28
}
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ trait CanOpenUrl
10
10
11
11
public function getUrl ($ record )
12
12
{
13
+ if ($ this ->url === null ) return null ;
14
+
13
15
if (is_callable ($ this ->url )) {
14
16
$ callback = $ this ->url ;
15
17
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ class Table
12
12
13
13
public $ pagination = true ;
14
14
15
+ public $ primaryColumnAction ;
16
+
17
+ public $ primaryColumnUrl ;
18
+
15
19
public $ recordActions = [];
16
20
17
21
public $ searchable = true ;
@@ -138,6 +142,28 @@ public function pagination($enabled)
138
142
return $ this ;
139
143
}
140
144
145
+ public function primaryRecordAction ($ action )
146
+ {
147
+ $ this ->columns = collect ($ this ->columns )
148
+ ->map (function ($ column ) use ($ action ) {
149
+ return $ column ->action ($ action );
150
+ })
151
+ ->toArray ();
152
+
153
+ return $ this ;
154
+ }
155
+
156
+ public function primaryRecordUrl ($ url )
157
+ {
158
+ $ this ->columns = collect ($ this ->columns )
159
+ ->map (function ($ column ) use ($ url ) {
160
+ return $ column ->url ($ url );
161
+ })
162
+ ->toArray ();
163
+
164
+ return $ this ;
165
+ }
166
+
141
167
public function recordActions ($ actions )
142
168
{
143
169
$ this ->recordActions = $ actions ;
Original file line number Diff line number Diff line change @@ -80,6 +80,14 @@ public function getTable()
80
80
->context (static ::class)
81
81
->filterable ($ this ->filterable )
82
82
->pagination ($ this ->pagination )
83
+ ->primaryRecordUrl (function ($ record ) {
84
+ if (! Filament::can ('update ' , $ record )) return ;
85
+
86
+ return $ this ->getResource ()::generateUrl (
87
+ $ this ->recordRoute ,
88
+ ['record ' => $ record ],
89
+ );
90
+ })
83
91
->recordActions ([
84
92
RecordActions \Link::make ('edit ' )
85
93
->label (static ::$ editRecordActionLabel )
Original file line number Diff line number Diff line change @@ -166,6 +166,11 @@ public function getTable()
166
166
return static ::table (Table::make ())
167
167
->filterable ($ this ->filterable )
168
168
->pagination (false )
169
+ ->primaryRecordAction (function ($ record ) {
170
+ if (! Filament::can ('update ' , $ record )) return ;
171
+
172
+ return 'openEdit ' ;
173
+ })
169
174
->recordActions ([
170
175
RecordActions \Link::make ('edit ' )
171
176
->label (static ::$ editRecordActionLabel )
You can’t perform that action at this time.
0 commit comments