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

UI: Fix disable parameter to hide addon panel #12171

Merged
merged 2 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- [6.0 Addon API changes](#60-addon-api-changes)
- [Consistent local addon paths in main.js](#consistent-local-addon-paths-in-mainjs)
- [Deprecated setAddon](#deprecated-setaddon)
- [Deprecated disabled parameter](#deprecated-disabled-parameter)
- [Actions addon uses parameters](#actions-addon-uses-parameters)
- [Removed action decorator APIs](#removed-action-decorator-apis)
- [Removed withA11y decorator](#removed-witha11y-decorator)
Expand Down Expand Up @@ -599,6 +600,22 @@ We've deprecated the `setAddon` method of the `storiesOf` API and plan to remove

Since early versions, Storybook shipped with a `setAddon` API, which allows you to extend `storiesOf` with arbitrary code. We've removed this from all core addons long ago and recommend writing stories in [Component Story Format](https://medium.com/storybookjs/component-story-format-66f4c32366df) rather than using the internal Storybook API.

#### Deprecated disabled parameter

Starting in 6.0.17, we've renamed the `disabled` parameter to `disable` to resolve an inconsistency where `disabled` had been used to hide the addon panel, whereas `disable` had been used to disable an addon's execution. Since `disable` was much more widespread in the code, we standardized on that.

So, for example:

```
Story.parameters = { actions: { disabled: true } }
```

Should be rewritten as:

```
Story.parameters = { actions: { disable: true } }
```

#### Actions addon uses parameters

Leveraging the new preset `@storybook/addon-actions` uses parameters to pass action options. If you previously had:
Expand Down
23 changes: 21 additions & 2 deletions lib/api/src/modules/addons.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { ReactElement } from 'react';

import { WindowLocation } from '@reach/router';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';

import { ModuleFn } from '../index';
import { Options } from '../store';
import { isStory } from '../lib/stories';

const warnDisabledDeprecated = deprecate(
() => {},
dedent`
Use 'parameters.key.disable' instead of 'parameters.key.disabled'.

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-disabled-parameter
`
);

yannbf marked this conversation as resolved.
Show resolved Hide resolved
export type ViewMode = 'story' | 'info' | 'settings' | 'page' | undefined | string;

export enum types {
Expand Down Expand Up @@ -104,7 +115,15 @@ export const init: ModuleFn = ({ provider, store, fullAPI }) => {
const filteredPanels: Collection = {};
Object.entries(allPanels).forEach(([id, panel]) => {
const { paramKey } = panel;
if (paramKey && parameters && parameters[paramKey] && parameters[paramKey].disabled) {
if (
paramKey &&
parameters &&
parameters[paramKey] &&
(parameters[paramKey].disabled || parameters[paramKey].disable)
) {
if (parameters[paramKey].disabled) {
warnDisabledDeprecated();
}
return;
}
filteredPanels[id] = panel;
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/tests/addons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Addons API', () => {
[storyId]: {
isLeaf: true,
parameters: {
a11y: { disabled: true },
a11y: { disable: true },
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/src/containers/panel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const AllAddons = () => <div>By default all addon panels are rendered</di
export const FilteredAddons = () => <div>By default all addon panels are rendered</div>;

FilteredAddons.parameters = {
a11y: { disabled: true },
actions: { disabled: true },
a11y: { disable: true },
actions: { disable: true },
};