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

Story Parameters for Official Addons #3625

Closed
6 tasks done
shilman opened this issue May 22, 2018 · 31 comments
Closed
6 tasks done

Story Parameters for Official Addons #3625

shilman opened this issue May 22, 2018 · 31 comments

Comments

@shilman
Copy link
Member

shilman commented May 22, 2018

Story parameters has been implemented for the notes addon in #3373

We should also implement it for other official addons as part of the 4.0 release:

@mshaaban088
Copy link
Contributor

viewport is implemented in #3610

@Hypnosphi Hypnosphi added the todo label May 22, 2018
@Hypnosphi Hypnosphi added this to the v4.0.0 milestone May 22, 2018
@tmeasday
Copy link
Member

Wow, that was fast, thanks @mshaaban088!

@tmeasday
Copy link
Member

Oh. Heh, I see it was done a few days ago. Still great!

@tmeasday tmeasday self-assigned this May 23, 2018
@tmeasday
Copy link
Member

I'll have a go at the jest addon

@tmeasday
Copy link
Member

tmeasday commented May 24, 2018

@renaudtertrais I am looking at the jest addon and there doesn't seem like much to change. I wondered though if we could make the DX a bit easier using parameters. My suggestion would be that rather than advising people to make a withTests.js file to avoid re-importing the test file, we could instead advise the following:

// In `.storybook/config.js`
import { addDecorator } from '@storybook/react';
import { withTests } from '@storybook/addon-jest';
import results from '../.jest-test-results.json';

addDecorator(withTests({ results }));

// In a story file
storiesOf('MyComponent', module)
  .addParameters({ jest: ['MyComponent', 'MyOtherComponent'] })
  .add('This story shows test results from MyComponent.test.js and MyOtherComponent.test.js', () => (
    <div>Jest results in storybook</div>
  ));

That way we solve the problem of not wanting to import jest-test-results.json in more than one place without needing to add a new file to the project.

Let me know what you think. I am happy to implement the changes to make this work, or work with you to make it happen (we'll of course continue to support the previous API).

@Keraito
Copy link
Contributor

Keraito commented May 25, 2018

I can work on info if nobody is already

@tmeasday
Copy link
Member

Sounds great @Keraito

@Hypnosphi
Copy link
Member

How about backgrounds?

@tmeasday
Copy link
Member

Seems reasonable. Any reason you left it off the list @shilman?

@tmeasday
Copy link
Member

How's info going @Keraito?

@Keraito
Copy link
Contributor

Keraito commented May 29, 2018

Sorry @tmeasday, thought I had a little bit more time on my hands. I will try to get a PR rolling by the end of this week at latest.

@tmeasday
Copy link
Member

No worries @Keraito. Just ping me if you do start it, otherwise I might do it soon to wrap this issue up.

@Keraito
Copy link
Contributor

Keraito commented May 29, 2018

Aight, will do!

@Keraito
Copy link
Contributor

Keraito commented May 30, 2018

@tmeasday so I started working on this, implemented the new parameter based pattern with the decorator, and am now writing some additional examples in the examples/official-storybook.

Currently, I have something like this (basically copied the first 2 stories that were already there):

storiesOf('Addons|Info.Options.parameters', module)
  .addDecorator(withInfo)
  .addParameters({
    info: {
      text: 'Component should be inlined between description and PropType table',
      inline: true, // Displays info inline vs click button to view
    }
  })
  .add(
    'Inlines component inside story', () => <BaseButton label="Button" />
  )
  .add(
    'Excludes propTypes that are in the excludedPropTypes array', 
    () => <BaseButton label="Button" />, 
    { 
      info: {
        text: 'Label propType should be excluded',
        excludedPropTypes: ['label'],
      }
    }
  );

Everything works fine, and the first story is inlined with the corresponding text. The second story however, throws away all the parameters I set in the addParameters and overrides it with the only
{ text: 'Label propType should be excluded', excludedPropTypes: ['label'] }. Is this intended? So imo it would be better if it would be merged together, particularly that the parameter per story would override any existing values set in the addParameters, and adding any non-existing entries.
Or at least put that functionality into the check between options and parameters.

@tmeasday
Copy link
Member

tmeasday commented May 31, 2018

@Keraito I think you are right. Perhaps you can make the change on this line:

https://github.com/storybooks/storybook/blob/fb6fb1d326acafc0411f5e1b725d98a5c0d23374/lib/core/src/client/preview/client_api.js#L110-L112

I'm not sure if we should use lodash merge to merge parameters all the way down, or just per-key? Probably just per key (so e.g. allParams.info = { ...this._globalParameters.info, ...localParameters.info, ...parameters.info })

@Hypnosphi
Copy link
Member

Per key sounds enough

@Keraito
Copy link
Contributor

Keraito commented May 31, 2018

@tmeasday so should I do this only for the info addon, or for all addons/keys in the 3 param objects?

@tmeasday
Copy link
Member

tmeasday commented Jun 1, 2018

@Keraito -- all keys, sorry if that was confusing ;)

