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

The api setQueryParams not working #8600

Closed
echoulen opened this issue Oct 29, 2019 · 15 comments
Closed

The api setQueryParams not working #8600

echoulen opened this issue Oct 29, 2019 · 15 comments

Comments

@echoulen
Copy link

echoulen commented Oct 29, 2019

Describe the bug
The method api.setQueryParams not working

To Reproduce

addons.register("storybook/something", (api) => {
  api.setQueryParams({abc: "hello"});
});

Expected behavior
expect api.getQueryParam("abc") to be "hello"

Screenshots
Screen Shot 2019-10-29 at 11 58 34 AM

Code snippets
Screen Shot 2019-10-29 at 11 57 30 AM

System:

"@storybook/addons": "^5.2.0",
"@storybook/react": "^5.2.0",

Additional context
The addon was not working with api.setQueryParams and api.getQueryParam any more
https://github.com/echoulen/storybook-addon-styled-component-theme

@stale
Copy link

stale bot commented Nov 26, 2019

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Nov 26, 2019
@shilman shilman added the todo label Nov 26, 2019
@stale stale bot removed the inactive label Nov 26, 2019
@alexreardon
Copy link
Contributor

I can confirm that this API is not working

@alexreardon
Copy link
Contributor

"@storybook/react": "6.0.0-alpha.30"

@alexreardon
Copy link
Contributor

This line is clearing the query string:

setTimeout(() => navigate(`${queryPath}`, { replace: true }), 1);

@ndelangen
Copy link
Member

The queryParam is for the preview, not the manager.

storybook/lib/api is code that only runs on the manager.

@alexreardon
Copy link
Contributor

So is there a way from my addon panel to set something in the query string? I am using the API in the same way as it is being used in the docs: https://storybook.js.org/docs/addons/api/#apisetqueryparams

@ndelangen
Copy link
Member

Why would you need to set something on the query of storybook's manager?

@echoulen
Copy link
Author

echoulen commented Apr 3, 2020

Hi @ndelangen
For my example, I have to set the active tab in my addon from query params if the user refresh the page

@ndelangen
Copy link
Member

For refreshes you could use the localStorage instead?

@echoulen
Copy link
Author

echoulen commented Apr 4, 2020

the route trigger enable tab is more make sense, I had used this API a long time ago, it's was broken after I upgrade the storybook, so that's why I report the issue.

@ndelangen
Copy link
Member

@echoulen you're 100% correct. The API used to set queries on the manager as well, but when we changed to use a router we removed this behavior so we could have clearer/readable URLs that wouldn't grow to be too long.

@alexreardon
Copy link
Contributor

I would like to be able to set the URL for sharing purposes. Right now I am unable to do anything to the URL as an addon as it is always cleared

@ndelangen
Copy link
Member

I agree that'd be useful

@echoulen
Copy link
Author

echoulen commented Apr 6, 2020

@ndelangen I see

@ndelangen
Copy link
Member

I think this problem has in essence been resolved by making globals persist on the URL:
https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals

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

4 participants