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

Add parameters to stories in the story store, and render them in app layers #2679

Merged
merged 9 commits into from
Mar 20, 2018

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Jan 8, 2018

Issue: #993

What I did

Added support for .add(name, fn, { parameters }), and similarly passing the options parameters as part of the story context.

Notes

This PR is incomplete, I have another one with some tests for the storystore that I will augment this with. I am interested in feedback on the feature and the approach.

Note that the various app layers no longer call .getStory() (now deprecated I think) and instead call the wrapped .getStoryWithContext() that handles the (generic) task of setting a context for the story. I think I caught all the places where we do this but let me know if not. Also need to test properly for all 4 app layers.

TODO

  • Add tests
  • Add API to react-native
  • Add documentation
  • Update addons to make use of it? [separate PR?]

</div>
),
{ myOption: 'value' }
);
Copy link
Member Author

Choose a reason for hiding this comment

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

See this example for insight into how this feature works. More importantly, decorators and addons get passed the context also.

@tmeasday tmeasday requested a review from a team January 8, 2018 05:55
@joscha
Copy link
Member

joscha commented Jan 8, 2018

This is quite cool, it would remove the need for the special abstraction around stories in percy-storybook as well. We currently introduce our own story type, add the options to a separate map and then extract them later again. See https://github.com/percy/percy-storybook/blob/3609b6f013e5a6f94a9b294a008b30bad425b9bc/packages/percy-storybook/src/index.js#L43-L62

cc @timhaines

@@ -3,9 +3,9 @@ import {
enableProdMode,
NgModule,
Component,
NgModuleRef
NgModuleRef,
Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite sure why prettier is reformatting this file. Any insights @igor-dv?

@tmeasday
Copy link
Member Author

tmeasday commented Jan 8, 2018

Yes! Keen to get insight from such use cases.

@shilman
Copy link
Member

shilman commented Jan 8, 2018

@alterx @tmeasday @ndelangen @igor-dv Any idea why prettier was not applied to the original app/angular source files? Inconvenient to review the changes when a lot of the changes are formatting changes. If there's something wrong with our tooling we should fix it? I was under the impression that we run prettier automatically on precommits.

@igor-dv
Copy link
Member

igor-dv commented Jan 8, 2018

Looks like tslint is not configured to run on precommit at all. And eslint handles only js files. Maybe it's your IDE refactored it ? Will take a look on it soon.

@Hypnosphi
Copy link
Member

After resolving the conflicts, the noisy diff should be gone

@tmeasday tmeasday force-pushed the tmeasday/add-options-to-story-store branch 2 times, most recently from 4ee31ea to bcbc87a Compare January 9, 2018 07:15
@tmeasday
Copy link
Member Author

tmeasday commented Jan 9, 2018

Ok, angular guff sorted.

@igor-dv
Copy link
Member

igor-dv commented Jan 9, 2018

Looks legit. What if we have a few decorators, that need different options? Will it be like this :

add('..', 
 () => ..., 
 {
  notes: {},
  info: {},
 ...
})

By convention ?

@tmeasday
Copy link
Member Author

@igor-dv I suspect it might but I think that is the next question to answer after merging this one. There are some other related things, like special options:

.add(..., () => ..., { decorators: ... });

@codecov
Copy link

codecov bot commented Feb 9, 2018

Codecov Report

Merging #2679 into master will increase coverage by 0.07%.
The diff coverage is 52.38%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2679      +/-   ##
=========================================
+ Coverage   35.83%   35.9%   +0.07%     
=========================================
  Files         440     440              
  Lines        9636    9669      +33     
  Branches      907     905       -2     
=========================================
+ Hits         3453    3472      +19     
- Misses       5634    5643       +9     
- Partials      549     554       +5
Impacted Files Coverage Δ
app/angular/src/client/preview/render.js 0% <ø> (ø) ⬆️
app/vue/src/client/preview/render.js 0% <ø> (ø) ⬆️
app/react/src/client/preview/render.js 0% <ø> (ø) ⬆️
app/polymer/src/client/preview/render.js 0% <ø> (ø) ⬆️
app/react-native/src/preview/index.js 0% <0%> (ø) ⬆️
app/react-native/src/index.js 0% <0%> (ø) ⬆️
app/angular/src/client/preview/index.js 0% <0%> (ø) ⬆️
app/react/src/client/preview/index.js 0% <0%> (ø) ⬆️
...t-native/src/preview/components/StoryView/index.js 0% <0%> (ø) ⬆️
app/polymer/src/client/index.js 0% <0%> (ø) ⬆️
... and 74 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 c8373ff...5a81b74. Read the comment docs.

@tmeasday
Copy link
Member Author

tmeasday commented Feb 9, 2018

This is now ready to merge, barring any docs changes we want to make.

I don't think we currently document what the context looks like for a story---perhaps we should, but I suspect it's mainly addon authors that care.

I think maybe if we are OK with merging this as is, we could follow it up with an PR that uses the options instead of the more awkward foo({options})(story) HoC style API in our built-in addons and then document the technique that we settle on in the addon documentation.

@Hypnosphi
Copy link
Member

Just to be clear: those are not the same options which are set via addon-options?

@tmeasday
Copy link
Member Author

Just to be clear: those are not the same options which are set via addon-options?

No, but this is a good point, we should have a way to set options per-app and per-chapter.

@tmeasday tmeasday self-assigned this Feb 11, 2018
@tmeasday
Copy link
Member Author

Let me know what you think about the global and chapter addOptions API.

I also remembered that react-native isn't yet using the @storybook/core module, so I'll either need to reimplement the API there or change it to do so before we merge this.

@Hypnosphi
Copy link
Member

I'll either need to reimplement the API there or change it to do so before we merge this

The latter sounds better to me =)

@tmeasday
Copy link
Member Author

tmeasday commented Feb 18, 2018 via email

@tmeasday tmeasday force-pushed the tmeasday/add-options-to-story-store branch from 8942d79 to 9795fa6 Compare February 20, 2018 09:52
@tmeasday
Copy link
Member Author

tmeasday commented Mar 1, 2018

Ok, renamed to parameters. I think this is ready to merge.

@tmeasday tmeasday force-pushed the tmeasday/add-options-to-story-store branch from 1ad8532 to 6c68af0 Compare March 1, 2018 04:23
@tmeasday
Copy link
Member Author

tmeasday commented Mar 1, 2018

Well except for the Angular snapshot changes, which are a bit baffling. Should I just accept them @igor-dv?

@igor-dv
Copy link
Member

igor-dv commented Mar 1, 2018

Yeah. I don't know yet how to get rid of those ng-💩 things...

@tmeasday tmeasday force-pushed the tmeasday/add-options-to-story-store branch from 97b5af3 to f654b4b Compare March 6, 2018 03:40
@Hypnosphi Hypnosphi added this to the v4.0.0 milestone Mar 8, 2018
@Hypnosphi Hypnosphi merged commit 9340dde into master Mar 20, 2018
@Hypnosphi Hypnosphi deleted the tmeasday/add-options-to-story-store branch March 20, 2018 12:20
@tmeasday
Copy link
Member Author

🎉 going to start working on the next phase of my master plan now ;)

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