-
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.
fix: Use incremental numeric id as a key for Tree Grid items (#3046)
* fix: Use incremental numeric id as a key for Tree Grid items Using Object::toString as an item's key for server-client communication makes item's data visible on the client side, so generated numeric id is used instead. * Use serializable map * Use index and depth as an item ID * fix data provider getId implementation * use custom unique key provider in tests Co-authored-by: Soroosh Taefi <taefi.soroosh@gmail.com> Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com> (cherry picked from commit 8fe0861)
- Loading branch information
1 parent
498d3a4
commit 8830955
Showing
2 changed files
with
71 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
...ow-parent/vaadin-grid-flow/src/test/java/com/vaadin/flow/component/grid/TreeGridTest.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,62 @@ | ||
/* | ||
* Copyright 2000-2022 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.component.grid; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.component.treegrid.TreeGrid; | ||
import com.vaadin.flow.function.ValueProvider; | ||
|
||
public class TreeGridTest { | ||
|
||
@Test | ||
public void defaultUniqueKeyProvider_usesIncrementalLongId() { | ||
Item item1 = new Item("sensitive data 1"); | ||
Item item2 = new Item("sensitive data 2"); | ||
|
||
UniqueKeyTreeGrid grid = new UniqueKeyTreeGrid(); | ||
String key1 = grid.getUniqueKeyProvider().apply(item1); | ||
Assert.assertEquals("0", key1); | ||
|
||
String key2 = grid.getUniqueKeyProvider().apply(item2); | ||
Assert.assertEquals("1", key2); | ||
|
||
key1 = grid.getUniqueKeyProvider().apply(item1); | ||
Assert.assertEquals("0", key1); | ||
} | ||
|
||
private static class UniqueKeyTreeGrid extends TreeGrid<Item> { | ||
@Override | ||
public ValueProvider<Item, String> getUniqueKeyProvider() { | ||
return super.getUniqueKeyProvider(); | ||
} | ||
} | ||
|
||
private static class Item { | ||
private final String sensitiveData; | ||
|
||
public Item(String sensitiveData) { | ||
this.sensitiveData = sensitiveData; | ||
} | ||
|
||
public String getSensitiveData() { | ||
return sensitiveData; | ||
} | ||
} | ||
|
||
} |