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

Fixes issues with displayFormat prop's default values by using a thunk #98

Merged
merged 1 commit into from
Sep 28, 2016

Conversation

majapw
Copy link
Collaborator

@majapw majapw commented Sep 27, 2016

to: @ljharb

When attempting to bump the version of react-dates used on Airbnb, we noticed that the display format for the DateRangePicker and SingleDatePicker components was often returning nonsense because moment's locale was not yet set. Similarly, live right now on the storybook, you can see that the format doesn't work at all for the non-english locale example. This fixes this issue.

@majapw majapw force-pushed the maja-set-moment-defaults-on-instantiation-not-import branch from 15201e2 to bd9f6d8 Compare September 27, 2016 18:32
@ljharb ljharb added semver-minor: new stuff Any feature or API addition. semver-patch: fixes/refactors/etc Anything that's not major or minor. labels Sep 27, 2016
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM but the comments might be some nice improvements

@@ -138,7 +138,9 @@ export default class DateRangePicker extends React.Component {

onEndDateChange(endDateString) {
const { startDate, isOutsideRange, onDatesChange, onFocusChange, displayFormat } = this.props;
const endDate = toMomentObject(endDateString, displayFormat);

const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat;
Copy link
Member

Choose a reason for hiding this comment

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

the propTypes help ensure it's only a string or function, but perhaps it would be more robust (ie, fail faster when it's not a func or string) if this did typeof displayFormat === 'string' ? displayFormat : displayFormat();?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay. I wasn't sure if it made more sense to have it fail abruptly in this way or fail silently, but still function, in the other. I can change it to the former.

Copy link
Member

Choose a reason for hiding this comment

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

i'm a big fan of failing fast and loud

@@ -175,7 +177,8 @@ export default class DateRangePicker extends React.Component {

onStartDateChange(startDateString) {
const { displayFormat } = this.props;
const startDate = toMomentObject(startDateString, displayFormat);
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat;
Copy link
Member

Choose a reason for hiding this comment

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

also here. should this logic be consolidated into a helper function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

@@ -203,8 +206,9 @@ export default class DateRangePicker extends React.Component {

getDateString(date) {
const { displayFormat } = this.props;
if (date && displayFormat) {
return date && date.format(displayFormat);
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat;
Copy link
Member

Choose a reason for hiding this comment

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

^_^

@@ -68,7 +68,8 @@ export default class SingleDatePicker extends React.Component {

onChange(dateString) {
const { displayFormat, isOutsideRange, onDateChange, onFocusChange } = this.props;
const date = toMomentObject(dateString, displayFormat);
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat;
Copy link
Member

Choose a reason for hiding this comment

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

ᕕ( ᐛ )ᕗ

@@ -114,8 +115,9 @@ export default class SingleDatePicker extends React.Component {

getDateString(date) {
const { displayFormat } = this.props;
if (date && displayFormat) {
return date && date.format(displayFormat);
const formatString = typeof displayFormat === 'function' ? displayFormat() : displayFormat;
Copy link
Member

Choose a reason for hiding this comment

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

there's a lot of these :-p

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lol

@majapw majapw force-pushed the maja-set-moment-defaults-on-instantiation-not-import branch from bd9f6d8 to cea7d28 Compare September 28, 2016 18:55
@majapw majapw merged commit d8628c6 into master Sep 28, 2016
@majapw majapw deleted the maja-set-moment-defaults-on-instantiation-not-import branch September 28, 2016 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor: new stuff Any feature or API addition. semver-patch: fixes/refactors/etc Anything that's not major or minor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants