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 URL query param feature #6601

Merged
merged 11 commits into from
Apr 24, 2019
Merged

Add URL query param feature #6601

merged 11 commits into from
Apr 24, 2019

Conversation

leoyli
Copy link
Contributor

@leoyli leoyli commented Apr 24, 2019

Issue: #6602

What I did

  • [feature] query param feature.
  • [type] types to match with its typed function name.
  • [doc] quickly document the new feature in README.md.
  • [test] add tests to cover the newly added serializers.
  • [chore] clean up: rename file structure.

How to test

Story running under default contexts

Story running under preselected contexts set by URL query params

Known bugs

  • The iframe URL is not get updated unless you switch from tabs (i.e. the iframe opening url is out of sync), which is the same problem as in the addon-knob.
  • Perform api.setQueryParams({ contexts: null }): nothing happened, but based on the doc this query param should be removed.

Will file issues later to track it.

@leoyli leoyli added this to the 5.1.0 milestone Apr 24, 2019
@leoyli leoyli requested review from shilman and ndelangen April 24, 2019 01:31
@leoyli leoyli self-assigned this Apr 24, 2019
@vercel
Copy link

vercel bot commented Apr 24, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-add-addon-contextsurl-q.storybook.now.sh

@shilman
Copy link
Member

shilman commented Apr 24, 2019

Possibly related to the known bugs #6075

@tmeasday is looking into that issue

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

Sorry for some drastic files movement, but I think this can make the source code easier to follow... And I quickly add 2 tests to cover the new pure functions. I think the feature is good to go. Let me see if we can push this addon to Angular community as the next. 💪

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Looking great @leoyli 👏

I wonder if there are some types & patterns of this that would be useful for other addons as well (e.g. the createAddonDecorator) @ndelangen @tmeasday

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

@shilman, I believe there are some pattern that potential can be further extracted to make cross framework addon development a breeze. I would be happy to share or draft a post to discuss on it. So far it seems each addon came up its unique way (and I came up with my own... but hope people think this could be easy to understand and follow).

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

I guess many people starts to get no-cycle linter errors due to eslint-plugin-import v1.7.2. The feature was added last year but get finally fixed and running out-of-box. It's a nice linting though. Here is the error when I run it on my local machine:

/Volumes/Data/GitHub/storybook/addons/info/src/components/types/ArrayOf.js
  1:1  error  Unused eslint-disable directive (no problems were reported from 'import/no-cycle')

/Volumes/Data/GitHub/storybook/addons/info/src/components/types/ObjectOf.js
  1:1  error  Unused eslint-disable directive (no problems were reported from 'import/no-cycle')

/Volumes/Data/GitHub/storybook/addons/info/src/components/types/OneOfType.js
  1:1  error  Unused eslint-disable directive (no problems were reported from 'import/no-cycle')

/Volumes/Data/GitHub/storybook/addons/info/src/components/types/PrettyPropType.js
  1:1  error  Unused eslint-disable directive (no problems were reported from 'import/no-cycle')

/Volumes/Data/GitHub/storybook/addons/info/src/components/types/Shape.js
  1:1  error  Unused eslint-disable directive (no problems were reported from 'import/no-cycle')

@shilman
Copy link
Member

shilman commented Apr 24, 2019

@leoyli I just pushed a fix for the linting error. Hopefully it passes CI. 🙏

@shilman
Copy link
Member

shilman commented Apr 24, 2019

@leoyli BTW can you create an issue in the storybook repo and reference that instead using the Issue: #xxx format? that way the issue will be closed & commented on when i release this improvement

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

@shilman, do you mean open an issue for the linting error or copy the original issue into this repo?!

@shilman
Copy link
Member

shilman commented Apr 24, 2019

@leoyli copy the original issue into this repo

@leoyli leoyli force-pushed the add/addon-contexts/url-query-param branch from d8ca8e0 to d66aa30 Compare April 24, 2019 05:12
@codecov
Copy link

codecov bot commented Apr 24, 2019

Codecov Report

