-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature : Add new types of Action #88
Comments
Hey @alexandre-castelain, thanks for the suggestion! Let me add some comments from my perspective:
TLDR: your suggestions are great, but personally, I'm up for the dropdown action type alone - this one seems really helpful, and I think it would fit in the core bundle nicely. Cheers. |
I have a naive implementation of DropdownActionType in my current project : class DropdownActionType extends AbstractActionType
{
public function buildView(ActionView $view, ActionInterface $action, array $options): void
{
$view->vars['dropdown'] = true;
}
public function getParent(): ?string
{
return LinkActionType::class;
}
public function configureOptions(OptionsResolver $resolver): void
{
// @todo : use group options to handle multiple dropdown
$resolver->setDefault('group', null);
}
} And the template : {% block actions %}
{% set dropdown_actions = actions | filter(a => a.vars.dropdown|default) %}
<div class="d-flex align-items-center gap-2">
{% for action in actions | filter(a => a not in dropdown_actions) %}
{{ data_table_action(action) }}
{% endfor %}
{% if dropdown_actions|length %}
<div class="dropdown">
<twig:Button type="button" size="sm" ghost data-bs-toggle="dropdown"
data-bs-popper-config="{{ { strategy: "fixed" }|json_encode|escape }}">
<twig:Icon icon="dots" class="m-0" />
</twig:Button>
<div class=" dropdown-menu">
{% for action in dropdown_actions %}
{% set class = ('dropdown-item ' ~ action.vars.attr.class|default('')) | trim %}
{% set attr = action.vars.attr|default([])|merge({ class }) %}
{{ data_table_action(action, { attr }) }}
{% endfor %}
</div>
</div>
{% endif %}
</div>
{% endblock %}
|
This is exactly the kind of thing I have in mind. We could add options:
I don't have any implementation with this bundle yet. |
I think the point is to define actions like we can define them currently, but optionally grouping them using the Thanks for suggestion @bdecarne! |
Oh, sorry @alexandre-castelain, I think I misunderstood what you meant at first - setting a label/icon/attributes for the dropdown itself? In that case I am not sure how we should handle following scenario: $builder
->addAction('red', DropdownActionType::class, [
'group' => 'colors',
'group_label' => 'Foo',
])
->addAction('blue', DropdownActionType::class, [
'group' => 'colors',
'group_label' => 'Bar',
])
; Single group, but two different labels (or icon, or attributes...) 😞 Maybe something like this: $builder
->addAction('colors', DropdownActionType::class, [
'actions' => [
$builder->createAction('red', LinkActionType::class),
$builder->createAction('blue', LinkActionType::class),
],
])
; Then, I'm not sure which action types would be allowed in the dropdown to be able to render them properly. |
Hi @Kreyu , Indeed, the second option was what I had in mind. We currently have this kind of action in our data-table implementation, and it is very convenient to use. Note, I'm not suggesting to adopt this functionality as it is, but rather to give you an idea. ->addColumn('action', ActionColumn::class, [
'label' => 'list.columns.actions.label',
'field' => 'id',
'actions' => function (int $idOfMyEntity, MyEntityDisplayed $myEntity) {
$actions = [
(new DropDownMenuAction())
->setLabel('list.columns.actions.menu.label')
->setActions([
(new DropDownItemAction('my_route'))
->setLabel('list.columns.actions.menu.customers_map.label')
->setActionType(AbstractAction::ACTION_TYPE_ROUTE)
->setActionParams(['id' => $idOfMyEntity])
->setDisplayRights([
//Add a way to pass some ROLES that must be matched to display this specific action.
]),
]),
(new ButtonAction('another_route'))
->setActionType(AbstractAction::ACTION_TYPE_ROUTE)
->setActionParams(['id' => $idOfMyEntity])
->setPictogram((new Icon())->setCssClass('fa-solid fa-eye')) //We could use Twig:Icon on the frontend side
];
if ('KO' === $myEntity->getStatus()) {
$actions[] = (new ButtonAction($this->router->generate('another_another_route')))
->setActionType(AbstractAction::ACTION_TYPE_AJAX_CALL) //This is usefull, you can make an ajax call and then refresh the data-table
->setActionParams(['id' => $idOfMyEntity])
->setDisplayRights([
['right' => MY_ENTITY::ROLE 'subject' => $myEntity], // This is the way we check the right in our lib.
])
->setPictogram((new Icon())->setCssClass('fa-solid fa-trash-arrow-up'))
->setCssClass('button-secondary');
}
return $actions;
},
]); I know there is a lot of information in this code snippet. I will try to review the elements that seem important to me.
I think I have covered the interesting options in this code snippet. We have implemented other things as well, but if we can add this to the bundle, it would already be very good! Again, I don't want to add this as it is; I think there is room for improvement. What do you think? |
Hello,
Currently, the following action types can be added directly to a data table:
It would benefit the bundle to have additional action types such as:
DropDownActionType
An action displayed as a select/option, containing a set of other actions. This allows for managing a large number of actions on a row without taking up too much space.
FrontActionType
An action that triggers a JavaScript event. This event should be handled by the developer's code to perform specific tasks.
CallbackActionType
An action that manages the callback directly within the data table, enabling the developer to handle a click as desired.
SwitchActionType
An extension of CallbackActionType that allows for a "Yes/No" action directly in the data table. If the action is set on a row, it modifies the current row. If set on the header, it can, for example, modify the SQL query.
ChoiceActionType
An extension of CallbackActionType that allows the user to select from a predefined set of values. Similar to SwitchActionType in terms of utility.
Have a great day,
Alexandre
The text was updated successfully, but these errors were encountered: