-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Addon-controls: Add JSON tree editor for Object args #12685
Addon-controls: Add JSON tree editor for Object args #12685
Conversation
17bbf30
to
4825594
Compare
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.
Looking awesome @hydrosquall!! ❤️
Can we remove most or all of the options? That's just more stuff to maintain and we should have good defaults for users out of the box. Of the existing options, I think the "sort" and "collapsed" options are things that we might want to allow configuration for, and the rest we should just provide good defaults. WDYT?
@domyen can you take a quick look at the design?
Nice work @hydrosquall! Requests:
Re:options
|
Awesome stuff @hydrosquall ! @domyen you can check this live demo to see what's available in the plugin. I don't think double click to edit is possible, but there's a shortcut stated in the demo:
I think that won't work on mac though, because ctrl + click is equivalent to right click |
@yannbf Thanks, I was referencing the demo for my earlier comments. The goal of Controls is to make it easy to edit any component prop. The current edit interaction results in a lot of extra clicking (at least 2 extra clicks for each field you want to edit). That's pretty unwieldy. I wonder if a simpler text editor interface makes editing json faster/easier. For example, this plugin (with fewer features) renders an editable json and validates. That way folks can paste or write the format they want. wdyt? |
Hmm that's pretty nice @domyen 🤔 |
Completely agree and we should try to make the editing experience easier, so maybe we can make a contribution to react-json-view to add the functionality we want. The dev is not actively doing new features in the repo but he said he is willing to review and accept contributions. A simpler lib like the one you mentioned is nice, but it's pretty dev-centered (stakeholders could not understand how to tweak with these values) and it also starts to get quite messy once the object is pretty large and contains arrays etc. The nice thing about the react-json-view is that it takes complex objects and makes them simple to visualize, expan, and collapse, rather than displaying long texts like you'd get in a text editor. Controls is in a panel that is usually pretty short in height, and being able to collapse properties is a big plus. You do mention an interesting point, though. What if the user wants to get a json and paste it directly to controls? With react-json-view that's not possible. In a way it's a good thing, because the lib enforces users to keep with the object structure coming from args and not simply be able to paste any random data. If the (niche) users want to paste a json, they could do so in the |
I guess there are two options here: A. Make PRs into react-json-view to make editing easier B. makes sense to me after more consideration. It's lower scope and satisfies what users have asked for (better object formatting). 🤦♀️ Ha! I already went through and customized RJV, but now I don't think it's what we need. A. has a lot of uncertainty about whether we can achieve the user experience we want. It's also greater maintenance surface area. Another option: Do what Cosmos does and have a tree + editable text fields. This seems like a lot more work for Other stakeholders |
Hi @domyen, thanks for taking a close look. I have some additional thoughts about using a nested object tree vs a text editor.
I think a collapsible tree view is preferable to a text editor (even with nicer formatting) for the components that I'm looking to use storybook with, and would like to see a
What do you think about If so, would you still be interested in the |
@yannbf I just had an idea for this - if this "import from a clipboard" is a necessary future feature request, we could have a button to read from clipboard, a popup dialog, or some open-able text field. If it passes JSON validation, then this data could be rendered and subsequently further edited in |
@shilman sure thing! I'll do this if we decide to move forward with |
One alternative to waiting for |
The target UX of Controls (and Storybook essential addons at large) is to instantly render changes when a control's value changes. That makes it faster/easier to see the results of prop changes. My UX goals for
For
jsoneditor seems promising (but heavy 226kb gzipped). It has a tree and editor view. In a nutshell, I'm trying to figure out how to satisfy the UX goals with low maintenance overhead. I suggested an "editor" because it's an evolutionary next step from what we have now. It's better than an unformatted text field (what we have now) and is straightforward to integrate in our UX. |
@domyen WDYT about styling There are actually three types of props that we care about:
We already handle 1 well. Ideally we handle 2 directly as rows in the ArgsTable, like Cosmos, but that's a bigger project and out of scope. I think for 3 we should handle that in a tree view like @hydrosquall proposes. Editing this stuff is unwieldy, even in the editor you recommended. Structuring it trumps instant keystroke-by-keystroke updates IMO. @hydrosquall we could potentially include both object UIs as an option. Another idea would be to implement #11486 and then you could override the object control outside of Storybook. I don't have a timeline for that though. |
It is highly customizable ( many namespaced CSS class names to hook into), but I don't think it satisfies the constraint of instant updates. If that is the most important factor, then I haven't come across any custom components that do instant updates aside from the As a point of feedback about instant updates, when typing a string name in a nested tree, there are a number of intermediary "bad" states that I don't actually want to lead to re-rendering, such as when I have a list of graph nodes and graph edges and am typing out nodes whose names have multiple characters). In these scenarios, requiring an extra click to "commit" the change is OK because I'm not distracted by viewing renders of data that technically parses correctly but isn't what I want to happen.
I very much like the idea of being able to bring in my own UI controls for when they fall out of the mainline Storybook design case, so whenever that's done, I'll be happy to test it out. Next steps
If lack of non-instant updates on the default object viewer is the main issue, then I'd like to propose shifting this PR from replacing the existing Object editor (which would remain the default so users continue to get the instant experience as a default, and someone else can start the process of making a fancier JSON text editor) to adding a new I think this solution would avoid breaking existing workflows. My question is whether the same set of design concerns (click name to edit instead of the edit button, instant updates) all apply if this tree is no longer the default. If we're able to release both of these constraints, I can make the edits to react-json-view with the original set of visual design feedback on this PR. If we instead want to try |
Clicking on the field you want to directly edit is a hard constraint for me because it gets us close to direct manipulation of the inputs. I don't think react-json-view is the user experience we want because it requires precise manipulation of small click targets. Not to mention the styling constraints. You and @shilman make good points about the tradeoffs between evolving the experience we have now and instant editing (an out-of-the-box solution doesn't seem to exist yet). It makes sense to release that constraint 👍. Thanks for getting us there!
This proposal SGTM. To confirm, the target user experience is:
And it should follow our styling conventions (within reason). |
If we could do:
and lazy load these components, that would be ideal. |
Understood! I am all for the value of direct manipulation a la Bret Victor and giving users fast feedback 👍 .
If the library had an active maintainer I would consider opening a PR there to add "click property instead of edit button", but since that isn't the case, I agree that it'll make sense for us to switch libraries.
From testing the demo here (https://oxyno-zeta.github.io/react-editable-json-tree/), I think all of these UX goals will be achieved. Note that unlike in react-json-viewer, this means it is harder to have prop strings that contain newlines if we're listening on the enter key (but I think this is probably a reasonable trade) |
Issue: #12599
What I did
react-json-view
lib (public demo here: https://mac-s-g.github.io/react-json-view/demo/dist/ )ObjectConfig
so that the user can customize the behavior of this control using all non-function props of theReactJSON
componentofficial-storybook
story about using add-controlsThanks to @yannbf for providing a guide to getting started and showing an example with using
knobs
here.How to test
It's possible, but I'm not sure that it's necessary.
We could, but I think updating the main storybook story may be sufficient, as this change should benefit most users without needing them to customize anything.
We could document the
ObjectConfig
options onthis page.On the other hand, we could also keep this as an undocumented feature if we're not sure whether we want users to be customizing their controls to this level. Not documenting these properties officially gives us the flexibility to switch to other JSON tree components in the future, without fear that the new library may not support all of these options.
FAQ
Why not some other JSON tree viewer library XYZ?
react-json
was picked for its balance between features and bundle weight. See the options that were evaluated here: Addon-controls: JSON Editor/Treeview for Object Properties #12599 (comment) . Very open to trying other suggestions if you have recommendations.What terminal commands did you use that you might use again next time?
1 change in
examples/official-storybook/main.ts
to speed up build time: