-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Bugfix closing the datepicker should cancel the ongoing selection 1836 #1856
Merged
DorianDeptuch
merged 6 commits into
hackforla:main
from
DorianDeptuch:bugfix-closing-the-datepicker-should-cancel-the-ongoing-selection-1836
Nov 26, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb254e3
Add initialStartDate to DatePicker.jsx
DorianDeptuch a6f2b40
Updated imports to DatePicker.jsx
DorianDeptuch 7780f09
removed redux imports from ReactDayPicker.jsx
DorianDeptuch 4f9f1aa
Merge branch 'main' into bugfix-closing-the-datepicker-should-cancel-…
DorianDeptuch b25884e
Updated comments, fixed closeCalendar dependency array
DorianDeptuch 14db20a
Added spaces after 'if' and after the start of the comments
DorianDeptuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,6 @@ import DayPicker from 'react-day-picker'; | |
import { connect } from 'react-redux'; | ||
import makeStyles from '@mui/styles/makeStyles'; | ||
import clsx from 'clsx'; | ||
import { | ||
updateEndDate as reduxUpdateEndDate, | ||
updateStartDate as reduxUpdateStartDate, | ||
} from '@reducers/filters'; | ||
|
||
import fonts from '@theme/fonts'; | ||
import colors from '@theme/colors'; | ||
import { INTERNAL_DATE_SPEC } from '../CONSTANTS'; | ||
|
@@ -175,13 +170,16 @@ function ReactDayPicker({ | |
setFromDay(day); | ||
return; | ||
} | ||
|
||
// Our date range selection logic is very simple: the user is selecting the | ||
// first day in their date range if from and to are set, or if they're both | ||
// unset. Otherwise, they are selecting the last day. | ||
if (!(startDate && endDate)) { | ||
// If the user picks the first date then picks the second date that is before the first date | ||
// Reassign the From and To Day | ||
|
||
//If both startDate and endDate were already selected. Start a new range selection. | ||
if(startDate && endDate){ | ||
setFromDay(day); | ||
updateEndDate(null); | ||
setEnteredTo(null); | ||
//If startDate is selected and endDate is unselected, complete the range selection. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: for comments, add space between |
||
} else if(startDate && !endDate){ | ||
// If the user selects the startDate then chooses an endDate that precedes it, | ||
// swap the values of startDate and endDate | ||
if (moment(day).format(INTERNAL_DATE_SPEC) < startDate) { | ||
const tempDate = startDate; | ||
setToDay(moment(tempDate).toDate()); | ||
|
@@ -191,11 +189,10 @@ function ReactDayPicker({ | |
} else { | ||
setToDay(day); | ||
} | ||
return; | ||
} | ||
setFromDay(day); | ||
updateEndDate(null); | ||
setEnteredTo(null); | ||
} else { | ||
//This should never happen. Log a warning. | ||
console.warn('Try to set a new date selection. Dates were in an invalid state. StartDate: ', startDate, " endDate: ", endDate); | ||
} | ||
}; | ||
|
||
const handleDayMouseEnter = day => { | ||
|
@@ -248,14 +245,9 @@ ReactDayPicker.defaultProps = { | |
endDate: null, | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
updateStartDate: date => dispatch(reduxUpdateStartDate(date)), | ||
updateEndDate: date => dispatch(reduxUpdateEndDate(date)), | ||
}); | ||
|
||
const mapStateToProps = state => ({ | ||
startDate: state.filters.startDate, | ||
endDate: state.filters.endDate, | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(ReactDayPicker); | ||
export default connect(mapStateToProps)(ReactDayPicker); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: add space after
if
(lines 175 and 180)