Skip to content

Commit

Permalink
Add actionsView feature
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Jan 22, 2024
1 parent 1a45614 commit 85dca3a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
10 changes: 9 additions & 1 deletion resources/views/components/row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@
wire:key="row-{{ $column->field }}-{{ $childIndex }}"
>
<div class="pg-actions">
@if(empty(data_get($row, 'actions')) && $column->isAction)
@if (method_exists($this, 'actionsView') && $actionView = $this->actionsView($row))
<div wire:key="actions-view-{{ data_get($row, $primaryKey) }}">
{!! $actionView !!}
</div>
@endif
@endif

@if (filled(data_get($row, 'actions')) && $column->isAction)
@foreach (data_get($row, 'actions') as $key => $action)
@if(filled($action))
<div wire:key="action-{{ data_get($row, $primaryKey) }}-{{ $key }}">
<div wire:key="actions-{{ data_get($row, $primaryKey) }}-{{ $key }}">
{!! $action !!}
</div>
@endif
Expand Down
3 changes: 3 additions & 0 deletions resources/views/tests/actions-view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Dish From Actions View: {{ $row->id }}
</div>
13 changes: 13 additions & 0 deletions src/Livewire/LazyChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
52 changes: 52 additions & 0 deletions tests/Feature/ActionsViewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use PowerComponents\LivewirePowerGrid\Column;

use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire;

use PowerComponents\LivewirePowerGrid\Tests\{Concerns\Components\DishesQueryBuilderTable,
Concerns\Components\DishesTable,
Concerns\Components\DishesTableWithJoin};

$component = new class () extends DishesTable {
public function columns(): array
{
return [
Column::add()
->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']],
]);

0 comments on commit 85dca3a

Please sign in to comment.