Merging #6601 into next will increase coverage by 0.02%.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #6601      +/-   ##
==========================================
+ Coverage   40.67%   40.69%   +0.02%     
==========================================
  Files         633      633              
  Lines        8674     8686      +12     
  Branches      620      624       +4     
==========================================
+ Hits         3528     3535       +7     
- Misses       5057     5061       +4     
- Partials       89       90       +1
Impacted Files Coverage Δ
...contexts/src/manager/components/ToolbarControl.tsx 0% <ø> (ø)
addons/contexts/src/manager/components/ToolBar.tsx 0% <ø> (ø)
addons/contexts/src/shared/constants.ts 100% <ø> (ø)
...ns/contexts/src/manager/components/ToolBarMenu.tsx 0% <ø> (ø)
...exts/src/manager/components/ToolBarMenuOptions.tsx 0% <ø> (ø)
addons/contexts/src/manager/libs/useChannel.ts 0% <ø> (ø) ⬆️
addons/contexts/src/preview/frameworks/react.ts 0% <0%> (ø) ⬆️
addons/contexts/src/register.ts 0% <0%> (ø) ⬆️
addons/contexts/src/preview/ContextsPreviewAPI.ts 0% <0%> (ø)
addons/contexts/src/manager/ContextsManager.tsx 0% <0%> (ø)
... and 16 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 6a71a0b...d66aa30. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 24, 2019

Codecov Report

Merging #6601 into next will increase coverage by 0.03%.
The diff coverage is 30.3%.

Impacted file tree graph

@@            Coverage Diff            @@
##             next   #6601      +/-   ##
=========================================
+ Coverage   40.67%   40.7%   +0.03%     
=========================================
  Files         633     633              
  Lines        8674    8687      +13     
  Branches      620     625       +5     
=========================================
+ Hits         3528    3536       +8     
- Misses       5057    5062       +5     
  Partials       89      89
Impacted Files Coverage Δ
addons/contexts/src/manager/components/ToolBar.tsx 0% <ø> (ø)
addons/contexts/src/shared/constants.ts 100% <ø> (ø)
...ns/contexts/src/manager/components/ToolBarMenu.tsx 0% <ø> (ø)
...exts/src/manager/components/ToolBarMenuOptions.tsx 0% <ø> (ø)
addons/contexts/src/manager/libs/useChannel.ts 0% <ø> (ø) ⬆️
...contexts/src/manager/components/ToolbarControl.tsx 0% <0%> (ø)
addons/contexts/src/preview/frameworks/react.ts 0% <0%> (ø) ⬆️
addons/contexts/src/register.ts 0% <0%> (ø) ⬆️
addons/contexts/src/preview/ContextsPreviewAPI.ts 0% <0%> (ø)
addons/contexts/src/manager/ContextsManager.tsx 0% <0%> (ø)
... and 10 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 6a71a0b...d2704db. Read the comment docs.

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

I have rebased the branch, and patch d66aa30, b178d68 for fixing the potential bugs due to exposing the state via URL query param. This avoid any inconsistency (as far as I can catch).

@shilman
Copy link
Member

shilman commented Apr 24, 2019

@leoyli build failed in addons/contexts:

$ node ../../scripts/prepare.js
src/shared/serializers.ts(21,3): error TS2322: Type 'string[]' is not assignable to type 'SelectionState'.
  Index signature is missing in type 'string[]'.

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

@shilman, learned a lesson on .reduce type inference... sometimes it failed in inferring the type, especially when its initial value is null or undefined; then I have to manually specify it 👀.

@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

Going to merge it since CD/CI are happy and all my paranoid checks and bug hunting have been done! 💪

@leoyli leoyli merged commit 97fbbc0 into next Apr 24, 2019
@leoyli leoyli deleted the add/addon-contexts/url-query-param branch April 24, 2019 13:26
@leoyli leoyli restored the add/addon-contexts/url-query-param branch April 24, 2019 13:29
@leoyli leoyli deleted the add/addon-contexts/url-query-param branch April 24, 2019 13:29
@leoyli leoyli restored the add/addon-contexts/url-query-param branch April 24, 2019 13:29
@leoyli
Copy link
Contributor Author

leoyli commented Apr 24, 2019

Related to #6602.

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.

2 participants