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 params-based API to options addon #3965

Merged
merged 8 commits into from
Sep 8, 2018

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Aug 6, 2018

Issue:

Options API wasn’t using params and couldn’t really be used per-story

What I did

  • Added a params-based API: .add(name, story, { options: {… } })
  • Added stories to official storybook
  • Updated .setOptions internally to reset each time, rather than remembering the previous state (and only overriding new keys). This didn’t really make sense and was broken when you switched between stories that set options, unless they all set all options, which users aren’t going to do.

STILL OUTSTANDING

When you change panels via options it does not re-calculate sizing. So if you hide the addons panel, it will leave a bunch of empty space. Can someone who knows the internals give me some advice on how to re-calculate sizes when options are set?

How to test

Is this testable with Jest or Chromatic screenshots?

There are some jest test that touch on it, but the UI is not currently captured by our screenshots for these stories.

Does this need a new example in the kitchen sink apps?

Yes, done.

Does this need an update to the documentation?

Yes, done (TODO).

If your answer is yes to any of these, please make sure to include it in your PR.

For maintainers only: Please tag your pull request with at least one of the following:
["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@tmeasday tmeasday changed the title tmeasday/add-params-to-options-addon Add params-based API to options addon Aug 6, 2018
@storybook-safe-bot
Copy link
Contributor

Fails
🚫

PR is not labeled with one of: ["cleanup","BREAKING CHANGE","feature request","bug","documentation","maintenance","dependencies:update","dependencies","other"]

Generated by 🚫 dangerJS

@ndelangen
Copy link
Member

@tmeasday I saw this PR first, looked great to me, but maybe you have thoughts on it?

#3958

You seem to be be of the opinion options should reset. Perhaps you can rebase this PR and implement that, if you so desire?

@tmeasday
Copy link
Member Author

tmeasday commented Aug 7, 2018

Wow I was totally gazumped by @nm123github -- nice ;)

From playing around with it a bit, I think the options need to be reset, otherwise you get super weird behaviour as the options drift as you change stories.

I'll rebase this PR against current master. New questions based on that PR:

  1. I'm not sure we should have a story about this in the marko example app? I think these kind SB-wide stories should just be in official storybook, right?

  2. We should ensure that the global setOptions function actually calls setParameters so the "default" options are the user's. (As pointed out by @nm123github) actually this part works.

  3. We need to deal with panel resizing still, when you toggle between "addon panel open" and "addon panel closed" at any rate.

This is just for simplicity. I think it is best if non-framework specific stories all live in official-storybook; that way they are easier to find in the future.

cc @nm123github
cc @nm123github -- FYI -- we made this shortcut so you don't need to call `addDecorator` followed by `addParameters`.
@nm123github
Copy link
Contributor

@tmeasday had no idea you were working on this too 🙂 , thanks for the review..

- I'm not sure we should have a story about this in the marko example app? I think these kind SB-wide stories should just be in official storybook, right?
Agreed, i will remove those and add something like that in official storybook

- We need to deal with panel resizing still, when you toggle between "addon panel open" and "addon panel closed" at any rate.
Can you please tell me little more about this? Maybe a gify or some screenshots might help. Also, feel free to PM on slack.

From playing around with it a bit, I think the options need to be reset, otherwise you get super weird behaviour as the options drift as you change stories.
^ you know, i would kinda agree with that, but @ndelangen mentioned "setOptions being persistent is expected behavior I think?". Also, i am not sure if there is current functionality that allows to setOptions specifically for a story, or if that will need to be built.

@ndelangen
Copy link
Member

Let me know when it's ready for review?

@tmeasday
Copy link
Member Author

tmeasday commented Aug 8, 2018

I've done 1. in this PR also. So from my perspective the remaining issue is just resizing the panels when they are hidden. Let me make a couple of gifs.

@tmeasday
Copy link
Member Author

tmeasday commented Aug 8, 2018

"setOptions being persistent is expected behavior I think?". Also, i am not sure if there is current functionality that allows to setOptions specifically for a story, or if that will need to be built.

I think maybe I have confused things a little -- this PR retains top-level setOptions being persisted, what it does not persist is story-level options being persisted. For instance in current master we have this behaviour:

ezgif com-video-to-gif

Notice how the Actions story's addons panel location depends on the previous story you looked at. It's even more of a problem when a story is e.g. hiding the panel.

If the user sets options on every story it is not a problem, but this isn't what users will expect i don't think. In any case I think this PR has the best of both worlds (story-level options are not remembered, global options set via setOptions are).

@nm123github
Copy link
Contributor

Thanks for taking care of this @tmeasday

@tmeasday
Copy link
Member Author

tmeasday commented Aug 8, 2018

No worries @nm123github -- just standing on your shoulders

@tmeasday
Copy link
Member Author

tmeasday commented Aug 8, 2018

On the subject on panel resizing I cannot reproduce the problem on master so hopefully I can figure out what's different on this branch and solve it. Will look later today.

@igor-dv
Copy link
Member

igor-dv commented Aug 8, 2018

@tmeasday, probably I am missing something, but playing with preview of your PR (didn't review the code yet), I do see options are persistent between stories. For example, the "Custom Storybook" name is remaining when navigating out of the story that changed it.

BTW I would also limit what people can change. For example, not allow changing hierarchy options.

@tmeasday tmeasday force-pushed the tmeasday/add-params-to-options-addon branch from 49694b7 to c865719 Compare August 8, 2018 09:39
@codecov
Copy link

codecov bot commented Aug 8, 2018

Codecov Report

Merging #3965 into master will increase coverage by 0.02%.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3965      +/-   ##
==========================================
+ Coverage   40.46%   40.48%   +0.02%     
==========================================
  Files         491      491              
  Lines        5835     5832       -3     
  Branches      793      791       -2     
==========================================
  Hits         2361     2361              
+ Misses       3085     3084       -1     
+ Partials      389      387       -2
Impacted Files Coverage Δ
addons/options/preview.js 100% <ø> (ø) ⬆️
lib/ui/src/modules/api/index.js 0% <ø> (ø) ⬆️
addons/options/src/preview/index.js 0% <0%> (ø) ⬆️
lib/ui/src/modules/shortcuts/actions/shortcuts.js 40.62% <100%> (ø) ⬆️
lib/ui/src/modules/shortcuts/defaultState.js 100% <100%> (ø)
lib/ui/src/modules/api/actions/api.js 100% <100%> (ø) ⬆️

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 e7d3a57...d309b91. Read the comment docs.

@tmeasday
Copy link
Member Author

tmeasday commented Aug 8, 2018

@igor-dv

probably I am missing something, but playing with preview of your PR (didn't review the code yet), I do see options are persistent between stories. For example, the "Custom Storybook" name is remaining when navigating out of the story that changed it.

Nope, you are not missing something, I thought I had fixed the problem but it turns out only partially.

Any ideas on how we could fix it properly? Would using a subscription help? I'm aware we don't want options to thrash as you go between stories. Ideally you would have the withOptions decorator applied at all times, but I don't think we can guarantee that.

BTW I would also limit what people can change. For example, not allow changing hierarchy options.

Yeah I think maybe we should just do the shortcutOptions and not the uiOptions

@tmeasday
Copy link
Member Author

tmeasday commented Aug 8, 2018

Here is a video of the issue with panel resizing. For some reason it doesn't happen for the deployed storybook. Anyone have any idea why?

ezgif com-video-to-gif-3

@tmeasday
Copy link
Member Author

tmeasday commented Aug 9, 2018

Ok, I investigated the panel resizing. I think the reason it doesn't happen on the deployed version is that it only happens in react dev mode. More details here: tomkp/react-split-pane#309

I'm not sure if we should ship this feature until this bug is fixed? It seems like storybook is buggy to have a story hide the addon panel and the layout gets broken.

Can anyone think of an easy workaround?

@nm123github
Copy link
Contributor

I could repro this locally. Does seem strange.

@tmeasday
Copy link
Member Author

I could also fork / PR react-split-pane to try and get the bug fixed quicker

@wuweiweiwu
Copy link
Member

@tmeasday If you could PR a fix that'll be amazing. I'm also a collaborator on react-split-pane so i can review it. I just don't have the bandwidth right now to write a fix :(

@igor-dv
Copy link
Member

igor-dv commented Aug 16, 2018

Any ideas on how we could fix it properly?

I will try to play with this PR a bit =)

@tmeasday
Copy link
Member Author

tmeasday commented Sep 8, 2018

Ok @igor-dv, that solves it. Let's recommend people use withOptions and deprecate setOptions. Easy.

@tmeasday tmeasday force-pushed the tmeasday/add-params-to-options-addon branch from c1d93ab to d9ab31c Compare September 8, 2018 04:25
@Hypnosphi Hypnosphi merged commit 1dc036e into master Sep 8, 2018
@Hypnosphi Hypnosphi deleted the tmeasday/add-params-to-options-addon branch September 8, 2018 17:35
@wuweiweiwu
Copy link
Member

Ill open an issue to update react-split-pane to 0.1.83, which would solve the StrictMode issues. Thanks again @tmeasday

@Hypnosphi
Copy link
Member

I don't think it can be merged to 3.4

@wuweiweiwu
Copy link
Member

On further investigation, @tmeasday I think I'll have to make additional changes, updating to 0.1.83 breaks the drag action in layouts somehow, it drags extremely slow.

@tmeasday
Copy link
Member Author

tmeasday commented Sep 9, 2018

@igor-dv, yeah this v4 only as params aren’t in v3

@wuweiweiwu any idea why? Afaict the function I changed is only called from componentDidMount and getDerivedStateFromProps, it’s explicitly not called from the drag handler.

Let me know if I can assist!

@igor-dv
Copy link
Member

igor-dv commented Sep 9, 2018

We can just add a deprecation warning to v3.4. Just so sad to pollute a beauty of the v4 with deprecations 😢

@tmeasday
Copy link
Member Author

tmeasday commented Sep 9, 2018

Can’t really deprecate something until an alternative is in place!

I think it’s fine to have something (setOptions) that is undocumented and deprecated in our shiny new thing. Previous users will appreciate not having their storybooks break!

@wuweiweiwu
Copy link
Member

wuweiweiwu commented Sep 10, 2018

@tmeasday not sure yet. I think getDerivedStaetFromProps being called multiple times per render in dev mode breaks stuff since our size calculation is not pure. I'll dig into it tonight.

edit: seems the new changes also breaks dragging in strict mode. It removed the size invalidation checks

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.

8 participants