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

Add type check to PropType on OneOf #2653

Merged
merged 8 commits into from
Feb 7, 2018
Merged

Add type check to PropType on OneOf #2653

merged 8 commits into from
Feb 7, 2018

Conversation

theAbeGonzalez
Copy link
Contributor

@theAbeGonzalez theAbeGonzalez commented Jan 5, 2018

Issue: #2652

What I did

Added a type check to PropType prop on OneOf component.

How to test

Add a story with at component that has a oneOf prop with an evaluation in the propType declaration.
See issue for further information.

Is this testable with jest or storyshots?
No

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

Does this need an update to the documentation?
No

@Hypnosphi Hypnosphi added addon: info bug patch:yes Bugfix & documentation PR that need to be picked to main branch labels Jan 5, 2018
@codecov
Copy link

codecov bot commented Jan 5, 2018

Codecov Report

Merging #2653 into master will decrease coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2653      +/-   ##
==========================================
- Coverage   37.38%   37.38%   -0.01%     
==========================================
  Files         426      426              
  Lines        9150     9153       +3     
  Branches      869      882      +13     
==========================================
+ Hits         3421     3422       +1     
+ Misses       5226     5182      -44     
- Partials      503      549      +46
Impacted Files Coverage Δ
addons/info/src/components/types/OneOf.js 61.11% <80%> (-5.56%) ⬇️
app/react/src/server/config/babel.js 0% <0%> (-100%) ⬇️
lib/ui/src/modules/ui/libs/hierarchy.js 49.03% <0%> (ø) ⬆️
addons/knobs/src/angular/utils.js 82.14% <0%> (ø) ⬆️
lib/core/src/client/manager/preview.js 0% <0%> (ø) ⬆️
addons/jest/src/components/Indicator.js 0% <0%> (ø) ⬆️
addons/a11y/src/components/Report/Tags.js 0% <0%> (ø) ⬆️
lib/codemod/src/transforms/update-addon-info.js 50% <0%> (ø) ⬆️
lib/ui/src/modules/api/actions/api.js 51.85% <0%> (ø) ⬆️
... and 55 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 0d04a79...149160c. Read the comment docs.

@@ -1,7 +1,13 @@
import React from 'react';
import { TypeInfo } from './proptypes';

const OneOf = ({ propType }) => <span>{propType.value.map(({ value }) => value).join(' | ')}</span>;
const isObject = propType => typeof propType.value === 'object';
Copy link
Member

Choose a reason for hiding this comment

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

Should it rather check that propType.value is an array, as we're using an array method?

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'm not sure why the typeof propType.value returns object when array. Better to change to Array.isArray()

Copy link
Member

Choose a reason for hiding this comment

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

why the typeof propType.value returns object when array

Because array is an object =)

@Hypnosphi
Copy link
Member

@theAbeGonzalez
Copy link
Contributor Author

theAbeGonzalez commented Jan 5, 2018

@Hypnosphi
Somehing like:

  /**
   * `oneOf` is basically an Enum which is also supported but can be pretty big.
   */
  enm: PropTypes.oneOf(['News', 'Photos']),
  enmEval: PropTypes.oneOf(() => (['News', 'Photos'])()),

?

@Hypnosphi
Copy link
Member

Yes, that would do it

@Hypnosphi
Copy link
Member

You might need to update snapshots of example stories by running yarn test --core --update

@theAbeGonzalez
Copy link
Contributor Author

@Hypnosphi snapshots updated

@@ -19,7 +19,7 @@ exports[`Storyshots Addons|Knobs.withKnobs tweaks static values 1`] = `
My name is Storyteller, I'm 70 years old, and my favorite fruit is apple.
</p>
<p>
My birthday is: January 20, 2017
My birthday is: January 19, 2017
Copy link
Member

Choose a reason for hiding this comment

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

@tmeasday looks like your fix don't work in some cases

Copy link
Member

Choose a reason for hiding this comment

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

@abrahamgnz just for reference, which timezone are you in?

Copy link
Member

Choose a reason for hiding this comment

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

This is puzzling ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@tmeasday tmeasday Jan 8, 2018

Choose a reason for hiding this comment

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

@abrahamgnz it would be interesting to know what the following output in the node REPL for you:

new Date('Jan 20 2017 GMT+0').toLocaleDateString('en-US')

Copy link
Contributor Author

@theAbeGonzalez theAbeGonzalez Jan 8, 2018

Choose a reason for hiding this comment

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

+new Date('Jan 20 2017 GMT+0')
1484870400000

@tmeasday
I got the same

Copy link
Member

@Hypnosphi Hypnosphi Jan 8, 2018

Choose a reason for hiding this comment

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

@tmeasday looks like we have to add timeZone: 'UTC' to dateOptions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
en-US is a format not a timezone

the default is the runtime's default time zone

The midnight in London is definitely the same day in Netherlands, Russia, Israel, India, and Australia, that's why it worked for most of the core contributors =)

Copy link
Member

Choose a reason for hiding this comment

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

I can't believe no-one in the US ran into this yet... not even the CI servers!

I can't really explain why it was printing out the 19th in the first place for me then (given new Date('Jan 20 2017') was midnight 20 Jan in my TZ). But let's lock it down.

Copy link
Member

Choose a reason for hiding this comment

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

how?

Copy link
Member

Choose a reason for hiding this comment

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

This was probably fixed in #2861

@abrahamgnz can you please try to update snapshots once again?

@Hypnosphi Hypnosphi merged commit 1405711 into storybookjs:master Feb 7, 2018
shilman pushed a commit that referenced this pull request Feb 21, 2018
Add type check to PropType on OneOf
@Hypnosphi Hypnosphi added patch:done Patch/release PRs already cherry-picked to main/release branch and removed patch:done Patch/release PRs already cherry-picked to main/release branch labels Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: info bug patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants