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

JS Objects in Knobs addon #1460

Closed
wants to merge 15 commits into from
Closed

JS Objects in Knobs addon #1460

wants to merge 15 commits into from

Conversation

z4o4z
Copy link
Member

@z4o4z z4o4z commented Jul 12, 2017

Issue:
#1187 #1186

What I did

Added JS Objects support to Knobs addon
Added react-ace as code editor

How to test

npm run storybook - look at 'with object' story

@shilman
Copy link
Member

shilman commented Jul 12, 2017

@z4o4z looks cool! will check it out later today. in the meantime how big (KB) is the ace-editor/brace dependency?

@z4o4z
Copy link
Member Author

z4o4z commented Jul 13, 2017

@shilman Hi, all new libs(react-ace, brace, brace/mode/javascript, brace/theme/github) have size about 710kb (not gzip)

Copy link
Member

@danielduan danielduan left a comment

Choose a reason for hiding this comment

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

Love the ability to read a knobs object. it's been really annoying seeing [object],[object]

I'll leave it up to others whether the editor is worth adding to our codebase.

const { knob } = this.props;
const getSpaces = level => Array.from({ length: level * 2 }, () => ' ').join('');

function toString(obj, spaceLevel = 1) {
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason why were manually converting objects? seems kind of fragile.

we can probably just do json.stringify and then pass it through some js beautifier or insert spaces ourselves.

kind of an edge case, but if there's a circular dependency somewhere, this would hang too.
i.e.: const obj = { key: this }

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @danielduan . I didn't use json.stringify because I tried to add support for functions. In future we can add support for other JS features(regexp, Map, Set, and etc)

Copy link
Member

Choose a reason for hiding this comment

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

makes sense. thanks @z4o4z

@shilman
Copy link
Member

shilman commented Jul 15, 2017

@tmeasday @ndelangen any thoughts on this re: code bloat with the new editor?

@shilman
Copy link
Member

shilman commented Jul 15, 2017

@z4o4z Finally had a chance to test this out. Love ❤️ the Object support and the function support is really funky and cool.

I also think:

  1. Examples should be added to examples/cra-kitchen-sink so we can see how the different addons interact in a single spot (which we'll run automated tests against soon).
  2. We should either get rid of the addon-specific example OR add lerna-support for them somehow (cc @ndelangen)
  3. We should split the react-ace work into a separate PR and not merge it until we have a better use case for it. For example @wcastand was working on support for a full code editor addon. (I am very concerned about Storybook getting bigger and slower since 3.0, and am very sensitive to taking on big dependencies, and think we're probably overdue for a performance milestone soon.)

What do you think? I'm happy to do some of this work, or load-balance.

@shilman
Copy link
Member

shilman commented Jul 15, 2017

For @ndelangen

storybook

storybook

@z4o4z
Copy link
Member Author

z4o4z commented Jul 20, 2017

Hi @shilman, Excellent suggestions! I will add demos to examples/cra-kitchen-sink.
And can you help me with it?

split the react-ace work into a separate PR

@ndelangen
Copy link
Member

minor linting error:

/tmp/storybook/addons/knobs/src/components/types/Object.js
  56:14  error    Arrow function should not return assignment               no-return-assign

@ndelangen
Copy link
Member

@z4o4z Can you take another look at this? I think the snapshots are outdated!

@z4o4z
Copy link
Member Author

z4o4z commented Aug 3, 2017

@ndelangen yep

@stale
Copy link

stale bot commented Oct 31, 2017

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks!

@stale stale bot added the inactive label Oct 31, 2017
}),
onChange: PropTypes.func,
};

ObjectType.serialize = object => JSON.stringify(object);
ObjectType.deserialize = value => (value ? JSON.parse(value) : {});
ObjectType.deserialize = value => eval(`(${value})`); // eslint-disable-line no-eval
Copy link
Member

Choose a reason for hiding this comment

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

We need some XSS protection here

Copy link
Member

Choose a reason for hiding this comment

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

Are we afraid of users scripting themselves or a knob url link with something potentially malicious inside it?

I think we can get around this by not allowing the javascript to be serialized into the URL if it's a real concern.

Copy link
Member

@Hypnosphi Hypnosphi Nov 14, 2017

Choose a reason for hiding this comment

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

Yeah, mostly the latter. Storybooks are often hosted at some path of the main website, so you can make cookies leak this way

Copy link
Member

Choose a reason for hiding this comment

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

🎖 for you @Hypnosphi

Copy link
Member

@Hypnosphi Hypnosphi Nov 15, 2017

Choose a reason for hiding this comment

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

Actually it shouldn't be deserialized from URL, either. And it would be a regression comparing to what we have now

Maybe we should try to do plain JSON.parse first, and just give up if it fails AND the value comes from URL

@stale stale bot removed the inactive label Oct 31, 2017
@storybookjs storybookjs deleted a comment from storybookbot Nov 14, 2017
@storybookjs storybookjs deleted a comment from codecov bot Nov 14, 2017
@danielduan
Copy link
Member

@z4o4z do you think you can remove the js object serialization so we can move this PR forward?

Copy link
Member

@Hypnosphi Hypnosphi left a comment

Choose a reason for hiding this comment

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

@stale
Copy link

stale bot commented Dec 31, 2017

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Dec 31, 2017
@stale
Copy link

stale bot commented Jan 15, 2018

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this Jan 15, 2018
@Hypnosphi Hypnosphi deleted the knobs-code-mirror branch February 17, 2018 13:43
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.

5 participants