Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Mar 10, 2021
2 parents 9b40b04 + eb2a9e5 commit c05cef1
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
FilePond.registerPlugin(FilePondPluginImageTransform)
let config = {
acceptedFileTypes: @json($formComponent->acceptedFileTypes),
acceptedFileTypes: {{ json_encode($formComponent->acceptedFileTypes) }},
files: [],
{{ $formComponent->imageCropAspectRatio !== null ? "imageCropAspectRatio: '{$formComponent->imageCropAspectRatio}'," : null }}
{{ $formComponent->imagePreviewHeight !== null ? "imagePreviewHeight: {$formComponent->imagePreviewHeight}," : null }}
Expand Down
10 changes: 5 additions & 5 deletions packages/tables/resources/views/cells/icon.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
@endphp

@if ($iconToShow)
@if ($column->action)
@if ($column->getAction($record) !== null)
<button
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
type="button"
>
<x-dynamic-component :component="$iconToShow" class="{{ $classes ?? null }} w-6 h-6" />
</button>
@elseif ($column->url)
@elseif ($column->getUrl($record) !== null)
<a
href="{{ $column->getUrl($record) }}"
@if ($column->shouldOpenUrlInNewTab)
target="_blank"
rel="noopener noreferrer"
target="_blank"
rel="noopener noreferrer"
@endif
>
<x-dynamic-component :component="$iconToShow" class="{{ $classes ?? null }} w-6 h-6" />
Expand Down
6 changes: 3 additions & 3 deletions packages/tables/resources/views/cells/image.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@if ($column->action)
@if ($column->getAction($record) !== null)
<button
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
type="button"
>
<img
Expand All @@ -12,7 +12,7 @@ class="{{ $column->rounded ? 'rounded-full' : null }}"
"
/>
</button>
@elseif ($column->url)
@elseif ($column->getUrl($record) !== null)
<a
href="{{ $column->getUrl($record) }}"
@if ($column->shouldOpenUrlInNewTab)
Expand Down
6 changes: 3 additions & 3 deletions packages/tables/resources/views/cells/text.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
@endphp

<div class="py-4">
@if ($column->action)
@if ($column->getAction($record) !== null)
<button
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
type="button"
class="{{ $primaryClasses }} hover:underline hover:text-primary-600 transition-colors duration-200"
>
{{ $column->getValue($record) }}
</button>
@elseif ($column->url)
@elseif ($column->getUrl($record) !== null)
<a
href="{{ $column->getUrl($record) }}"
class="{{ $primaryClasses }} hover:underline hover:text-primary-600 transition-colors duration-200"
Expand Down
13 changes: 13 additions & 0 deletions packages/tables/src/Columns/Concerns/CanCallAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,17 @@ public function action($action)

return $this;
}

public function getAction($record)
{
if ($this->action === null) return null;

if (is_callable($this->action)) {
$callback = $this->action;

return $callback($record);
}

return $this->action;
}
}
2 changes: 2 additions & 0 deletions packages/tables/src/Columns/Concerns/CanOpenUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ trait CanOpenUrl

public function getUrl($record)
{
if ($this->url === null) return null;

if (is_callable($this->url)) {
$callback = $this->url;

Expand Down
26 changes: 26 additions & 0 deletions packages/tables/src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Table

public $pagination = true;

public $primaryColumnAction;

public $primaryColumnUrl;

public $recordActions = [];

public $searchable = true;
Expand Down Expand Up @@ -138,6 +142,28 @@ public function pagination($enabled)
return $this;
}

public function primaryRecordAction($action)
{
$this->columns = collect($this->columns)
->map(function ($column) use ($action) {
return $column->action($action);
})
->toArray();

return $this;
}

public function primaryRecordUrl($url)
{
$this->columns = collect($this->columns)
->map(function ($column) use ($url) {
return $column->url($url);
})
->toArray();

return $this;
}

public function recordActions($actions)
{
$this->recordActions = $actions;
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/Pages/ListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public function getTable()
->context(static::class)
->filterable($this->filterable)
->pagination($this->pagination)
->primaryRecordUrl(function ($record) {
if (! Filament::can('update', $record)) return;

return $this->getResource()::generateUrl(
$this->recordRoute,
['record' => $record],
);
})
->recordActions([
RecordActions\Link::make('edit')
->label(static::$editRecordActionLabel)
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/RelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public function getTable()
return static::table(Table::make())
->filterable($this->filterable)
->pagination(false)
->primaryRecordAction(function ($record) {
if (! Filament::can('update', $record)) return;

return 'openEdit';
})
->recordActions([
RecordActions\Link::make('edit')
->label(static::$editRecordActionLabel)
Expand Down

0 comments on commit c05cef1

Please sign in to comment.