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

Fix info upgrade codemod failing when optional description string is not supplied #2138

Merged
merged 3 commits into from
Oct 28, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,11 @@ storiesOf('Button').addWithInfo(
}
}
)

storiesOf('shared/ProgressBar', module)
.addDecorator(withKnobs)
.addWithInfo('default style', () => (
<ProgressBar progress={number('progress', 25)}
delay={number('delay', 500)}
/>
));
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,11 @@ storiesOf('Button').add('with custom styles', withInfo({
return stylesheet
}
})(() => <Button label="The Button" onClick={action('onClick')} />))

storiesOf('shared/ProgressBar', module)
.addDecorator(withKnobs)
.add('default style', withInfo('default style')(() => (
<ProgressBar progress={number('progress', 25)}
delay={number('delay', 500)}
/>
)));
11 changes: 10 additions & 1 deletion lib/codemod/src/transforms/update-addon-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default function transformer(file, api) {
*/
const getOptions = args => {
if (args[3] === undefined) {
if (args[2] === undefined) {
// when the optional description string is not supplied for addWithInfo, just use story name
return [args[0]];
}
return [args[1]];
}
return [
Expand All @@ -56,10 +60,15 @@ export default function transformer(file, api) {
const node = addWithInfoExpression.node;
const args = node.arguments;

// if optional description string is not supplied, the story component becomes second arg
const storyComponent = args[2] ? args[2] : args[1];

node.callee.property.name = 'add';
node.arguments = [
args[0],
j.callExpression(j.callExpression(j.identifier('withInfo'), getOptions(args)), [args[2]]),
j.callExpression(j.callExpression(j.identifier('withInfo'), getOptions(args)), [
storyComponent,
]),
];

return node;
Expand Down