Skip to content

Commit

Permalink
Merge pull request #2138 from storybooks/dd/fix-info-opt-desc
Browse files Browse the repository at this point in the history
Fix info upgrade codemod failing when optional description string is not supplied
  • Loading branch information
danielduan authored Oct 28, 2017
2 parents 287414f + 6599b38 commit de474b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit de474b6

Please sign in to comment.