Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Obtaining currently selected item in lists is not convenient #766

@alexbudarov

Description

@alexbudarov

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:

  1. Too much code, e.g. when comparing to Vaadin screens (Entity entity = table.getSingleSelected())
  2. 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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions