-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add ITreeNode.userData property. #1998
Conversation
Thanks for your interest in palantir/blueprint, @yaronlavi! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
I don't think this is necessary. See discussion in #1989 |
I'm sorry, but I disagree:
Please reconsider. |
What does the complex code look like when you have to maintain your own data structure for node-level data? How are you constructing the tree in the first place? |
That’s easy:
- each node represents a different entity in my app, so I’d be storing like a node type enumeration.
- second, some node user data will contain direct object pointers to the objects their represent, instead me holding an node-object lookup.
The tree is constructed by calling several business API, and building nodes according to the results. Each node represents a different object entity. I then hold nodes in state, including their expand/collapse state.
It’s possible of course at this stage to construct yet another node-object lookup, but holding a simple object ref per each tree node is much more elegant, efficient and straight forward.
Thanks,
Yaron
|
@yaronlavi: the proposal on #1989 to simply maintain a separate dictionary keyed by node ID seems more than sufficient for this use case. that's arguably a better approach than including |
As I wrote before to Adi:
- the ability to store user data per node is common, and critical to any component being used with production-level web apps.
- everything can be self-developed :), however we all use components to focus on the business and not on the “plumbing”. I don’t see any serious app not needing this.
- the size of contents is irrelevant here; a tree by definition is a large component and I’ve evaluated a few.
I love the tree and blueprint in general, but in order to use conveniently and elegantly this feature is really missing.
Please reconsider.
Thanks,
Yaron
|
our proposal: const userData: Record<string, IData>;
const contents: ITreeNode[];
<Tree contents={contents} onNodeClick={onClick} />
function onClick(node) {
console.log(userData[node.id]);
} your proposal: const contents: ITreeNode[];
<Tree contents={contents} onNodeClick={onClick} />
function onClick(node) {
console.log(node.userData as IData);
} the difference is negligible. i don't see how this isn't already supported trivially. followup: our proposal is inherently more type-safe as it avoids declaring an |
Not at all. One is held in the tree and is integral part. The second is glueing both artificially.
The difference is in concept and component design, not code per-se.
If this is so troubling you guys, you can start by removing pros like node.path or node.depth which are mandatory when supplying nodes for some reason but seems useless...
Thanks,
Yaron
|
Hi, I have prior experience with other Tree-like controls, and that was the common interface there as well. Thanks, |
Reading the above, @yaronlavi suggestion seems more like it. Up-vote from me! |
I agree with @giladgray here, if we were to even consider This is clunky in React, I assume it'd have to be something like this: blueprint/packages/select/src/components/select/select.tsx Lines 117 to 119 in e2d8317
|
Yeah I agree with @jkillian, I'd prefer to use a generic type rather than Lastly, I think we should rename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to this overall idea & goal, but requesting changes as noted above ^
@yaronlavi status here? we're open to the overall idea and have left some comments with next steps. |
A generic type for nodeData is welcomed, although I didn't understand how to combine ofType with my solution.
|
|
closing this PR as stale. @yaronlavi you know what to do when you're ready to revisit this! |
Hi, |
No description provided.