Skip to content

Conversation

@sissbruecker
Copy link
Contributor

Description

Allows setting an item remove handler in Dashboard, which gives manual control over item removal, for example to show a confirmation dialog.

  • Dashboard now always prevents automatic removal on the client-side and handles the removal logic on the server
  • Without a remove handler, items are automatically removed (as before)
  • With a remove handler items are not automatically removed
  • The handler receives an event that provides:
    • The item to be removed
    • Optionally, the section that the item is in
    • A method for removing the item

Example usage with a ConfirmDialog:

dashboard.setItemRemoveHandler(removeEvent -> {
    ConfirmDialog dialog = new ConfirmDialog();
    dialog.addConfirmListener(confirmEvent -> removeEvent.removeItem());
    dialog.open();
});

Part of #8257
Depends on vaadin/web-components#10623

Type of change

  • Feature

@sonarqubecloud
Copy link

* @see DashboardItemRemoveHandler
* @see DashboardItemRemoveEvent
*/
public void setItemRemoveHandler(DashboardItemRemoveHandler handler) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a similar feature in Dialog where addCloseActionListener prevents a dialog from automatically closing. However the design and implementation seem overcomplicated (allows multiple listeners, keeps track of listener count). I think just being able to set a handler and prevent the default behavior based on the presence of that handler is more straightforward.

Still providing an event to the handler seems like it could be beneficial. But we could also just pass the item to the handler, and, regardless whether it's a widget or section, removing it would just be item.removeFromParent().

handleItemRemovedClientEvent(e, idKey);
}).addEventData(idKey);
handleItemBeforeRemoveClientEvent(e, idKey, sectionKey);
}).preventDefault().addEventData(idKey).addEventData(sectionKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With preventDefault this always prevents the web component from removing the item, delegating the logic to the server.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants