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

Tree widget: Add selectionPredicate to models tree building blocks #1124

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

grigasp
Copy link
Member

@grigasp grigasp commented Dec 17, 2024

Closes #1099.

The predicate receives a node and its type to help consumers decide whether selection should be allowed or not. Example:

function MyModelsTree(props) {
  return (
    <ModelsTreeComponent
      {...props}
      selectionPredicate={myNodesSelectionPredicate}
    />
  )
}

const myNodesSelectionPredicate: ComponentProps<typeof ModelsTreeComponent>["selectionPredicate"] = ({ node, type }) => {
  if (type === "element") {
    return true;
  }
  return node.label.includes("whatever");
};

@grigasp grigasp requested review from a team as code owners December 17, 2024 15:25
@grigasp grigasp enabled auto-merge (squash) December 17, 2024 15:26
Copy link
Contributor

@MartynasStrazdas MartynasStrazdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could visually show which nodes are not selectable?

@grigasp
Copy link
Member Author

grigasp commented Dec 18, 2024

Perhaps we could visually show which nodes are not selectable?

I guess that would be nice for users to know that before clicking on the node, but I think the visual should be very subtle to avoid extra noise. Got anything in mind?

Note: the primary use case for this feature is to allow consumers temporarily disable selection of specific nodes (e.g. subjects, models, categories) until other components are able to handle that stuff being selected. As such, I don't think we should invest much time into improving UX for it - the change should be simple to implement.

@grigasp grigasp merged commit db4ec4a into master Dec 18, 2024
14 checks passed
@grigasp grigasp deleted the tree-widget/node-selection-predicate branch December 18, 2024 08:48
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

Successfully merging this pull request may close these issues.

[Tree Widget] model / category selection inconsistencies with selection based tools
2 participants