Skip to content

Commit

Permalink
[Feature] Actions view (#1343)
Browse files Browse the repository at this point in the history
* Fix LazyChild data issue

* Add actionsView feature

* Add actionsView feature

* fix test

* Run pint
  • Loading branch information
luanfreitasdev authored Jan 22, 2024
1 parent 5fed9be commit 5d3f2c1
Show file tree
Hide file tree
Showing 40 changed files with 195 additions and 120 deletions.
8 changes: 8 additions & 0 deletions resources/views/components/row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
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))
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>
12 changes: 12 additions & 0 deletions src/Livewire/LazyChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ 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
12 changes: 6 additions & 6 deletions tests/Feature/ActionRules/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function actionRules($row): array
};

dataset('actionRules:simple', [
'tailwind' => [$simple::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind' => [$simple::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind join' => [$simple::class, (object) ['theme' => 'tailwind', 'join' => true]],
]);

Expand Down Expand Up @@ -57,7 +57,7 @@ public function actionRules($row): array
);
})->with(
[
'tailwind' => [$simple::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind' => [$simple::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind join' => [$simple::class, (object) ['theme' => 'tailwind', 'join' => true]],
]
)->group('actionRules');
Expand All @@ -76,7 +76,7 @@ public function actionRules($row): array
);
})->with(
[
'bootstrap' => [$simple::class, (object) ['theme' => 'bootstrap', 'join' => false, 'dishId' => 1]],
'bootstrap' => [$simple::class, (object) ['theme' => 'bootstrap', 'join' => false, 'dishId' => 1]],
'bootstrap join' => [$simple::class, (object) ['theme' => 'bootstrap', 'join' => true, 'dishId' => 1]],
]
)->group('actionRules');
Expand Down Expand Up @@ -142,8 +142,8 @@ public function actionRules($row): array
]
);
})->with([
'tailwind' => [$customAttributes::class, (object) ['theme' => 'tailwind', 'join' => false, 'dishId' => 2]],
'bootstrap' => [$customAttributes::class, (object) ['theme' => 'bootstrap', 'join' => false, 'dishId' => 2]],
'tailwind join' => [$customAttributes::class, (object) ['theme' => 'tailwind', 'join' => true, 'dishId' => 2]],
'tailwind' => [$customAttributes::class, (object) ['theme' => 'tailwind', 'join' => false, 'dishId' => 2]],
'bootstrap' => [$customAttributes::class, (object) ['theme' => 'bootstrap', 'join' => false, 'dishId' => 2]],
'tailwind join' => [$customAttributes::class, (object) ['theme' => 'tailwind', 'join' => true, 'dishId' => 2]],
'bootstrap join' => [$customAttributes::class, (object) ['theme' => 'bootstrap', 'join' => true, 'dishId' => 2]],
])->group('actionRules');
6 changes: 3 additions & 3 deletions tests/Feature/ActionRules/BladeComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class="w-5 h-5" dish-id="id"
})
->with(
[
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]
)->group('actionRules');
2 changes: 1 addition & 1 deletion tests/Feature/ActionRules/DetailRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ public function actionRules(): array
->group('actionRules');

dataset('detail_row_tailwind_join', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
]);
6 changes: 3 additions & 3 deletions tests/Feature/ActionRules/DisableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function actionRules($row): array
};

dataset('action:disabled', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/ActionRules/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function actionRules($row): array
->set('search', 'Francesinha vegana')
->assertSeeHtml("\$dispatch(&#039;toggleEvent&#039;, JSON.parse(&#039;{\\u0022dishId\\u0022:5}&#039;))");
})->with([
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
])->group('actionRules');
6 changes: 3 additions & 3 deletions tests/Feature/ActionRules/DispatchToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function actionRules($row): array
})->with('emit_to_themes_with_join')->group('actionRules');

dataset('emit_to_themes_with_join', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);
12 changes: 6 additions & 6 deletions tests/Feature/ActionRules/HideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function actionRules($row): array
->assertDontSeeHtml("\$dispatch(&#039;executeDispatch&#039;, JSON.parse(&#039;{\u0022id\u0022:3}&#039;");
})
->with([
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
])
->group('action');
Expand All @@ -97,9 +97,9 @@ public function actionRules($row): array
->assertSeeHtml("action-3-render-action.0.edit");
})
->with([
'tailwind' => [$hidePreventShowHtml::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$hidePreventShowHtml::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$hidePreventShowHtml::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$hidePreventShowHtml::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$hidePreventShowHtml::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$hidePreventShowHtml::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$hidePreventShowHtml::class, (object) ['theme' => 'bootstrap', 'join' => true]],
])
->group('action');
2 changes: 1 addition & 1 deletion tests/Feature/ActionRules/LoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function actionRules($row): array
};

dataset('actionRules:loop', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/ActionRules/RedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function actionRules($row): array
->group('actionRules');

dataset('redirect', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);
6 changes: 3 additions & 3 deletions tests/Feature/ActionRules/SlotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function actionRules($row): array
})->with('caption_themes_with_join')->group('actionRules');

dataset('caption_themes_with_join', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);
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('can render actionsView property', 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']],
]);
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/BladeComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function actions($row): array
};

dataset('bladeComponent', [
'tailwind' => [$bladeComponent::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$bladeComponent::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$bladeComponent::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$bladeComponent::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$bladeComponent::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$bladeComponent::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$bladeComponent::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/CallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function actions($row): array
};

dataset('action:call', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/CanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function actions($row): array
};

dataset('action:can', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public function actions($row): array
};

dataset('action:dispatch', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/DispatchToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public function actions($row): array
};

dataset('action:dispatchTo', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/IdAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function actions($row): array
};

dataset('id', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/MethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function actions($row): array
};

dataset('action:routeMethod', [
'tailwind' => [$route::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$route::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$route::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$route::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$route::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$route::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$route::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/ParentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public function actions($row): array
};

dataset('action:parent', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Buttons/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function actions($row): array
};

dataset('action:closure', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);

Expand Down
Loading

0 comments on commit 5d3f2c1

Please sign in to comment.