-
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
[DateRangePicker] support time selection #2895
Merged
giladgray
merged 14 commits into
palantir:develop
from
Sam-Kramer:sk/date_range_picker_time_select
Sep 7, 2018
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3737105
add time selection unit tests
2504efd
add maybeRender placeholder
eb7a450
add wrapper div for calendars + time
8d3a43d
add time precision to DRP example
9139a8d
reorder function
0c4a828
Merge branch 'develop' into feature/daterangepicker-time
2646517
DateRangePicker now has time selection field
6059acf
Updated DateRangePicker example to show time when precision is selected
463c8c5
Updated props to include timePickerProps and fixed/cleaned up tests f…
df7e57b
renamed timepicker classes appropiately, and code cleanup
3336faf
updated momentTime to pass props
efb8d4e
clicking on a shortcut doesn't change the time
ed30278
removed only from describe in tests
b153572
removed unneeded CSS property and added test for making sure that tim…
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ import DateRange = DateUtils.DateRange; | |
|
||
import * as Errors from "./common/errors"; | ||
import { MonthAndYear } from "./common/monthAndYear"; | ||
|
||
import { DatePickerCaption } from "./datePickerCaption"; | ||
import { | ||
combineModifiers, | ||
|
@@ -31,6 +30,7 @@ import { | |
import { DatePickerNavbar } from "./datePickerNavbar"; | ||
import { DateRangeSelectionStrategy } from "./dateRangeSelectionStrategy"; | ||
import { Shortcuts } from "./shortcuts"; | ||
import { TimePicker } from "./timePicker"; | ||
|
||
export interface IDateRangeShortcut { | ||
label: string; | ||
|
@@ -113,6 +113,7 @@ export interface IDateRangePickerState { | |
leftView?: MonthAndYear; | ||
rightView?: MonthAndYear; | ||
value?: DateRange; | ||
time?: DateRange; | ||
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. my final question is... can this feature be implemented without adding this |
||
} | ||
|
||
export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps, IDateRangePickerState> { | ||
|
@@ -124,6 +125,7 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps | |
minDate: getDefaultMinDate(), | ||
reverseMonthAndYearMenus: false, | ||
shortcuts: true, | ||
timePickerProps: {}, | ||
}; | ||
|
||
public static displayName = `${DISPLAYNAME_PREFIX}.DateRangePicker`; | ||
|
@@ -166,6 +168,7 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps | |
public constructor(props: IDateRangePickerProps, context?: any) { | ||
super(props, context); | ||
const value = getInitialValue(props); | ||
const time: DateRange = value; | ||
const initialMonth = getInitialMonth(props, value); | ||
|
||
// if the initial month is the last month of the picker's | ||
|
@@ -187,7 +190,7 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps | |
!props.contiguousCalendarMonths && rightDate != null && !DateUtils.areSameMonth(initialMonth, rightDate) | ||
? MonthAndYear.fromDate(rightDate) | ||
: leftView.getNextMonth(); | ||
this.state = { leftView, rightView, value, hoverValue: [null, null] }; | ||
this.state = { leftView, rightView, value, hoverValue: [null, null], time }; | ||
} | ||
|
||
public render() { | ||
|
@@ -203,7 +206,10 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps | |
return ( | ||
<div className={classes}> | ||
{this.maybeRenderShortcuts()} | ||
{this.renderCalendars(isShowingOneMonth)} | ||
<div> | ||
{this.renderCalendars(isShowingOneMonth)} | ||
{this.maybeRenderTimePickers()} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
@@ -272,6 +278,52 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps | |
]; | ||
} | ||
|
||
private maybeRenderTimePickers() { | ||
const { timePrecision, timePickerProps } = this.props; | ||
if (timePrecision == null && timePickerProps === DateRangePicker.defaultProps.timePickerProps) { | ||
return null; | ||
} | ||
return ( | ||
<div className={DateClasses.DATERANGEPICKER_TIMEPICKERS}> | ||
<TimePicker | ||
precision={timePrecision} | ||
{...timePickerProps} | ||
onChange={this.handleTimeChangeLeftCalendar} | ||
value={this.state.time[0]} | ||
/> | ||
<TimePicker | ||
precision={timePrecision} | ||
{...timePickerProps} | ||
onChange={this.handleTimeChangeRightCalendar} | ||
value={this.state.time[1]} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
private handleTimeChange = (newTime: Date, dateIndex: number) => { | ||
Utils.safeInvoke(this.props.timePickerProps.onChange, newTime); | ||
const { value, time } = this.state; | ||
const newValue = DateUtils.getDateTime( | ||
value[dateIndex] != null ? DateUtils.clone(value[dateIndex]) : new Date(), | ||
newTime, | ||
); | ||
const newDateRange: DateRange = [value[0], value[1]]; | ||
newDateRange[dateIndex] = newValue; | ||
const newTimeRange: DateRange = [time[0], time[1]]; | ||
newTimeRange[dateIndex] = newTime; | ||
Utils.safeInvoke(this.props.onChange, newDateRange); | ||
this.setState({ value: newDateRange, time: newTimeRange }); | ||
}; | ||
|
||
private handleTimeChangeLeftCalendar = (time: Date) => { | ||
this.handleTimeChange(time, 0); | ||
}; | ||
|
||
private handleTimeChangeRightCalendar = (time: Date) => { | ||
this.handleTimeChange(time, 1); | ||
}; | ||
|
||
private renderCalendars(isShowingOneMonth: boolean) { | ||
const { contiguousCalendarMonths, dayPickerProps, locale, localeUtils, maxDate, minDate } = this.props; | ||
const dayPickerBaseProps: DayPickerProps = { | ||
|
@@ -417,12 +469,14 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps | |
|
||
private handleNextState = (nextValue: DateRange) => { | ||
const { value } = this.state; | ||
nextValue[0] = DateUtils.getDateTime(nextValue[0], this.state.time[0]); | ||
nextValue[1] = DateUtils.getDateTime(nextValue[1], this.state.time[1]); | ||
|
||
const nextState = getStateChange(value, nextValue, this.state, this.props.contiguousCalendarMonths); | ||
|
||
if (this.props.value == null) { | ||
this.setState(nextState); | ||
} | ||
|
||
Utils.safeInvoke(this.props.onChange, nextValue); | ||
}; | ||
|
||
|
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
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.
@Sam-Kramer why did you add this property? it has no effect since we don't use floats.