-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support dashboard item remove using button (#6650)
* feat: support dashboard item remove using button * test: remove tests about visibility of edit buttons
- Loading branch information
1 parent
6ae4942
commit 4a5c1e0
Showing
9 changed files
with
134 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardItemRemovedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* This program is available under Vaadin Commercial License and Service Terms. | ||
* | ||
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} for the full | ||
* license. | ||
*/ | ||
package com.vaadin.flow.component.dashboard; | ||
|
||
import java.util.Objects; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.ComponentEvent; | ||
import com.vaadin.flow.component.ComponentEventListener; | ||
import com.vaadin.flow.component.DomEvent; | ||
import com.vaadin.flow.component.EventData; | ||
|
||
/** | ||
* Widget or section removed event of {@link Dashboard}. | ||
* | ||
* @author Vaadin Ltd. | ||
* @see Dashboard#addItemRemovedListener(ComponentEventListener) | ||
*/ | ||
@DomEvent("dashboard-item-removed") | ||
public class DashboardItemRemovedEvent extends ComponentEvent<Dashboard> { | ||
|
||
private final Component removedItem; | ||
|
||
/** | ||
* Creates a dashboard item removed event. | ||
* | ||
* @param source | ||
* Dashboard that contains the item that was removed | ||
* @param fromClient | ||
* <code>true</code> if the event originated from the client | ||
* side, <code>false</code> otherwise | ||
*/ | ||
public DashboardItemRemovedEvent(Dashboard source, boolean fromClient, | ||
@EventData("event.detail.item.nodeid") int nodeId) { | ||
super(source, fromClient); | ||
this.removedItem = getRemovedItem(source, nodeId); | ||
} | ||
|
||
/** | ||
* Returns the removed item | ||
* | ||
* @return the removed item | ||
*/ | ||
public Component getRemovedItem() { | ||
return removedItem; | ||
} | ||
|
||
private static Component getRemovedItem(Dashboard dashboard, int nodeId) { | ||
return dashboard.getChildren().map(item -> { | ||
if (nodeId == item.getElement().getNode().getId()) { | ||
return item; | ||
} | ||
if (item instanceof DashboardSection section) { | ||
return section.getWidgets().stream() | ||
.filter(sectionItem -> nodeId == sectionItem | ||
.getElement().getNode().getId()) | ||
.findAny().orElse(null); | ||
} | ||
return null; | ||
}).filter(Objects::nonNull).findAny().orElse(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters