Skip to content

Commit eb2a9e5

Browse files
committed
Primary column actions and urls
1 parent 5073d82 commit eb2a9e5

File tree

9 files changed

+66
-12
lines changed

9 files changed

+66
-12
lines changed

packages/forms/resources/views/components/file-upload.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
FilePond.registerPlugin(FilePondPluginImageTransform)
6262
6363
let config = {
64-
acceptedFileTypes: @json($formComponent->acceptedFileTypes),
64+
acceptedFileTypes: {{ json_encode($formComponent->acceptedFileTypes) }},
6565
files: [],
6666
{{ $formComponent->imageCropAspectRatio !== null ? "imageCropAspectRatio: '{$formComponent->imageCropAspectRatio}'," : null }}
6767
{{ $formComponent->imagePreviewHeight !== null ? "imagePreviewHeight: {$formComponent->imagePreviewHeight}," : null }}

packages/tables/resources/views/cells/icon.blade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
@endphp
1414

1515
@if ($iconToShow)
16-
@if ($column->action)
16+
@if ($column->getAction($record) !== null)
1717
<button
18-
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
18+
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
1919
type="button"
2020
>
2121
<x-dynamic-component :component="$iconToShow" class="{{ $classes ?? null }} w-6 h-6" />
2222
</button>
23-
@elseif ($column->url)
23+
@elseif ($column->getUrl($record) !== null)
2424
<a
2525
href="{{ $column->getUrl($record) }}"
2626
@if ($column->shouldOpenUrlInNewTab)
27-
target="_blank"
28-
rel="noopener noreferrer"
27+
target="_blank"
28+
rel="noopener noreferrer"
2929
@endif
3030
>
3131
<x-dynamic-component :component="$iconToShow" class="{{ $classes ?? null }} w-6 h-6" />

packages/tables/resources/views/cells/image.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
@if ($column->action)
1+
@if ($column->getAction($record) !== null)
22
<button
3-
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
3+
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
44
type="button"
55
>
66
<img
@@ -12,7 +12,7 @@ class="{{ $column->rounded ? 'rounded-full' : null }}"
1212
"
1313
/>
1414
</button>
15-
@elseif ($column->url)
15+
@elseif ($column->getUrl($record) !== null)
1616
<a
1717
href="{{ $column->getUrl($record) }}"
1818
@if ($column->shouldOpenUrlInNewTab)

packages/tables/resources/views/cells/text.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
@endphp
44

55
<div class="py-4">
6-
@if ($column->action)
6+
@if ($column->getAction($record) !== null)
77
<button
8-
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
8+
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
99
type="button"
1010
class="{{ $primaryClasses }} hover:underline hover:text-primary-600 transition-colors duration-200"
1111
>
1212
{{ $column->getValue($record) }}
1313
</button>
14-
@elseif ($column->url)
14+
@elseif ($column->getUrl($record) !== null)
1515
<a
1616
href="{{ $column->getUrl($record) }}"
1717
class="{{ $primaryClasses }} hover:underline hover:text-primary-600 transition-colors duration-200"

packages/tables/src/Columns/Concerns/CanCallAction.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@ public function action($action)
1212

1313
return $this;
1414
}
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+
}
1528
}

packages/tables/src/Columns/Concerns/CanOpenUrl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ trait CanOpenUrl
1010

1111
public function getUrl($record)
1212
{
13+
if ($this->url === null) return null;
14+
1315
if (is_callable($this->url)) {
1416
$callback = $this->url;
1517

packages/tables/src/Table.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class Table
1212

1313
public $pagination = true;
1414

15+
public $primaryColumnAction;
16+
17+
public $primaryColumnUrl;
18+
1519
public $recordActions = [];
1620

1721
public $searchable = true;
@@ -138,6 +142,28 @@ public function pagination($enabled)
138142
return $this;
139143
}
140144

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+
141167
public function recordActions($actions)
142168
{
143169
$this->recordActions = $actions;

src/Resources/Pages/ListRecords.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public function getTable()
8080
->context(static::class)
8181
->filterable($this->filterable)
8282
->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+
})
8391
->recordActions([
8492
RecordActions\Link::make('edit')
8593
->label(static::$editRecordActionLabel)

src/Resources/RelationManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public function getTable()
166166
return static::table(Table::make())
167167
->filterable($this->filterable)
168168
->pagination(false)
169+
->primaryRecordAction(function ($record) {
170+
if (! Filament::can('update', $record)) return;
171+
172+
return 'openEdit';
173+
})
169174
->recordActions([
170175
RecordActions\Link::make('edit')
171176
->label(static::$editRecordActionLabel)

0 commit comments

Comments
 (0)