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

Add ITreeNode.userData property. #1998

Closed
wants to merge 2 commits into from

Conversation

yaron-lavi-deel
Copy link

No description provided.

@palantirtech
Copy link
Member

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.

@adidahiya adidahiya changed the base branch from master to develop January 15, 2018 17:10
@adidahiya
Copy link
Contributor

I don't think this is necessary. See discussion in #1989

@adidahiya adidahiya closed this Jan 16, 2018
@yaron-lavi-deel
Copy link
Author

I'm sorry, but I disagree:

  • any decent tree component has the ability to attach custom data to each node, this is a necessity to every production level application.
  • I was puzzled the tree component doesn't have it. I was asked to do a PR on this, which I did and it passed all tests.
  • the change is practically harmless, but will greatly amplify the tree component capabilities.
  • I know can hold my own data objects against the data node ID, but this simply complicates a simple and common solution.

Please reconsider.

@adidahiya
Copy link
Contributor

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?

@yaron-lavi-deel
Copy link
Author

yaron-lavi-deel commented Jan 16, 2018 via email

@giladgray
Copy link
Contributor

@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 userData in the contents prop tree, which is already a massive, unwieldy data structure.

@yaron-lavi-deel
Copy link
Author

yaron-lavi-deel commented Jan 16, 2018 via email

@giladgray
Copy link
Contributor

giladgray commented Jan 16, 2018

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 any type.

@yaron-lavi-deel
Copy link
Author

yaron-lavi-deel commented Jan 17, 2018 via email

@izikorgad
Copy link
Contributor

Hi,
In my opinion, the way @yaronlavi suggested gives a whole solution within the component itself.
Of curse, this can be implemented as external lookup data structure, but it would be much more robust to have it as part of a well-defined components props.

I have prior experience with other Tree-like controls, and that was the common interface there as well.

Thanks,
Izik

@msydoron
Copy link

Reading the above, @yaronlavi suggestion seems more like it. Up-vote from me!

@jkillian
Copy link
Contributor

followup: our proposal is inherently more type-safe as it avoids declaring an any type.

I agree with @giladgray here, if we were to even consider userData, we'd need a way to make it typed. We'd have to propagate a generic type down from the Tree component.

This is clunky in React, I assume it'd have to be something like this:

public static ofType<T>() {
return Select as new () => Select<T>;
}

@adidahiya
Copy link
Contributor

Yeah I agree with @jkillian, I'd prefer to use a generic type rather than any. We could do this in a non-breaking way with generic parameter defaults in TS 2.3. Tree and TreeNode would have to use the same type constraint, so ofType<T> should return both a Tree and TreeNode component. We should return userData in Tree's various onNode* event handlers and get rid of path: number[].

Lastly, I think we should rename userData to nodeData.

Copy link
Contributor

@adidahiya adidahiya left a 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 ^

@giladgray
Copy link
Contributor

@yaronlavi status here? we're open to the overall idea and have left some comments with next steps.

@yaron-lavi-deel
Copy link
Author

yaron-lavi-deel commented Jan 30, 2018

A generic type for nodeData is welcomed, although I didn't understand how to combine ofType with my solution.

  1. Did you mean that instead of nodeData: any it'll be defined as nodeData<T>?
  2. What if a user does not want to use nodeData at all? will he be forced to pass in a type T for the tree and tree node?

@adidahiya
Copy link
Contributor

  1. yes
  2. you can set a default for the generic type parameter so that users who don't need it won't have to specify T. use nodeData: T where the interface is defined as ITreeNode<T = {}>, similar to queryList:

@giladgray
Copy link
Contributor

closing this PR as stale.

@yaronlavi you know what to do when you're ready to revisit this!

@giladgray giladgray closed this Feb 2, 2018
@izikorgad izikorgad mentioned this pull request Feb 14, 2018
3 tasks
@izikorgad
Copy link
Contributor

Hi,
I've submit PR that implements the generic nodeData concept.
Please review #2132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants