-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
ππ Fix and Enhance Date Range Selection #4306
Conversation
- Add logic to disallow the selection of an end date before the start date and vice versa in the date range picker. - Temporarily disable linter rules in tests due to React 18 updates and
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 pull request was sent to the PullRequest network.
@frankops11 you can click here to see the review status or cancel the code review job.
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.
PullRequest Breakdown
Reviewable lines of change
+ 27
- 1
93% JavaScript
7% JavaScript (tests)
Type of change
Fix - These changes are likely to be fixing a bug or issue.
Codecov Report
@@ Coverage Diff @@
## main #4306 +/- ##
==========================================
- Coverage 96.54% 96.18% -0.37%
==========================================
Files 27 27
Lines 2374 2384 +10
Branches 966 974 +8
==========================================
+ Hits 2292 2293 +1
- Misses 82 91 +9
|
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 have a concern left inline r.e. the catch block. We're also missing test coverage for the changes here.
Reviewed with β€οΈ by PullRequest
src/index.jsx
Outdated
this.setState({ inputValue: null }); | ||
} | ||
} catch (error) { | ||
console.log(error); |
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.
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.
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.
π Hello everyone!
I would like to provide some clarifications regarding the use of the try...catch
block in the previously shared code. πββοΈ
Initially, I introduced this block in an attempt to pinpoint the invalid date issue that I was grappling with during the debugging phase. The idea was to ensure that, if any related error emerged, I could rapidly identify its origin. π΅οΈββοΈ
However, upon further review and additional testing, I was able to verify that that particular section of the code was not the root cause of the issue at hand, thus rendering the try...catch
not only unnecessary but also disruptive to code fluidity and readability. π§ͺπ
Consequently, I have now removed this block from the code to preserve clarity and prevent confusion in future reviews. π§Ήβ¨
I greatly appreciate your attention and sharp observation. Any feedback is always valuable! Moreover, have you had a chance to observe the error mentioned in the PR? Gaining insights from your impressions and awareness of this issue would be immensely helpful. π
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.
Graham has already left some good feedback inline. I had an additional concern about the broad try-catch block without a clear picture of what errors we'll actually encounter.
Reviewed with β€οΈ by PullRequest
Eliminate the try...catch block that was initially introduced for debugging the invalid date issue, but was determined not to be the root cause and therefore is not needed.
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.
We're still missing test coverage. I have another comment left inline, too.
Reviewed with β€οΈ by PullRequest
@@ -639,6 +646,23 @@ export default class DatePicker extends React.Component { | |||
this.setState({ monthSelectedIn: monthSelectedIn }); | |||
} | |||
} | |||
|
|||
if (selectsStart || selectsEnd) { |
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.
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.
Why? Could you explain me because are unnecessary?
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.
The level of nesting and use of else. One can replace lines 650-664 with:
if ((selectsStart || selectsEnd) && isValid(new Date(startDate)) && isValid(new Date(endDate))) {
if (isAfter(new Date(changedDate), new Date(endDate)) && selectsStart) {
return;
}
if (isBefore(new Date(changedDate), new Date(startDate)) && selectsEnd) {
return;
}
}
@@ -1,3 +1,4 @@ | |||
/* eslint-disable react/no-deprecated */ |
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.
Why is this needed?
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.
@martijnrusschen I wrote: Temporarily disable linter rules in tests due to React 18 updates
@@ -1,3 +1,4 @@ | |||
/* eslint-disable react/no-deprecated */ |
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.
Why is this needed?
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 agree that more tests could be added to capture the fix and new behavior. At a minimum a test for the original bug would be good to prevent future regressions.
Reviewed with β€οΈ by PullRequest
Steps to Reproduce π΅οΈββοΈ
Visit the documentation and date range selection example:
Navigate to the date range picker example in the documentation.
Observe the second input (for
endDate
):Note that the days prior to the date selected in the first input are disabled, which may not be the desired behavior in some use cases.
Select a start date (
startDate
) that is after the end date (endDate
):The invalid range is allowed, posing a usability concern as users can select a start date that is after their chosen end date, which might not be intuitive or may not validate against business logic.
π¨ Issue:
π Invalid Date Ranges: The component allows users to select invalid date ranges when using two inputs for range selection.
π« Days Becoming Incorrectly Disabled: Selecting certain date ranges results in days becoming incorrectly disabled in the UI.
π‘ Proposed Solutions:
π Prevent Invalid Range Selection: Implement logic to prevent the user from selecting an invalid date range by doing nothing (or potentially showing an error message) when they attempt to select an end date that is earlier than the start date and vice versa.
π Equalizing Start and End Dates: Introduce logic that sets the end date equal to the start date if the user attempts to set a start date that is later than the end date, and vice versa.
π Resetting the Opposite Input: If a user selects an invalid range, automatically reset the opposite input (reset end date if an invalid start date is selected, and vice versa).
β¨ Allow Invalid Ranges Prop: Introduce a new prop
allowInvalidRanges
, which enables developers to control whether invalid date ranges can be set by the user. Whentrue
, invalid ranges are allowed, potentially enabling developers to handle this case in a way that suits their application, such as displaying a custom error message.π Additional Notes:
π Tasks:
allowInvalidRanges
prop to provide additional flexibility for developers.π§ͺ Tests:
NOTE: Temporarily disable linter rules in tests due to React 18 updates