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-Actions: Add preset and configure with parameters #9933

Merged
merged 12 commits into from
Mar 27, 2020

Conversation

jonspalmer
Copy link
Contributor

@jonspalmer jonspalmer commented Feb 22, 2020

Issue: #9741

What I did

Add a preset for Actions Addon
Changed Action Addon to be configured via parameters
Simplified the Server app to remove the special case actions code in favor of parameters.

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.

LGTM aside from disable not working. @tmeasday do you know the fix off the top of your head?

@jonspalmer jonspalmer changed the title Add Preset for Actions Addon Actions Addon - Add Preset for and configure with Parameters Feb 23, 2020

export const createDecorator = (actionsFn: any) => (...args: any[]) => (storyFn: () => any) => {
applyEventHandlers(actionsFn, ...args)

return storyFn();
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

createDecorator is used by the decorate options. I'm a bit fuzzy on that use case but we have examples of it in a few examples.

@@ -1,8 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`json-to-csf-compiler actions.json 1`] = `
"import { withActions } from '@storybook/addon-actions';

"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making @tmeasday happy to see the imports go away!

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

Just a bunch of thoughts, I'm not quite sure of the exact way forward

MIGRATION.md Outdated Show resolved Hide resolved

You can define action handles in a declarative way using `withActions` decorators. It accepts the same arguments as [`actions`](#multiple-actions)
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand this line, it doesn't seem correct ("It accepts the same arguments as [actions]"). I realise this was here before but it doesn't seem right at all. The arguments are very much different.

addons/actions/src/preview/withActions.ts Outdated Show resolved Hide resolved
addons/actions/src/preview/withActions.ts Show resolved Hide resolved
addons/actions/src/preview/withActions.ts Outdated Show resolved Hide resolved

export const createDecorator = (actionsFn: any) => (...args: any[]) => (storyFn: () => any) => {
Copy link
Member

Choose a reason for hiding this comment

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

How is this used? I think we should drop it and just allow deprecated usage below..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It ends up getting used like this example:

https://github.com/storybookjs/storybook/blob/next/examples/html-kitchen-sink/stories/addon-actions.stories.js#L40

Feels weird to me but maybe I'm not understanding the use case.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, wow that's pretty weird. I suspect this is a super old usage pattern from before we had support for story-level decorators, this was the only way to apply a decorator to a single story.

I'm not sure we need to keep supporting it. WDYT @shilman?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think we should drop support for this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There isn't a great way to remove this without removing the ability to manipulate the event data for frameworks like html and web components.

The problem is if you use parameters then the presetDecorator will apply but it would have the customer actionFunctions that decorate otherwise adds. We can't use parameters to supply the actionFunctions as they have to be serializable (so args v1 won't help here either).

Is there some other mechanism where we can 'configure' the decorator to use a different set of action functions? @tmeasday @shilman ?

Copy link
Member

Choose a reason for hiding this comment

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

@jonspalmer I don't really understand what that use case is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tmeasday I'm not too sure of it either. It looks like we went out of our way to allow people to manipulate the event arguments. I'm not clear why you want that.

In React land (or some other JS component framework) if you wanted to manipulate the args of the event handler you could do this without any special support from the actions addon:

import { action } from '@storybook/addon-actions';
import Button from './button';

export default {
  title: 'Button',
  component: Button,
};

const clickAction = action('click');

export const first = () => (
  <Button onClick={(...args) => clickAction(args[0])}>Hello World!</Button>
);

However in html or web components we can't do it in the story function. So the equivalent is:

import { decorate } from '@storybook/addon-actions';

const firstArg = decorate([args => [args[0]]]);

export const first = () => firstArg.withActions('click')(
  () => `<button type="button">Hello World!</button>`;
);

If its important to support the manipulate of event args I don't think we have a great way to maintain support other than this approach. However, I could see us dropping it entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a conversation with @shilman we agreed the decorate API is YAGNI. I've removed it and updated the docs.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for explaining it to me anyway @jonspalmer, I get it now ;)

@@ -0,0 +1,90 @@
import addons from '@storybook/addons';
import { actions } from '../..';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel a lot better having a test of some of the new logic. Not sure if this is the best factoring. Some prior art from the action.test. Could perhaps make it a little less verbose but...

@jonspalmer
Copy link
Contributor Author

@tmeasday @shilman I've rebased from next. I think this is good to go. Looks like CircleCI is borked - Do we have to pay them money to get more credits?

@shilman
Copy link
Member

shilman commented Mar 24, 2020

Awesome @jonspalmer!! 💯 Re: CircleCI, I think @ndelangen 's running point on this. Hopefully we can get it sorted out quickly 🤞

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.

🥇

@ndelangen
Copy link
Member

We're sponsored by CircleCI, but something is mis-configured. They are working on it to resolve this.

@shilman shilman modified the milestones: 6.0, 6.0 server Mar 26, 2020
@shilman shilman changed the title Actions Addon - Add Preset for and configure with Parameters Addon-Actions: Add preset and configure with parameters Mar 27, 2020
@shilman shilman merged commit 4007098 into storybookjs:next Mar 27, 2020
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.

4 participants