@webholics
Copy link

webholics commented Jun 8, 2018

I would like to hide the addon panel of certain pages (pages which basically just render some Markdown documentation). The way how the options plugin currently works makes this quite difficult to implement because you not only have to set showAddonPanel to false on those pages but you also have to set it back to true on all the other stories.

It would be really nice to support the options here too, like:
.addParameters({ options: { showAddonPanel: false }})

@Hypnosphi
Copy link
Member

Yeah, addon-options is an obvious missing candidate here

@tmeasday
Copy link
Member

tmeasday commented Jun 8, 2018

Yes! Let's deprecate the setOptions(options) API and do addDecorator(withOptions(options)) instead!

(Slightly more convoluted but so much more consistent!)

@webholics
Copy link

@tmeasday what is important though is that if you do not add the withOptions decorator that some previously defined default options are picked up. Otherwise you would be forced to use the decorator in all stories. So we definitely still need the setOptions, but maybe more for setting those defaults.

@tmeasday
Copy link
Member

tmeasday commented Jun 9, 2018

Otherwise you would be forced to use the decorator in all stories.

Is this a problem? Can we not just make addDecorator(withOptions(...)) essentially identical to setOptions(...)?

You need the decorator on all stories otherwise the options story param will be ignored. Unless you have to add the decorator wherever you add the param, which would be counterproductive IMO.

At first it seems weird that a story decorator could not change the story but simply effect the UI of the manager, but if you think about it, this is what quite a few decorators do in fact (e.g. jest, notes). Perhaps its confusing, but I think a user probably isn't really thinking too hard that it's not a decorator but instead something else triggered by the story.

If I was designing it from scratch I might do it a different way, but 🤷‍♂️

@shilman
Copy link
Member Author

shilman commented Jul 4, 2018

@tmeasday Is the idea for withOptions just to simplify the API and make it more consistent (which is a good enough reason for me FWIW), or are there other benefits as well?

@tmeasday
Copy link
Member

tmeasday commented Jul 4, 2018

There is an advantage in parameter cascading (story parameters overriding whole-storybook or chapter parameters) -- see this comment: #3625 (comment)

But yeah, mostly just to be consistent.

@sapkra
Copy link

sapkra commented Jul 24, 2018

Is there any progress for the option plugin? Because this issue is the last open issue in the Storybook 4.0.0 Milestone.

@tmeasday
Copy link
Member

I was going to look at it in the next day or two. If you are interested it could be a good contribution to make to the project?

@sapkra
Copy link

sapkra commented Jul 25, 2018

Yeah right but I have to say sorry. I definitely have not the time to contribute to this project right know.
Maybe in some month I will find some time to contribute.

@tmeasday
Copy link
Member

No problem!

@igor-dv
Copy link
Member

igor-dv commented Aug 28, 2018

Let's remove storyshots from the list. It's a new functionality for it, and shouldn't block us.

@ghost ghost mentioned this issue Sep 7, 2018
3 tasks
@igor-dv igor-dv added merged and removed todo labels Sep 10, 2018
@tmeasday
Copy link
Member

Yay! This is now done! Great team effort everyone!

When I next have some free cycles I am going to look at #4010 but I agree its not a blocker for 4.0

@issue-sh issue-sh bot removed the merged label Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants