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

Select knob key/value ordering #1745

Merged
merged 19 commits into from
Jan 31, 2018
Merged

Select knob key/value ordering #1745

merged 19 commits into from
Jan 31, 2018

Conversation

psimyn
Copy link
Member

@psimyn psimyn commented Aug 27, 2017

continued from #1449

fixes #799

Issue:

Using knobs is currently confusing.

Example, for complex strings and null values

select('My Select', {
  none: null, // renders empty item
  [`Computed key`]: 'computed', 
  'Some kind of long sentence. This is ok, mainly just looks odd as a key': 'sentence',
})

What I did

Use value as value
Still uses key for the key property on each <option>

How to test

select('My Select', {
  Empty: null,
  'First item': 'The first item selected',
  second: `The item with key 'second' is selected`
})

Is this testable with jest or storyshots?

Does this need a new example in the kitchen sink apps?

Does this need an update to the documentation?

If your answer is yes to any of these, please make sure to include it in your PR.


This change is Reviewable

@codecov
Copy link

codecov bot commented Aug 27, 2017

Codecov Report

Merging #1745 into master will increase coverage by 0.1%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1745     +/-   ##
=========================================
+ Coverage   35.73%   35.84%   +0.1%     
=========================================
  Files         428      428             
  Lines        9444     9452      +8     
  Branches      978      980      +2     
=========================================
+ Hits         3375     3388     +13     
+ Misses       5421     5405     -16     
- Partials      648      659     +11
Impacted Files Coverage Δ
addons/knobs/src/angular/index.js 0% <ø> (ø) ⬆️
addons/knobs/src/vue/index.js 24.13% <ø> (ø) ⬆️
addons/knobs/src/index.js 0% <ø> (ø) ⬆️
addons/knobs/src/react/index.js 40% <ø> (ø) ⬆️
addons/knobs/src/base.js 11.76% <33.33%> (+5.09%) ⬆️
addons/knobs/src/components/types/Select.js 24.63% <63.63%> (+16.7%) ⬆️
app/react/src/server/utils.js 0% <0%> (-53.58%) ⬇️
lib/core/src/client/preview/story_store.js 84.21% <0%> (ø) ⬆️
lib/ui/src/modules/ui/components/menu_item.js 19.14% <0%> (ø) ⬆️
addons/knobs/src/components/types/Button.js 11.9% <0%> (ø) ⬆️
... and 54 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d8db3e...5928842. Read the comment docs.

@danielduan
Copy link
Member

Think this should go out as a minor version instead of a patch.

Is this documented anywhere and also is there an example somewhere in the cra-kitchen-sink for this?

@psimyn
Copy link
Member Author

psimyn commented Sep 10, 2017

@danielduan I've updated addons README (and rebased on latest release/3.3)

Not sure about adding to kitchen-sink examples, since for users it is identical to existing select. What do you think?

};
const defaultValue = 'Red';

const value = select(label, options, defaultValue);
Copy link
Member

Choose a reason for hiding this comment

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

effectively, this should be selectV2() with this PR change?

I don't think this alleviates the breaking change, it only defers the problem to a later date.

Copy link
Member

Choose a reason for hiding this comment

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

yes, seems that by doing that we could release this early and deprecate the old method, and then remove the old implementation at the next major.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, this means the breaking change in v4 will be renaming selectV2 to select

this was meant to be selectV2, I've updated it 👍

@ndelangen
Copy link
Member

@psimyn The addon has changed somewhat since this PR was rebased, mainly support for Vue and Angular was introduced, and thus a lot of code was moved.

Do you think you could fix the merge conflicts? Let me know if you need help?

@Hypnosphi Hypnosphi changed the base branch from release/3.3 to master December 23, 2017 23:55
fixes #799
add selectV2 for backwards compatibility
@psimyn
Copy link
Member Author

psimyn commented Dec 30, 2017

@ndelangen I've updated this with latest master, and added a test for the SelectType component.

Let me know if anything else is needed - the existing example is still valid (since it uses the Array of options).

apologies for the massive delay!

@Hypnosphi
Copy link
Member

Should we add a deprecation notice for old select usages?

@ndelangen
Copy link
Member

@psimyn Thanks for the hard work! Really appreciate the time and effort you've put in!

This is a good step overall to improve the knobs API!

I feel it's merge-able without the deprecation warning on select, but if you feel like adding it to this PR that's great!

Merge when ready IMHO

@psimyn
Copy link
Member Author

psimyn commented Jan 2, 2018

thanks @ndelangen & @Hypnosphi

I'll add deprecate, but could use some help with wording. Currently have:

select: 'in v4 the options keys/values are being swapped'
selectV2: 'in v4 this will be renamed to select'

@ndelangen
Copy link
Member

@shilman You wanna pitch on on the deprecation messages?

@Hypnosphi
Copy link
Member

Hypnosphi commented Jan 15, 2018

select: 'in v4 the options keys/values are being swapped'
selectV2: 'in v4 this will be renamed to select'

The problem with this is that currently there is no way for a user to avoid getting warnings. Maybe we should add the latter warning only in 4.0, and remove selectV2 only in 5.0

@Hypnosphi
Copy link
Member

@kevinSuttle in your case, keys and values are the same string, so this PR shouldn't change anything for you.

Btw, you can use an array for that:

const buttonVariants = [
  "primary",
  "secondary",
  "negative",
  "alternate"
];

@psimyn
Copy link
Member Author

psimyn commented Jan 18, 2018

thanks @Hypnosphi - I didn't like always showing deprecation message. I've removed the v2 one

manager.knob(name, { type: 'select', options, value }),
'in v4 keys/values of the options argument are reversed'
);
}
Copy link
Member

Choose a reason for hiding this comment

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

For some reason, it throws in unit tests:

TypeError: Object prototype may only be an Object or null: apple
        at Function.setPrototypeOf (<anonymous>)

      74 | 
      75 | function select(name, options, value) {
    > 76 |   return (0, _utilDeprecate2.default)(manager.knob(name, { type: 'select', options: options, value: value }), 'in v4 keys/values of the options argument are reversed');
      77 | }
      78 | 
      79 | function selectV2(name, options, value) {
      
      at select (addons/knobs/dist/base.js:76:38)

https://circleci.com/gh/storybooks/storybook/33655?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

Copy link
Member Author

Choose a reason for hiding this comment

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

I was doing it wrong :)

fixed this up and added selectV2 example

Copy link
Member

@Hypnosphi Hypnosphi left a comment

Choose a reason for hiding this comment

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

Please add some selectV2 usages to examles/official-storybook

@ndelangen
Copy link
Member

Perfect @psimyn This is good to go IMHO 👍

@ndelangen
Copy link
Member

Is there something we're doing wrong that is causing the deprecation message to appear multiple times?

screen shot 2018-01-31 at 22 06 18

manager.knob.bind(manager),
'in v4 keys/values of the options argument are reversed'
)(name, { type: 'select', options, value });
}
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be rewritten as follows:

export const select = deprecate(
  (name, options, value) => manager.knob(name, { type: 'select', options, value }),
  'in v4 keys/values of the options argument are reversed'
);

See #1745 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks! I was missing the arrow function before and passing the result of manager.knob 🤦

@psimyn
Copy link
Member Author

psimyn commented Jan 31, 2018

thanks @ndelangen & @Hypnosphi

multiple warnings was due to me deprecating incorrectly. Fixed up now 👍

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.

None yet

5 participants