From 1065c23046eea34f7a40d03006aca8cda6b00bed Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Sun, 14 Jul 2024 18:29:51 +0300 Subject: [PATCH] fix #932 Wrong UI interaction between datatable SummaryPlugin and EmptyStatePlugin --- .../domino/ui/datatable/TableConfig.java | 9 +++++ .../plugins/summary/EmptyStatePlugin.java | 38 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java index 43a42c643..cd1753291 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java @@ -390,6 +390,15 @@ public List> getFlattenColumns() { .collect(Collectors.toList()); } + /** + * Retrieves only the leaf columns of the data table. + * + * @return A list of {@link ColumnConfig} representing all columns, flattened. + */ + public List> getLeafColumns() { + return columns.stream().flatMap(col -> col.leafColumns().stream()).collect(Collectors.toList()); + } + /** * Retrieves the columns of the DataTable as grouped. * diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/summary/EmptyStatePlugin.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/summary/EmptyStatePlugin.java index 4764fc19d..7fba6e4ad 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/summary/EmptyStatePlugin.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/summary/EmptyStatePlugin.java @@ -19,6 +19,9 @@ import org.dominokit.domino.ui.datatable.DataTable; import org.dominokit.domino.ui.datatable.events.TableDataUpdatedEvent; import org.dominokit.domino.ui.datatable.plugins.DataTablePlugin; +import org.dominokit.domino.ui.elements.TDElement; +import org.dominokit.domino.ui.elements.TFootElement; +import org.dominokit.domino.ui.elements.TableRowElement; import org.dominokit.domino.ui.icons.Icon; import org.dominokit.domino.ui.layout.EmptyState; import org.dominokit.domino.ui.utils.ChildHandler; @@ -47,6 +50,9 @@ public class EmptyStatePlugin implements DataTablePlugin { private EmptyState emptyState; + private TableRowElement rowElement = tr(); + private TDElement stateCell = td(); + private TFootElement footer; /** * Creates and returns a new instance of {@code EmptyStatePlugin} with the provided icon and @@ -72,18 +78,42 @@ public EmptyStatePlugin(Icon emptyStateIcon, String title) { } @Override - public void onAfterAddTable(DataTable dataTable) { + public void init(DataTable dataTable) { + rowElement + .addCss(dui_table_row) + .appendChild(stateCell.addCss(dui_table_cell).appendChild(emptyState)); + } + + /** + * Invoked when the footer is added to the DataTable. + * + * @param datatable The DataTable to which the footer is added. + */ + @Override + public void onFooterAdded(DataTable datatable) { + this.footer = datatable.footerElement(); + this.footer.appendChild(rowElement); + } + + @Override + public void onAfterAddTable(DataTable dataTable) { dataTable.addTableEventListener( TableDataUpdatedEvent.DATA_UPDATED, event -> { TableDataUpdatedEvent tableDataUpdatedEvent = (TableDataUpdatedEvent) event; + long columnsCount = + dataTable.getTableConfig().getLeafColumns().stream() + .filter(c -> !c.isHidden()) + .count(); + stateCell.setAttribute("colspan", columnsCount); + if (tableDataUpdatedEvent.getTotalCount() == 0) { - emptyState.show(); + rowElement.show(); } else { - emptyState.hide(); + rowElement.hide(); } }); - dataTable.element().appendChild(emptyState.element()); + this.footer.insertFirst(rowElement); } /**