Skip to content

Commit

Permalink
fix: allow replacing items with refreshItem (#6714) (#6718)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Ißbrücker <[email protected]>
  • Loading branch information
vaadin-bot and sissbruecker authored Oct 11, 2024
1 parent 89ba5fb commit 5b05385
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,10 @@ private void onDataChange(DataChangeEvent<T> event) {
getItems()
.filter(vaadinItem -> updatedItemId.equals(
identifierProvider.apply(vaadinItem.getItem())))
.findAny().ifPresent(this::updateItem);
.findAny().ifPresent(item -> {
item.setItem(updatedItem);
updateItem(item);
});
} else {
reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public T getItem() {
return item;
}

void setItem(T item) {
this.item = item;
}

@Override
public void onEnabledStateChanged(boolean enabled) {
// Not setting the disabled attribute because vaadin-item's that are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ public void setIdentifierProvider_customIdentity_itemRefreshed() {

dataView.setIdentifierProvider(Item::getId);

first.setValue("changed-1");
second.setValue("changed-2");

dataProvider.refreshItem(new Item(1L));
dataProvider.refreshItem(new Item(1L, "changed-1"));

Assert.assertTrue(containsItem(component, "changed-1"));
Assert.assertFalse(containsItem(component, "changed-2"));
Expand All @@ -85,10 +84,9 @@ public void setIdentifierProvider_customDataProviderIdentity_itemRefreshed() {
Select<Item> component = new Select<>();
component.setItems(dataProvider);

first.setValue("changed-1");
second.setValue("changed-2");

dataProvider.refreshItem(new Item(1L));
dataProvider.refreshItem(new Item(1L, "changed-1"));

Assert.assertTrue(containsItem(component, "changed-1"));
Assert.assertFalse(containsItem(component, "changed-2"));
Expand Down

0 comments on commit 5b05385

Please sign in to comment.