]> source.dussan.org Git - vaadin-framework.git/commitdiff
Refresh DataProvider only once when reordering the grid using GridRowDragger (#11981)
authorMartín López <mlopez@flowingcode.com>
Mon, 11 May 2020 07:00:35 +0000 (04:00 -0300)
committerGitHub <noreply@github.com>
Mon, 11 May 2020 07:00:35 +0000 (10:00 +0300)
Fixes #10844

server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java
server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java

index 56ebe406cae855661031214ceeeaee039a09e1c1..6b21981f245d850798d7724a13365bb3fd876872 100644 (file)
@@ -381,7 +381,11 @@ public class GridRowDragger<T> implements Serializable {
         }
 
         sourceItems.removeAll(droppedItems);
-        listDataProvider.refreshAll();
+
+        // if reordering the same grid, DataProvider's refresh will be done later
+        if (getGridDragSource().getGrid() != getGridDropTarget().getGrid()) {
+            listDataProvider.refreshAll();
+        }
     }
 
     private void handleTargetGridDrop(GridDropEvent<T> event, final int index,
index 08b647cdde93b2816659715b411b748d6a5ff39b..6c522abcf93e397731c2367b345d3c2101a50fdc 100644 (file)
@@ -127,6 +127,26 @@ public class GridRowDraggerOneGridTest {
         verifyDataProvider("1", "2", "0");
     }
 
+    @Test
+    public void listDataProvider_calledOnlyOnce() {
+
+        final int[] times = new int[1];
+
+        source.setItems("0", "1", "2");
+
+        source.getDataProvider().addDataProviderListener(ev -> times[0]++);
+
+        dragger.setDropIndexCalculator(event -> {
+            return Integer.MAX_VALUE;
+        });
+
+        drop("1", DropLocation.ABOVE, "0");
+
+        verifyDataProvider("1", "2", "0");
+
+        Assert.assertArrayEquals("DataProvider should be invoked only once", new int[] { 1 }, times);
+    }
+
     @Test
     public void noopSourceUpdater() {
         source.setItems("0", "1", "2");