]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updates to TreeGrid's ensureAvailability handling. (#12374)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Fri, 20 Aug 2021 11:27:18 +0000 (14:27 +0300)
committerGitHub <noreply@github.com>
Fri, 20 Aug 2021 11:27:18 +0000 (14:27 +0300)
- Always update the availability request range when more or less data
becomes available. Otherwise e.g. programmatically expanding a TreeGrid
row can lead to discarding a lot of the new data right after receiving
it.

Fixes #12372

client/src/main/java/com/vaadin/client/ui/treegrid/TreeGridConnector.java
uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridProgrammaticExpand.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridProgrammaticExpandTest.java [new file with mode: 0644]

index 7c2475dd09daf9148775b23c23b0f3018e2e46f8..2172ee1d0f970c5ecda668d32e87d652ac119f09 100644 (file)
@@ -207,13 +207,12 @@ public class TreeGridConnector extends GridConnector {
             public void dataRemoved(int firstRowIndex, int numberOfRows) {
                 if (awaitingRowsState == AwaitingRowsState.COLLAPSE) {
                     awaitingRowsState = AwaitingRowsState.NONE;
-                    // make sure the cache stays up to date with the collapsing
-                    Range visibleRowRange = getWidget().getEscalator()
-                            .getVisibleRowRange();
-                    getDataSource().ensureAvailability(
-                            visibleRowRange.getStart(),
-                            visibleRowRange.length());
                 }
+                // make sure the cache stays up to date
+                Range visibleRowRange = getWidget().getEscalator()
+                        .getVisibleRowRange();
+                getDataSource().ensureAvailability(visibleRowRange.getStart(),
+                        visibleRowRange.length());
                 checkExpand();
             }
 
@@ -221,13 +220,12 @@ public class TreeGridConnector extends GridConnector {
             public void dataAdded(int firstRowIndex, int numberOfRows) {
                 if (awaitingRowsState == AwaitingRowsState.EXPAND) {
                     awaitingRowsState = AwaitingRowsState.NONE;
-                    // make sure the cache stays up to date with the expanding
-                    Range visibleRowRange = getWidget().getEscalator()
-                            .getVisibleRowRange();
-                    getDataSource().ensureAvailability(
-                            visibleRowRange.getStart(),
-                            visibleRowRange.length());
                 }
+                // make sure the cache stays up to date
+                Range visibleRowRange = getWidget().getEscalator()
+                        .getVisibleRowRange();
+                getDataSource().ensureAvailability(visibleRowRange.getStart(),
+                        visibleRowRange.length());
                 checkExpand();
             }
 
@@ -252,7 +250,7 @@ public class TreeGridConnector extends GridConnector {
             GridEventHandler<?> eventHandler)
     /*-{
         var browserEventHandlers = grid.@com.vaadin.client.widgets.Grid::browserEventHandlers;
-
+    
         // FocusEventHandler is initially 5th in the list of browser event handlers
         browserEventHandlers.@java.util.List::set(*)(5, eventHandler);
     }-*/;
diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridProgrammaticExpand.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridProgrammaticExpand.java
new file mode 100644 (file)
index 0000000..f6c5a6b
--- /dev/null
@@ -0,0 +1,45 @@
+package com.vaadin.tests.components.treegrid;
+
+import com.vaadin.data.TreeData;
+import com.vaadin.data.provider.TreeDataProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.TreeGrid;
+
+public class TreeGridProgrammaticExpand extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        TreeData<String> data = new TreeData<>();
+        String root = "Root";
+        data.addItem(null, root);
+        for (int i = 0; i < 15; i++) {
+            String leaf = "Leaf " + i;
+            data.addItem(root, leaf);
+        }
+
+        TreeDataProvider<String> treeDataProvider = new TreeDataProvider<>(
+                data);
+        TreeGrid<String> treeGrid = new TreeGrid<>();
+        treeGrid.setDataProvider(treeDataProvider);
+        treeGrid.addColumn(String::toString).setCaption("String")
+                .setId("string");
+        treeGrid.addColumn(i -> "--").setCaption("Nothing");
+
+        Button button = new Button("Expand", e -> treeGrid.expand(root));
+
+        addComponents(button, treeGrid);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "There should be no client-side exception when clicking Leaf 4 "
+                + "or lower before scrolling.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 12372;
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridProgrammaticExpandTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridProgrammaticExpandTest.java
new file mode 100644 (file)
index 0000000..65d8f2f
--- /dev/null
@@ -0,0 +1,22 @@
+package com.vaadin.tests.components.treegrid;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TreeGridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TreeGridProgrammaticExpandTest extends MultiBrowserTest {
+
+    @Test
+    public void expandAndClick() {
+        openTestURL("debug");
+        TreeGridElement treeGrid = $(TreeGridElement.class).first();
+        $(ButtonElement.class).first().click();
+        waitUntilLoadingIndicatorNotVisible();
+        treeGrid.getCell(5, 0).click();
+        waitUntilLoadingIndicatorNotVisible();
+        assertElementNotPresent(By.className("v-Notification-error"));
+    }
+}