|
@@ -6,6 +6,7 @@ import styled from 'react-emotion';
|
|
|
|
|
|
import {DEFAULT_STATS_PERIOD} from 'app/constants';
|
|
|
import {analytics} from 'app/utils/analytics';
|
|
|
+import {defined, parsePeriodToHours} from 'app/utils';
|
|
|
import {
|
|
|
getLocalToSystem,
|
|
|
getPeriodAgo,
|
|
@@ -13,7 +14,6 @@ import {
|
|
|
getUtcToSystem,
|
|
|
} from 'app/utils/dates';
|
|
|
import {getRelativeSummary} from 'app/components/organizations/timeRangeSelector/utils';
|
|
|
-import {parsePeriodToHours} from 'app/utils';
|
|
|
import {t} from 'app/locale';
|
|
|
import DateRange from 'app/components/organizations/timeRangeSelector/dateRange';
|
|
|
import DateSummary from 'app/components/organizations/timeRangeSelector/dateSummary';
|
|
@@ -105,7 +105,6 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
static defaultProps = {
|
|
|
showAbsolute: true,
|
|
|
showRelative: true,
|
|
|
- utc: getUserTimezone() === 'UTC',
|
|
|
};
|
|
|
|
|
|
static contextTypes = {
|
|
@@ -124,7 +123,9 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
}
|
|
|
|
|
|
this.state = {
|
|
|
- utc: props.utc,
|
|
|
+ // if utc is not null and not undefined, then use value of `props.utc` (it can be false)
|
|
|
+ // otherwise if no value is supplied, the default should be the user's timezone preference
|
|
|
+ utc: defined(props.utc) ? props.utc : getUserTimezone() === 'UTC',
|
|
|
isOpen: false,
|
|
|
hasChanges: false,
|
|
|
start,
|
|
@@ -188,8 +189,12 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
'hours'
|
|
|
).toDate(),
|
|
|
end: new Date(),
|
|
|
- utc: this.state.utc,
|
|
|
};
|
|
|
+
|
|
|
+ if (defined(this.props.utc)) {
|
|
|
+ newDateTime.utc = this.state.utc;
|
|
|
+ }
|
|
|
+
|
|
|
this.setState({
|
|
|
hasChanges: true,
|
|
|
...newDateTime,
|
|
@@ -205,7 +210,6 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
relative: value,
|
|
|
start: null,
|
|
|
end: null,
|
|
|
- utc: this.state.utc,
|
|
|
};
|
|
|
this.setState(newDateTime);
|
|
|
this.callCallback(onChange, newDateTime);
|
|
@@ -215,11 +219,12 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
handleClear = () => {
|
|
|
const {onChange} = this.props;
|
|
|
const newDateTime = {
|
|
|
- relative: DEFAULT_STATS_PERIOD,
|
|
|
+ relative: null,
|
|
|
start: null,
|
|
|
end: null,
|
|
|
- utc: this.state.utc,
|
|
|
+ utc: null,
|
|
|
};
|
|
|
+ this.setState(newDateTime);
|
|
|
this.callCallback(onChange, newDateTime);
|
|
|
this.handleUpdate(newDateTime);
|
|
|
};
|
|
@@ -231,8 +236,12 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
relative: null,
|
|
|
start,
|
|
|
end,
|
|
|
- utc: this.state.utc,
|
|
|
};
|
|
|
+
|
|
|
+ if (defined(this.props.utc)) {
|
|
|
+ newDateTime.utc = this.state.utc;
|
|
|
+ }
|
|
|
+
|
|
|
this.setState({hasChanges: true, ...newDateTime});
|
|
|
this.callCallback(onChange, newDateTime);
|
|
|
};
|
|
@@ -241,26 +250,27 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
const {onChange} = this.props;
|
|
|
let {start, end} = this.props;
|
|
|
|
|
|
- if (!start) {
|
|
|
- start = getDateWithTimezoneInUtc(this.state.start, this.props.utc);
|
|
|
- }
|
|
|
-
|
|
|
- if (!end) {
|
|
|
- end = getDateWithTimezoneInUtc(this.state.end, this.props.utc);
|
|
|
- }
|
|
|
-
|
|
|
this.setState(state => {
|
|
|
const utc = !state.utc;
|
|
|
|
|
|
+ if (!start) {
|
|
|
+ start = getDateWithTimezoneInUtc(state.start, state.utc);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!end) {
|
|
|
+ end = getDateWithTimezoneInUtc(state.end, state.utc);
|
|
|
+ }
|
|
|
+
|
|
|
analytics('dateselector.utc_changed', {
|
|
|
utc,
|
|
|
path: getRouteStringFromRoutes(this.context.router.routes),
|
|
|
org_id: parseInt(this.props.organization.id, 10),
|
|
|
});
|
|
|
+
|
|
|
const newDateTime = {
|
|
|
relative: null,
|
|
|
- start: this.props.utc ? getUtcToSystem(start) : getLocalToSystem(start),
|
|
|
- end: this.props.utc ? getUtcToSystem(end) : getLocalToSystem(end),
|
|
|
+ start: utc ? getLocalToSystem(start) : getUtcToSystem(start),
|
|
|
+ end: utc ? getLocalToSystem(end) : getUtcToSystem(end),
|
|
|
utc,
|
|
|
};
|
|
|
this.callCallback(onChange, newDateTime);
|
|
@@ -280,10 +290,10 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
const shouldShowRelative = showRelative;
|
|
|
const isAbsoluteSelected = !!start && !!end;
|
|
|
|
|
|
- const summary = relative ? (
|
|
|
- getRelativeSummary(relative)
|
|
|
- ) : (
|
|
|
+ const summary = isAbsoluteSelected ? (
|
|
|
<DateSummary utc={this.state.utc} start={start} end={end} />
|
|
|
+ ) : (
|
|
|
+ getRelativeSummary(relative || DEFAULT_STATS_PERIOD)
|
|
|
);
|
|
|
|
|
|
return (
|
|
@@ -298,7 +308,10 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
<StyledHeaderItem
|
|
|
icon={<StyledInlineSvg src="icon-calendar" />}
|
|
|
isOpen={isOpen}
|
|
|
- hasSelected={this.props.relative !== DEFAULT_STATS_PERIOD}
|
|
|
+ hasSelected={
|
|
|
+ (!!this.props.relative && this.props.relative !== DEFAULT_STATS_PERIOD) ||
|
|
|
+ isAbsoluteSelected
|
|
|
+ }
|
|
|
hasChanges={this.state.hasChanges}
|
|
|
onClear={this.handleClear}
|
|
|
allowClear={true}
|
|
@@ -317,7 +330,7 @@ class TimeRangeSelector extends React.PureComponent {
|
|
|
{shouldShowRelative && (
|
|
|
<RelativeSelector
|
|
|
onClick={this.handleSelectRelative}
|
|
|
- selected={relative}
|
|
|
+ selected={relative || DEFAULT_STATS_PERIOD}
|
|
|
/>
|
|
|
)}
|
|
|
{shouldShowAbsolute && (
|