-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow same day input when minimumNights={0}
#555
Conversation
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, this looks great overall!
@@ -41,6 +42,7 @@ const propTypes = forbidExtraProps({ | |||
keepOpenOnDateSelect: PropTypes.bool, | |||
reopenPickerOnClearDates: PropTypes.bool, | |||
withFullScreenPortal: PropTypes.bool, | |||
minimumNights: PropTypes.number, |
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 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} />); |
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 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} />
));
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.
+1, on a related note, wondering if there are plans to add anything like Prettier to the code base?
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.
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]; |
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.
const [{ startDate, endDate }] = onDatesChangeStub.getCall(0).args;
onDatesChange={onDatesChangeStub} | ||
endDate={endDate} | ||
minimumNights={1} | ||
/>); |
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.
similarly, since the opening (
ends a line, the closing )
should start a line.
const wrapper = | ||
shallow(<DateRangePickerInputController onFocusChange={onFocusChangeStub} />); | ||
const wrapper = shallow( | ||
<DateRangePickerInputController onFocusChange={onFocusChangeStub} />, |
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.
@ljharb putting a trailing comma seems like the more consistent pattern in the codebase vs. double parens, does this look right to you? Thanks!
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, 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.
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.
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))); |
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 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?
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.
+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!
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.
Hey! Wondering if there's anything else I can do WRT this PR? Thanks!
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 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
c03e69d
to
f2b572c
Compare
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.
LGTM; deferring to @majapw
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 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.
Sounds good, made the change (though I used |
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.
LGTM!
Fixes #353.