From 85dca3a43c50ab8bef2c4ed8f884e2f801b82577 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Mon, 22 Jan 2024 09:19:26 -0300 Subject: [PATCH] Add actionsView feature --- resources/views/components/row.blade.php | 10 +++- resources/views/tests/actions-view.blade.php | 3 ++ src/Livewire/LazyChild.php | 13 +++++ tests/Feature/ActionsViewTest.php | 52 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 resources/views/tests/actions-view.blade.php create mode 100644 tests/Feature/ActionsViewTest.php diff --git a/resources/views/components/row.blade.php b/resources/views/components/row.blade.php index cb7f2cdb..046138bd 100644 --- a/resources/views/components/row.blade.php +++ b/resources/views/components/row.blade.php @@ -45,10 +45,18 @@ wire:key="row-{{ $column->field }}-{{ $childIndex }}" >
+ @if(empty(data_get($row, 'actions')) && $column->isAction) + @if (method_exists($this, 'actionsView') && $actionView = $this->actionsView($row)) +
+ {!! $actionView !!} +
+ @endif + @endif + @if (filled(data_get($row, 'actions')) && $column->isAction) @foreach (data_get($row, 'actions') as $key => $action) @if(filled($action)) -
+
{!! $action !!}
@endif diff --git a/resources/views/tests/actions-view.blade.php b/resources/views/tests/actions-view.blade.php new file mode 100644 index 00000000..a8ec03e8 --- /dev/null +++ b/resources/views/tests/actions-view.blade.php @@ -0,0 +1,3 @@ +
+ Dish From Actions View: {{ $row->id }} +
diff --git a/src/Livewire/LazyChild.php b/src/Livewire/LazyChild.php index 101e1df3..2c08b3c2 100644 --- a/src/Livewire/LazyChild.php +++ b/src/Livewire/LazyChild.php @@ -52,6 +52,19 @@ public function afterToggleDetail(string $id, string $state): void $this->dispatch($dispatchAfterToggleDetail, id: $id, state: $state ? 'true' : 'false')->to($parentComponent); } + public function actionsView(mixed $row): ?View + { + /** @var string $parentComponent */ + $parentComponent = app(ComponentRegistry::class)->getClass($this->parentName); + + if (method_exists($parentComponent, 'actionsView')) { + return app($parentComponent)->actionsView($row); + + } + + return null; + } + public function render(): View { return view('livewire-powergrid::livewire.lazy-child'); diff --git a/tests/Feature/ActionsViewTest.php b/tests/Feature/ActionsViewTest.php new file mode 100644 index 00000000..f9ff5ec3 --- /dev/null +++ b/tests/Feature/ActionsViewTest.php @@ -0,0 +1,52 @@ +title('Id') + ->field('id') + ->searchable() + ->sortable(), + + Column::add() + ->title('Dish') + ->field('name') + ->searchable() + ->contentClasses('bg-custom-500 text-custom-500') + ->sortable(), + + Column::action('Action'), + ]; + } + + public function actionsView($row) + { + return view('livewire-powergrid::tests.actions-view', compact('row')); + } +}; + +it('add contentClasses on dishes name column', function (string $component, object $params) { + livewire($component) + ->call($params->theme) + ->assertSeeInOrder([ + 'Dish From Actions View: 1', + 'Dish From Actions View: 2', + 'Dish From Actions View: 3', + 'Dish From Actions View: 4', + 'Dish From Actions View: 5', + 'Dish From Actions View: 6', + ]); +})->with([ + 'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'field' => 'name']], + 'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'field' => 'name']], +]);