Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtaining currently selected item in lists is not convenient #766

Open
alexbudarov opened this issue Nov 17, 2021 · 0 comments
Open

Obtaining currently selected item in lists is not convenient #766

alexbudarov opened this issue Nov 17, 2021 · 0 comments

Comments

@alexbudarov
Copy link

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant