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

[addon-options | ui] how to set default options instead of options #1185

Closed
Stupidism opened this issue Jun 2, 2017 · 7 comments
Closed

Comments

@Stupidism
Copy link
Contributor

Now options specified in url will be blocked by setOptions of addon-options

@Stupidism Stupidism changed the title [addon-options|ui] how to set default options instead of options [addon-options | ui] how to set default options instead of options Jun 3, 2017
@Stupidism
Copy link
Contributor Author

I'm trying to fix this out of the library. But I found I can't get the real location variable. It seems to be a race problem.

import qs from 'query-string';

const getResponsiveOptions = () => {
  if (typeof window === 'undefined') return {};

  const width = window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;

  return {
    downPanelInRight: width > 1200,
    goFullScreen: width < 600,
  }
};

const getOptionsFromUrl = () => {
  if (typeof window === 'undefined') return {};
  const queryString = location.search.substring(1);
  if (!queryString || queryString === '') return {};
  const parsedQs = qs.parse(queryString);
  const {
    full,
    down,
    left,
    panelRight,
    downPanel,
  } = parsedQs;

  const options = {};

  if (typeof full !== 'undefined') options.goFullScreen = Boolean(Number(full));
  if (typeof down !== 'undefined') options.showDownPanel = Boolean(Number(down));
  if (typeof left !== 'undefined') options.showLeftPanel = Boolean(Number(left));
  if (typeof panelRight !== 'undefined') options.downPanelInRight = Boolean(Number(panelRight));

  console.log(location, full, options);

  return options;
};

const defaultOptions = {
  goFullScreen: false,
  showLeftPanel: true,
  showDownPanel: true,
  showSearchBox: true,
  downPanelInRight: true,
};

console.log('options', getResponsiveOptions(), getOptionsFromUrl());

export default {
  ...defaultOptions,
  ...getResponsiveOptions(),
  ...getOptionsFromUrl(),
}

I tried to access a url http://localhost:6006/?selectedKind=Welcome&selectedStory=to%20stupid-rc-starter&full=1&down=1&left=1&panelRight=0&downPanel=storybook%2Faddon-actions%2Factions-panel
But the search in the printed location has a chance to be ?selectedKind=Welcome&selectedStory=to%20stupid-rc-starter

@stale
Copy link

stale bot commented Oct 31, 2017

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. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks!

@stale stale bot added the inactive label Oct 31, 2017
@Stupidism
Copy link
Contributor Author

Is this fixed or not?

@stale stale bot removed the inactive label Nov 1, 2017
@Hypnosphi
Copy link
Member

Not yet. There is some discussion in #1690

@stale
Copy link

stale bot commented Dec 16, 2017

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 60 days. Thanks!

@stale stale bot added the inactive label Dec 16, 2017
@stale
Copy link

stale bot commented Jan 30, 2018

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 60 days. Thanks!

@stale stale bot added the inactive label Jan 30, 2018
@stale
Copy link

stale bot commented Feb 14, 2018

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Feb 14, 2018
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

3 participants