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

Use per-story parameters in Notes addon #3373

Merged
merged 9 commits into from
Apr 13, 2018

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Apr 6, 2018

Now we have per-story parameters, we can change the addon APIs to be more ergonomic via the use of parameters.

This PR is a first pass at changing the notes addon to use a parameter named notes. I want to put it out there to try and flush out any problems with the approach and get feedback before following up with changing the other addons.

New API:

Instead of:

storiesOf(..)
  .add(
    'using decorator arguments, withNotes',
    withNotes('Notes into withNotes')(() => <Story/>)
  );

We now do

storiesOf(..)
  .add('withNotes', () => <Story/>, {
    notes:
      'This is the notes for a button. This is helpful for adding details about a story in a separate panel.',
  })

To test

See the official-storybook.

@tmeasday tmeasday requested a review from a team April 6, 2018 03:37
@tmeasday tmeasday changed the title Update addon-notes README Use per-story parameters in Notes addon Apr 8, 2018
@Hypnosphi
Copy link
Member

Wow, so cool! Can we do the same for info?


```js
import { storiesOf } from '@storybook/react';
import { configure, addDecorator } from '@storybook/react`; // <- whichever storybook version you use
Copy link
Member

Choose a reason for hiding this comment

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

The "version" word is a bit confusing here =)

channel.emit('storybook/notes/add_notes', marked(text));
return (getStory, context) => {
const { parameters: { notes } } = context;
console.log({ options, getStory, context, notes });
Copy link
Member

Choose a reason for hiding this comment

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

Left by mistake?

Copy link
Member Author

Choose a reason for hiding this comment

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

😬

@tmeasday
Copy link
Member Author

tmeasday commented Apr 9, 2018

Can we do the same for info?

Yes, definitely, as well as some others.

I just wanted to get this out there and find out what people thought. For instance, are we OK with addons just claiming parameter namespaces (notes in this case)? Obviously there is scope for collision, but I am guessing people can be sensible about it.

Any other objections?

If not I will put a few utilities together that make this easier to do in each case and do the obvious things in the other addons.

@tmeasday
Copy link
Member Author

tmeasday commented Apr 9, 2018

Would like to see some explicit 👍 from some other interested folks before moving forward here.

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.

Interesting. It's not that different from what we used to be doing so I wouldn't call this an API revamp by any means. It is slightly better so I definitely welcome this tweak.

I think for an API v2, we should think about an API that resembles more like the content being rendered. I'm not a huge fan of these multiple function parameters in the .add() variants. The chaining of functions is also a bit bizarre withNotes()(). The way we declare storiesOf() is also a bit strange, and its also easy to miss the module parameter at the end as well.

Looks fine to me.

Copy link
Member

@igor-dv igor-dv left a comment

Choose a reason for hiding this comment

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

Very cool.

If this PR is targeting the v4, probably, it worth removing unneeded exports.

)
`;

storiesOf('Addons|Notes', module)
Copy link
Member

Choose a reason for hiding this comment

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

Please add these example to the other frameworks too

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep!

@tmeasday
Copy link
Member Author

tmeasday commented Apr 9, 2018

it worth removing unneeded exports.

@igor-dv do you mean the old WithNotes component (slated for removal in 4.0), or the support for withNotes('note')(story) / withMarkdownNotes('note')(story)? As much as 4.0 is a breaking release, I think we should have a period of deprecation..

Either we deprecate in an upcoming 3.4.x release (in which case this all needs to be backported to 3.4, probably not a great plan), or we leave the current API around (marked deprecated) until 5.0. I'm OK with that, really.

@tmeasday
Copy link
Member Author

tmeasday commented Apr 9, 2018

OK, I'll call that a quorum. Will finish off this PR then follow it up with similar changes to other addons.

@Hypnosphi
Copy link
Member

we should think about an API that resembles more like the content being rendered

You should probably take a look at https://github.com/storybooks/SBNext/blob/POC-bundler/examples/react/in/button/button.example.js

@tmeasday
Copy link
Member Author

@Hypnosphi / @danielduan I expect the concept of parameters to come through to the new API however---people will still need a way to annotate their "pure" examples with instructions for SB/documentation.

This isn't the place to discuss the exact API but one idea might be to add a property to the exported function:

export const example1 = () => <Component>with children</Component>;

example1.storyParameters = {
  notes: 'This is the story note that will appear in the storybook UI'
}

@codecov
Copy link

codecov bot commented Apr 13, 2018

Codecov Report

Merging #3373 into master will increase coverage by 0.03%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3373      +/-   ##
==========================================
+ Coverage   36.65%   36.69%   +0.03%     
==========================================
  Files         458      458              
  Lines       10124    10135      +11     
  Branches      895      886       -9     
==========================================
+ Hits         3711     3719       +8     
- Misses       5854     5877      +23     
+ Partials      559      539      -20
Impacted Files Coverage Δ
app/mithril/src/client/preview/render.js 0% <ø> (ø) ⬆️
addons/notes/src/index.js 90% <88.88%> (+32.85%) ⬆️
addons/notes/src/react.js 0% <0%> (-33.34%) ⬇️
lib/ui/src/modules/ui/libs/filters.js 48.64% <0%> (ø) ⬆️
addons/jest/src/hoc/provideJestResult.js 0% <0%> (ø) ⬆️
addons/info/src/components/markdown/pre/pre.js 77.58% <0%> (ø) ⬆️
lib/codemod/src/transforms/update-addon-info.js 50% <0%> (ø) ⬆️
addons/storysource/src/loader/index.js 0% <0%> (ø) ⬆️
addons/info/src/components/types/Enum.js 0% <0%> (ø) ⬆️
addons/storysource/src/loader/parsers/parser-ts.js 14.28% <0%> (ø) ⬆️
... and 61 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e8281ab...bd0eb7f. Read the comment docs.

@tmeasday
Copy link
Member Author

Updated the remaining app layers and addressed the other things on this ticket.

@tmeasday
Copy link
Member Author

Also removed WithNotes (old currently-deprecated API).

Next up I will factor out a utility to make this easy to generalize and deprecate the current API as part of that.

@Hypnosphi Hypnosphi merged commit 80c4bf5 into master Apr 13, 2018
@Hypnosphi Hypnosphi deleted the tmeasday/use-parameters-in-addons branch April 13, 2018 23:45
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.

None yet

4 participants