To get currently selected item in browser screens (table, cards) I should write the following:
let selectedEntityId = entityListState.selectedEntityId;
const selectedEntity = items?.find(i => i.id === selectedEntityId);
Problems:
- Too much code, e.g. when comparing to Vaadin screens (
Entity entity = table.getSingleSelected())
- It's not obvious that selected entity should be taken from
items of useEntityList hook. Before found items of , I tried to use entityList and listQueryResult {data}
It would be nice to provide shorter API.
Example of usage:
function isDeactivateButtonDisabled() {
let selectedEntityId = entityListState.selectedEntityId;
const user = items?.find(i => i.id === selectedEntityId);
let currentUserName = mainStore.userName
return user == null || !user.active|| user.username === currentUserName
}
//...
<Button
htmlType="button"
style={{ margin: "0 12px 12px 0" }}
disabled={isDeactivateButtonDisabled()}
onClick={handleDeactivateBtnClick}
key="deactivate"
type="default"
>
<FormattedMessage id="users.deactivate"/>
</Button>