Skip to content

Commit

Permalink
fix: update keymapper when refreshing radio button item (#6934)
Browse files Browse the repository at this point in the history
* fix: update keymapper when refreshing radio button item

* cleanup
  • Loading branch information
sissbruecker authored Dec 13, 2024
1 parent ab5ac67 commit 975cf1e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,9 @@ public void onDiscard(DataChangeEvent<T> dataChangeEvent) {
}

private void handleDataChange(DataChangeEvent<T> dataChangeEvent) {
if (dataChangeEvent instanceof DataChangeEvent.DataRefreshEvent) {
resetRadioButton(
((DataChangeEvent.DataRefreshEvent<T>) dataChangeEvent)
.getItem());
if (dataChangeEvent instanceof DataChangeEvent.DataRefreshEvent<T> refreshEvent) {
keyMapper.refresh(refreshEvent.getItem());
resetRadioButton(refreshEvent.getItem());
} else {
keyMapper.removeAll();
selectionPreservationHandler.handleDataChange(dataChangeEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,27 @@ public void preserveAllSelectionOnDataChange_noExtraChangeEventsFired() {
Assert.assertEquals(selectedItem, group.getValue());
Assert.assertTrue(events.isEmpty());
}

@Test
public void refreshItem_selectFromClient_valueContainsUpdatedItem() {
RadioButtonGroup<CustomItem> group = new RadioButtonGroup<>();
RadioButtonGroupListDataView<CustomItem> dataView = group.setItems(
new CustomItem(1L, "foo"), new CustomItem(2L, "bar"),
new CustomItem(3L, "baz"));
dataView.setIdentifierProvider(CustomItem::getId);

CustomItem updatedItem = new CustomItem(2L, "updated");
dataView.refreshItem(updatedItem);

AtomicReference<CustomItem> selectedItem = new AtomicReference<>();
group.addValueChangeListener(e -> selectedItem.set(e.getValue()));

// Simulate selecting an item from the client side via key
String itemKey = group.getChildren().skip(1).findFirst().orElseThrow()
.getElement().getProperty("value");
group.getElement().setProperty("value", itemKey);

Assert.assertEquals("updated", selectedItem.get().getName());
Assert.assertEquals("updated", group.getValue().getName());
}
}

0 comments on commit 975cf1e

Please sign in to comment.