From 59f34a8c0cfa14e21c45b9b20a36b8d6a9ec0bbc Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 26 Mar 2021 22:36:55 -0400 Subject: [PATCH 1/5] addRecordActions method in Table --- packages/tables/src/Table.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/tables/src/Table.php b/packages/tables/src/Table.php index 09a35576d86..c45c5cc8e9f 100644 --- a/packages/tables/src/Table.php +++ b/packages/tables/src/Table.php @@ -204,14 +204,24 @@ 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 addRecordActions($actions) + { + $this->recordActions = array_merge( + $this->recordActions, + collect(value($actions)) + ->map(fn ($action) => $action->table($this)) + ->toArray() + ); + + return $this; + } + public function reorder($order) { $callback = $this->reorderUsing; From 337eded478640443b2fcf4ac77c407358ff73bc0 Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 26 Mar 2021 23:12:46 -0400 Subject: [PATCH 2/5] manually keep the Edit link as last action --- packages/tables/src/Table.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/tables/src/Table.php b/packages/tables/src/Table.php index c45c5cc8e9f..12fc52d031d 100644 --- a/packages/tables/src/Table.php +++ b/packages/tables/src/Table.php @@ -212,6 +212,10 @@ public function recordActions($actions) public function addRecordActions($actions) { + if(last($this->recordActions)->getName() == "edit") { + $edit = array_pop($this->recordActions); + } + $this->recordActions = array_merge( $this->recordActions, collect(value($actions)) @@ -219,6 +223,10 @@ public function addRecordActions($actions) ->toArray() ); + if(isset($edit)) { + $this->recordActions[] = $edit; + } + return $this; } From d7c52e38ae14121acb0b6d8ee41efcd813d9a7d9 Mon Sep 17 00:00:00 2001 From: Joseph Date: Sat, 27 Mar 2021 09:46:54 -0400 Subject: [PATCH 3/5] table action styling --- packages/tables/resources/views/components/table.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tables/resources/views/components/table.blade.php b/packages/tables/resources/views/components/table.blade.php index c4361202f73..8faf869e8ce 100644 --- a/packages/tables/resources/views/components/table.blade.php +++ b/packages/tables/resources/views/components/table.blade.php @@ -89,7 +89,7 @@ class="border-gray-300 rounded shadow-sm text-primary-600 focus:border-primary-6 @endforeach - + @foreach ($table->getRecordActions() as $recordAction) {{ $recordAction->render($record) }} @endforeach From 767529aaf93b9f181a80da113482f2b8b1917d29 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Sun, 11 Apr 2021 23:21:12 +0100 Subject: [PATCH 4/5] Refactor to push() and prepend() --- packages/tables/src/Table.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/tables/src/Table.php b/packages/tables/src/Table.php index 12fc52d031d..a39440d290b 100644 --- a/packages/tables/src/Table.php +++ b/packages/tables/src/Table.php @@ -210,22 +210,24 @@ public function recordActions($actions) return $this; } - public function addRecordActions($actions) + public function pushRecordActions($actions) { - if(last($this->recordActions)->getName() == "edit") { - $edit = array_pop($this->recordActions); - } + $this->recordActions = collect($this->recordActions) + ->push( + collect(value($actions))->map(fn ($action) => $action->table($this)) + ) + ->toArray(); - $this->recordActions = array_merge( - $this->recordActions, - collect(value($actions)) - ->map(fn ($action) => $action->table($this)) - ->toArray() - ); + return $this; + } - if(isset($edit)) { - $this->recordActions[] = $edit; - } + public function prependRecordActions($actions) + { + $this->recordActions = collect($this->recordActions) + ->prepend( + collect(value($actions))->map(fn ($action) => $action->table($this)) + ) + ->toArray(); return $this; } From a1b55671cdec3cd16d483b716ba7c2f1af8b9911 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Sun, 11 Apr 2021 23:44:44 +0100 Subject: [PATCH 5/5] Update Table.php --- packages/tables/src/Table.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/tables/src/Table.php b/packages/tables/src/Table.php index a39440d290b..b9224ea12ec 100644 --- a/packages/tables/src/Table.php +++ b/packages/tables/src/Table.php @@ -212,22 +212,20 @@ public function recordActions($actions) public function pushRecordActions($actions) { - $this->recordActions = collect($this->recordActions) - ->push( - collect(value($actions))->map(fn ($action) => $action->table($this)) - ) - ->toArray(); + $this->recordActions = array_merge( + $this->recordActions, + collect(value($actions))->map(fn ($action) => $action->table($this))->toArray(), + ); return $this; } public function prependRecordActions($actions) { - $this->recordActions = collect($this->recordActions) - ->prepend( - collect(value($actions))->map(fn ($action) => $action->table($this)) - ) - ->toArray(); + $this->recordActions = array_merge( + collect(value($actions))->map(fn ($action) => $action->table($this))->toArray(), + $this->recordActions, + ); return $this; }