Allow same day input when minimumNights={0}#555
Conversation
ljharb
left a comment
There was a problem hiding this comment.
Thanks, this looks great overall!
| keepOpenOnDateSelect: PropTypes.bool, | ||
| reopenPickerOnClearDates: PropTypes.bool, | ||
| withFullScreenPortal: PropTypes.bool, | ||
| minimumNights: PropTypes.number, |
There was a problem hiding this comment.
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.
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.
+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.
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.
const [{ startDate, endDate }] = onDatesChangeStub.getCall(0).args;
| onDatesChange={onDatesChangeStub} | ||
| endDate={endDate} | ||
| minimumNights={1} | ||
| />); |
There was a problem hiding this comment.
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.
@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.
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.
majapw
left a comment
There was a problem hiding this comment.
Looking good! One quick Q
| const isEndDateValid = endDate && !isOutsideRange(endDate) && | ||
| !isInclusivelyBeforeDay(endDate, startDate); | ||
| (!isInclusivelyBeforeDay(endDate, startDate) || | ||
| (minimumNights === 0 && isSameDay(endDate, startDate))); |
There was a problem hiding this comment.
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.
+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.
Hey! Wondering if there's anything else I can do WRT this PR? Thanks!
There was a problem hiding this comment.
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
majapw
left a comment
There was a problem hiding this comment.
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 |
Fixes #353.