-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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? |
54c09a8
to
7801d5a
Compare
@danielduan I've updated addons README (and rebased on latest Not sure about adding to kitchen-sink examples, since for users it is identical to existing |
addons/knobs/README.md
Outdated
}; | ||
const defaultValue = 'Red'; | ||
|
||
const value = select(label, options, defaultValue); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
@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? |
7801d5a
to
81deff8
Compare
fixes #799 add selectV2 for backwards compatibility
993f872
to
a12d5c5
Compare
@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! |
Should we add a deprecation notice for old |
@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 Merge when ready IMHO |
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' |
@shilman You wanna pitch on on the deprecation messages? |
…k into select-knob-ordering
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 |
@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:
|
thanks @Hypnosphi - I didn't like always showing deprecation message. I've removed the v2 one |
addons/knobs/src/base.js
Outdated
manager.knob(name, { type: 'select', options, value }), | ||
'in v4 keys/values of the options argument are reversed' | ||
); | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this 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
…k into select-knob-ordering
Perfect @psimyn This is good to go IMHO 👍 |
addons/knobs/src/base.js
Outdated
manager.knob.bind(manager), | ||
'in v4 keys/values of the options argument are reversed' | ||
)(name, { type: 'select', options, value }); | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
🤦
…k into select-knob-ordering
thanks @ndelangen & @Hypnosphi multiple warnings was due to me deprecating incorrectly. Fixed up now 👍 |
continued from #1449
fixes #799
Issue:
Using knobs is currently confusing.
Example, for complex strings and null values
What I did
Use value as value
Still uses key for the key property on each
<option>
How to test
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