Skip to content

Add withConfirmation(ValueProvider<T, String>) for per-item confirmation messages #18

Description

@javier-godoy

Feature proposal

EasyRowAction.withConfirmation(...) currently accepts static strings only:

public EasyRowAction<T> withConfirmation(String message)
public EasyRowAction<T> withConfirmation(String title, String message)

There is no way to derive the confirmation text from the row item, so the most common phrasing for a
destructive action — "Are you sure you want to delete John Smith?" — cannot be expressed. The
message has to stay generic ("Are you sure you want to delete this item?"), or the developer has to
abandon withConfirmation altogether and open a ConfirmDialog by hand inside the action handler.

Rolling your own dialog means losing what EasyRowAction already does for you:

  • the confirmPending guard that stops dialogs from stacking on rapid clicks;
  • re-checking visibleWhen / enabledWhen at confirm time, not just at click time;
  • the Vaadin 24 / 25 compatibility shim around ConfirmDialog.addOpenedChangeListener.

This is the same gap that was already closed for tooltips, which offer both a static and a
row-derived form (tooltip(String) / tooltip(ValueProvider<T, String>)).

Describe solution expectations

Add ValueProvider overloads mirroring the tooltip pair:

public EasyRowAction<T> withConfirmation(ValueProvider<T, String> messageProvider)
public EasyRowAction<T> withConfirmation(String title, ValueProvider<T, String> messageProvider)
public EasyRowAction<T> withConfirmation(ValueProvider<T, String> titleProvider,
                                         ValueProvider<T, String> messageProvider)

Usage:

grid.addRowAction("Delete", VaadinIcon.TRASH, this::delete)
    .withConfirmation("Delete person",
        person -> "Are you sure you want to delete " + person.getFullName() + "?");

The three signatures do not collide with the existing (String) / (String, String) pair, so this
is source- and binary-compatible.

Implementation looks small, because the dialog is already built lazily at click time:

  • confirmDialogSupplier (a SerializableSupplier<ConfirmDialog>, field declared at
    EasyRowAction.java:129) is only invoked from execute(T item), where the row item is already in
    scope. Changing it to a SerializableFunction<T, ConfirmDialog> and calling .apply(item) instead
    of .get() is enough to make the whole dialog item-aware.
  • The private builder at EasyRowAction.java:209 becomes provider-based, and the existing String
    overloads delegate to it through Constant.of(...) — exactly the way tooltip(String) delegates
    today.
  • null title should keep meaning "no header", as it does now via
    withConfirmation(String message)withConfirmation(null, message).
  • ValueProvider is Serializable, so this stays consistent with the add-on's serialization
    requirements.

Whether the confirm/cancel button labels should also become row-derived is probably not worth it —
they are not item-dependent in practice — but the private 4-arg builder would support it for free if
that changes.

Additional information

References in src/main/java/com/flowingcode/vaadin/addons/easygrid/actions/EasyRowAction.java
(master):

What Line
tooltip(String) — the precedent, delegates via Constant.of 170
tooltip(ValueProvider<T, String>) — the precedent 182
withConfirmation(String message) 194
withConfirmation(String title, String message) 205
private withConfirmation(title, message, confirmText, cancelText) builder 209
confirmDialogSupplier field 129
execute(T item) — where the dialog is built, item in scope 270

RowActionsDynamicDemo would be the natural place to show a per-row confirmation message alongside
the existing dynamic tooltip / visibleWhen / enabledWhen examples.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions