-
Notifications
You must be signed in to change notification settings - Fork 45
feat: added onTreePopulated prop #159
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
Conversation
|
@domagojk I've looked at this and linked PR but it's a bit hard for me to understand how necessary is this change. Can you maybe elaborate a bit more what are you trying to achieve here? 🤔 It worries me, because those changes expose a lot of internals. I am sure it's warranted but maybe we can come up with a way to minimise the amount of added props. 🤷 |
|
@mpodlasin This mirrors what has been done before which is that for each tree node, we are making a node in studio where we control its state (checked and required) so it can be send to the masking api. I don't see a way of doing that without As for event handlers, I'm using it to calculate the number of nodes in a tree because there is a limit on how big the model can be in order for it to be masked. But I have nothing against in doing that internally, maybe we can return that along with |
|
@domagojk is there no way to retrieve the number of nodes from JsonSchemaTree directly? 🤔 |
|
And yes |
src/components/JsonSchemaViewer.tsx
Outdated
| return !((viewMode === 'read' && !!validations.writeOnly) || (viewMode === 'write' && !!validations.readOnly)); | ||
| }); | ||
| jsonSchemaTree.populate(); | ||
| onTreePopulated?.(jsonSchemaTree); |
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.
I know that this useMemo is quite side-effect'y already, but we really shouldn't do that.
Simple refactor would allow for that function to be called in a separate useEffect hook.
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.
Can you elaborate more on what kind of refactor you have in mind?
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.
tracking isPopulated state and then using that in useEffect?
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.
oh I guess I could just use jsonSchemaTreeRoot as dependency, I will try it out
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.
useMemo can return the whole jsonSchemaTree.
Than you just make useEffect where that callback is called with jsonSchemaTree 🤷
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.
something like:
const jsonSchemaTree = React.useMemo(...);
React.useEffect(() => {
onTreePopulated?.(jsonSchemaTree);
}, [jsonSchemaTree, onTreePopulated]);
As far as i know, there is no way of doing that anymore. |
I believe this would be much cleaner solution. But I don't want to block you. Let's make the count a part of Just for future extensibility I would do something like
Note how nodeCount is in an object - if in the future you will need something more, we can add it there. |
|
I think Thanks for the tip! 👍 I will try to minimise exposing so many things, but I just found a bug in the implementation so I will have to change this PR probably 🙄 |
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.
Yes! Looks great now! 🎉
|
🎉 This PR is included in version 4.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Needed for https://github.com/stoplightio/platform-internal/pull/7139