Skip to content

Commit

Permalink
Merge pull request #298 from jszobody/feature/add-record-actions
Browse files Browse the repository at this point in the history
addRecordActions method in Table
  • Loading branch information
danharrin authored Apr 11, 2021
2 parents b09c849 + a1b5567 commit 6115475
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/tables/resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class="border-gray-300 rounded shadow-sm text-primary-600 focus:border-primary-6
</td>
@endforeach

<td class="px-6 py-4 text-right whitespace-nowrap">
<td class="px-6 py-4 whitespace-nowrap flex justify-end items-center space-x-2">
@foreach ($table->getRecordActions() as $recordAction)
{{ $recordAction->render($record) }}
@endforeach
Expand Down
24 changes: 21 additions & 3 deletions packages/tables/src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,32 @@ public function primaryColumnUrl($url, $shouldOpenInNewTab = false)
public function recordActions($actions)
{
$this->recordActions = collect(value($actions))
->map(function ($action) {
return $action->table($this);
})
->map(fn ($action) => $action->table($this))
->toArray();

return $this;
}

public function pushRecordActions($actions)
{
$this->recordActions = array_merge(
$this->recordActions,
collect(value($actions))->map(fn ($action) => $action->table($this))->toArray(),
);

return $this;
}

public function prependRecordActions($actions)
{
$this->recordActions = array_merge(
collect(value($actions))->map(fn ($action) => $action->table($this))->toArray(),
$this->recordActions,
);

return $this;
}

public function reorder($order)
{
$callback = $this->reorderUsing;
Expand Down

0 comments on commit 6115475

Please sign in to comment.