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 initialVisibleMonth fn prop to DayPicker #70

Merged
merged 1 commit into from
Oct 10, 2016

Conversation

travisbloom
Copy link
Contributor

@travisbloom travisbloom commented Sep 9, 2016

Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker
that passes a fn to DayPicker. On the initial focus, that fn will be called
and set the initial month to the returned moment object.

solves issue #17

@@ -260,6 +261,20 @@ describe('DayPicker', () => {
});
});

describe('#componentWillReceiveProps', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test can't run currently because of https://github.com/airbnb/react-dates/blob/master/test/components/DayPicker_spec.jsx#L225

Is there an open issue/discussion for how to solve? getting It looks like you calledmount()without a global document being loaded. when i remove skip

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, at Airbnb we use jsdom afaict and mocha-wrap (https://github.com/ljharb/mocha-wrap) plugin, but I think there was some discussion on what we plan to do for our open-source repos. @ljharb do you have thoughts on getting enzym's mount to work in this repo? I haven't really thought about it, but we should really open an issue I guess.

Copy link
Member

Choose a reason for hiding this comment

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

In order to do that, we'd need to run the test suite twice - once with jsdom, and once without it - and be able to mark tests that require the DOM such that they'd be skipped when running without jsdom.

I don't yet have a clean solution for this; i think it's OK to skip those tests for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah let's skip them.

@travisbloom
Copy link
Contributor Author

@ljharb fixes added, let me know if you have more insight into the It looks like you called mount() without a global document being loaded issue

@travisbloom
Copy link
Contributor Author

also the linter is failing because of https://github.com/airbnb/react-dates/pull/70/files#diff-883056b4b11263241c339f927e93411bR75

the issue is that if I make it one line I get exceeds max length of 100 lint error.

Is the expected style below?

const triggerInitialVisibleMonth = (props) => 
  props.hidden ? moment() : 
  props.initialVisibleMonth();

@ljharb
Copy link
Member

ljharb commented Sep 9, 2016

const triggerInitialVisibleMonth = ({ hidden, initialVisibleMonth }) => (
  hidden ? moment() : initialVisibleMonth()
);

@travisbloom
Copy link
Contributor Author

@ljharb whoops, totally spaced on that, good call :)

@travisbloom
Copy link
Contributor Author

Any reason the tests that are failing wouldn't be running/failing on my local machine?

@ljharb
Copy link
Member

ljharb commented Sep 14, 2016

@travisbloom yes - rebase on latest master; one of the dependencies had to be locked down to avoid a bug.

@@ -68,11 +72,17 @@ const defaultProps = {
monthFormat: 'MMMM YYYY',
};

const triggerInitialVisibleMonth = (props) => (
props.hidden ? moment() : props.initialVisibleMonth()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that we need this logic to be perfectly honest. The constructor is only called once and even if the datepicker is visible at that point, it will be the first time its ever rendered so I think we can just set state.currentMonth to props.initialVisibleMonth(). What is the edge case this is trying to solve?

Copy link
Collaborator

@majapw majapw Sep 29, 2016

Choose a reason for hiding this comment

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

Can we pull this as an instance method onto the class, named as getInitialVisibleMonth or something? That way we just have access to the props straight up.

Actually we don't even call this more than once. Why don't we just have this logic directly in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ljharb asked for it to be broken out in to a seperate function in case we need the logic elsewhere, not 100% where that would be.

@majapw let me know which you prefer, getting conflicting suggestions :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sorry about that! I think if it's only used once, we should not pull it out. :) Let's go with that.

Copy link
Member

Choose a reason for hiding this comment

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

Since it's used in two separate components, my hope was that we'd define it in one place and import it in both.

export default class DayPicker extends React.Component {
constructor(props) {
super(props);

this.hasSetInitialVisibleMonth = !props.hidden;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly I don't think we need the hasSetInitialVisibleMonth logic either.

@majapw
Copy link
Collaborator

majapw commented Sep 15, 2016

Hey @travisbloom, this is looking good, but I'm a bit confused about the constructor logic you've included.

@ljharb ljharb mentioned this pull request Sep 16, 2016
@travisbloom
Copy link
Contributor Author

@majapw my understanding was we only want initialVisibleMonth fn to trigger once, when the calendar opens initially. The constructor logic ensures that the fn will be called on mount, or if the component is not focused yet, it will call the first time the nextProps has focused === true...

Now that I think about it, it would prob be better to trigger it every time it opens...is that the expected behavior you were thinking?

@travisbloom
Copy link
Contributor Author

if thats the case, I'd propose changing initialVisibleMonth to visibleMonthOnFocus

@majapw majapw added the needs rebase Please rebase your branch onto latest master! This removes merge commits, & keeps the git log clean. label Sep 26, 2016
@majapw
Copy link
Collaborator

majapw commented Sep 26, 2016

Hmm, let me review again with that in mind. I guess the initialVisibleMonth does make sense... I was just misunderstanding the implementation I am pretty sure.

We can maybe augment it in the future to do kind of a fully controlled visibleMonthOnFocus situation, but for now I think this is sufficient.

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

Hi @travisbloom, sorry for the long delay in getting this out the door. Let's leave the implementation as is, but address the small nits in this review. After that I'm happy to merge this in ASAP. :)

@@ -361,6 +364,8 @@ export default class DateRangePicker extends React.Component {
onNextMonthClick={onNextMonthClick}
monthFormat={monthFormat}
withPortal={withPortal || withFullScreenPortal}
hidden={!focusedInput}
Copy link
Collaborator

@majapw majapw Sep 29, 2016

Choose a reason for hiding this comment

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

Can we change this name to isVisible instead of hidden? I think that is more in line with the other nomenclature in these files.

I think once we move to react-with-styles, we hopefully won't need this anyways. since the component will be unmounted/remounted every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:( unfortunately I had it named as visible before but @ljharb asked to change it to be hidden so we didn't have a boolean prop that defaulted to true.

Let me know what you would prefer now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Man, I should really have read @ljharb's comments more carefully before. :) hidden sounds good to me

@@ -68,11 +72,17 @@ const defaultProps = {
monthFormat: 'MMMM YYYY',
};

const triggerInitialVisibleMonth = (props) => (
props.hidden ? moment() : props.initialVisibleMonth()
Copy link
Collaborator

@majapw majapw Sep 29, 2016

Choose a reason for hiding this comment

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

Can we pull this as an instance method onto the class, named as getInitialVisibleMonth or something? That way we just have access to the props straight up.

Actually we don't even call this more than once. Why don't we just have this logic directly in the constructor?

@@ -204,6 +208,8 @@ export default class SingleDatePicker extends React.Component {
onNextMonthClick={onNextMonthClick}
monthFormat={monthFormat}
withPortal={withPortal || withFullScreenPortal}
hidden={!focused}
Copy link
Collaborator

Choose a reason for hiding this comment

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

same, let's name this as isVisible

@majapw
Copy link
Collaborator

majapw commented Sep 29, 2016

We'll also need to rebase before getting this out! :D Thanks so much @travisbloom

@travisbloom
Copy link
Contributor Author

@majapw @ljharb a lot of back and forth on what changes should be made :) rebased and made the requested fixes, let me know if thats inline with what we ended up wanting to do.

Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker
that passes a fn to DayPicker. On the initial focus, that fn will be called
and set the initial month to the returned moment object.

solves issue react-dates#17
@@ -11,6 +11,6 @@ instrumentation:
check:
global:
statements: 89
branches: 70
branches: 69
Copy link
Contributor Author

Choose a reason for hiding this comment

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

inline with #70 (comment), updating coverage requirements

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 87.893% when pulling bff83ef on rocketrip:master into 8c03d77 on airbnb:master.

@majapw
Copy link
Collaborator

majapw commented Oct 10, 2016

Great! Thank you for all of this @travisbloom.

@majapw majapw removed the needs rebase Please rebase your branch onto latest master! This removes merge commits, & keeps the git log clean. label Oct 10, 2016
@majapw majapw merged commit 7d2e0d4 into react-dates:master Oct 10, 2016
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants