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

Allow same day input when minimumNights={0} #555

Conversation

timhwang21
Copy link
Collaborator

Fixes #353.

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.

Thanks, this looks great overall!

@@ -41,6 +42,7 @@ const propTypes = forbidExtraProps({
keepOpenOnDateSelect: PropTypes.bool,
reopenPickerOnClearDates: PropTypes.bool,
withFullScreenPortal: PropTypes.bool,
minimumNights: PropTypes.number,
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 a non-negative integer (nonNegativeInteger from airbnb-prop-types), not just a number

it('calls props.onDatesChange with provided end date', () => {
const onDatesChangeStub = sinon.stub();
const wrapper =
shallow(<DateRangePickerInputController onDatesChange={onDatesChangeStub} />);
Copy link
Member

Choose a reason for hiding this comment

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

please don't add line breaks after assignments (same throughout, even if that was already in the file); if this is too long, let's indent like so:

const wrapper = shallow((
  <DateRangePickerInputController onDatesChange={onDatesChangeStub} />
));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1, on a related note, wondering if there are plans to add anything like Prettier to the code base?

Copy link
Member

Choose a reason for hiding this comment

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

Definitely not; if there's anything eslint doesn't do, let's make eslint better. I'm not yet aware of anything prettier is theoretically capable of that eslint theoretically isn't :-)

wrapper.instance().onEndDateChange(validFutureDateString);
expect(onDatesChangeStub.callCount).to.equal(1);

const onDatesChangeArgs = onDatesChangeStub.getCall(0).args[0];
Copy link
Member

Choose a reason for hiding this comment

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

const [{ startDate, endDate }] = onDatesChangeStub.getCall(0).args;

onDatesChange={onDatesChangeStub}
endDate={endDate}
minimumNights={1}
/>);
Copy link
Member

Choose a reason for hiding this comment

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

similarly, since the opening ( ends a line, the closing ) should start a line.

@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 Jun 12, 2017
const wrapper =
shallow(<DateRangePickerInputController onFocusChange={onFocusChangeStub} />);
const wrapper = shallow(
<DateRangePickerInputController onFocusChange={onFocusChangeStub} />,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ljharb putting a trailing comma seems like the more consistent pattern in the codebase vs. double parens, does this look right to you? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

yes, either one's totally fine :-)

unfortunately comma-dangle for functions doesn't have an exception for "1-arg jsx", which is the one case it looks weird.

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.

Looking good! One quick Q

keepOpenOnDateSelect,
onDatesChange,
} = this.props;

const endDate = toMomentObject(endDateString, this.getDisplayFormat());

const isEndDateValid = endDate && !isOutsideRange(endDate) &&
!isInclusivelyBeforeDay(endDate, startDate);
(!isInclusivelyBeforeDay(endDate, startDate) ||
(minimumNights === 0 && isSameDay(endDate, startDate)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit of a nit, but could we change this to:

(
  !isInclusivelyBeforeDay(endDate, startDate) ||
  (minimumNights === 0 && isSameDay(endDate, startDate))
);

Also, I feel like it's a bit weird that we don't check for minimum nights requirements in other scenarios. Maybe this should just be:

 isInclusivelyAfterDay(endDate, startDate + minimumNights)

Would that work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 to the first part, and ah yeah, I see how the Inclusively functions work now, should have taken a closer look -- !isInclusivelyBeforeDay() is equivalent to isAfterDay() so yeah, makes sense to me. Though we'd have to do startDate.clone().add(minimumNights, 'days'). Do you think it's worth the clone?

Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey! Wondering if there's anything else I can do WRT this PR? Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is worth the clone in this scenario. Let's change it to be isInclusivelyAfterDay(endDate, startDate + minimumNights).

* Proptypes.number => nonNegativeInteger
* Fix no linebreak after assignment
* Fix training parentheses not having linebreak when leading parentheses does
@timhwang21 timhwang21 force-pushed the timhwang21/353-manual-input-breaks-for-same-day branch from c03e69d to f2b572c Compare June 30, 2017 01:46
@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.13% when pulling f2b572c on timhwang21:timhwang21/353-manual-input-breaks-for-same-day into c96a237 on airbnb:master.

ljharb
ljharb previously approved these changes Jun 30, 2017
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; deferring to @majapw

majapw
majapw previously approved these changes Jun 30, 2017
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.

This seems legit to me. I'd prefer the isInclusivelyAfterDay(endDate, startDate + minimumNights) call for the clarity of code, despite the cloning required. It doesn't get called too much so i think it should be okay!

Used `isBeforeDay` instead of `isInclusivelyAfterDay` because to clone, a null check is needed for `startDate`. And when doing the same, reversed check in `onStartDateChange()` the double negative `!` looks bad.
@timhwang21 timhwang21 dismissed stale reviews from majapw and ljharb via be4ef1e June 30, 2017 22:02
@timhwang21
Copy link
Collaborator Author

Sounds good, made the change (though I used isBeforeDay to make the boolean logic less ugly)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.266% when pulling 312216b on timhwang21:timhwang21/353-manual-input-breaks-for-same-day into c384dc1 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.266% when pulling 312216b on timhwang21:timhwang21/353-manual-input-breaks-for-same-day into c384dc1 on airbnb:master.

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.

LGTM!

@majapw majapw merged commit 19a10f7 into react-dates:master Jul 14, 2017
@timhwang21 timhwang21 deleted the timhwang21/353-manual-input-breaks-for-same-day branch July 14, 2017 22:32
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.

4 participants