mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
This reverts commit 0752a09f92
.
This commit is contained in:
parent
0752a09f92
commit
6144c0f51d
@ -5,18 +5,6 @@ import { TimeZone } from '../types';
|
|||||||
|
|
||||||
const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
|
const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
|
||||||
|
|
||||||
export function isMathString(text: string | DateTime | Date): boolean {
|
|
||||||
if (!text) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof text === 'string' && (text.substring(0, 3) === 'now' || text.includes('||'))) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses different types input to a moment instance. There is a specific formatting language that can be used
|
* Parses different types input to a moment instance. There is a specific formatting language that can be used
|
||||||
* if text arg is string. See unit tests for examples.
|
* if text arg is string. See unit tests for examples.
|
||||||
|
@ -14,7 +14,6 @@ import { rawToTimeRange } from './time';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { TimeRange, TimeOption, TimeZone, TIME_FORMAT, SelectableValue } from '@grafana/data';
|
import { TimeRange, TimeOption, TimeZone, TIME_FORMAT, SelectableValue } from '@grafana/data';
|
||||||
import { isMathString } from '@grafana/data/src/utils/datemath';
|
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
value: TimeRange;
|
value: TimeRange;
|
||||||
@ -124,21 +123,13 @@ export class TimePicker extends PureComponent<Props, State> {
|
|||||||
const { isCustomOpen } = this.state;
|
const { isCustomOpen } = this.state;
|
||||||
const options = this.mapTimeOptionsToSelectableValues(selectTimeOptions);
|
const options = this.mapTimeOptionsToSelectableValues(selectTimeOptions);
|
||||||
const currentOption = options.find(item => isTimeOptionEqualToTimeRange(item.value, value));
|
const currentOption = options.find(item => isTimeOptionEqualToTimeRange(item.value, value));
|
||||||
|
const rangeString = rangeUtil.describeTimeRange(value.raw);
|
||||||
const isUTC = timeZone === 'utc';
|
|
||||||
const adjustedTo = isUTC ? value.to.utc() : value.to.local();
|
|
||||||
const adjustedFrom = isUTC ? value.from.utc() : value.from.local();
|
|
||||||
const adjustedTimeRange = {
|
|
||||||
to: isMathString(value.raw.to) ? value.raw.to : adjustedTo,
|
|
||||||
from: isMathString(value.raw.from) ? value.raw.from : adjustedFrom,
|
|
||||||
};
|
|
||||||
const rangeString = rangeUtil.describeTimeRange(adjustedTimeRange);
|
|
||||||
|
|
||||||
const label = (
|
const label = (
|
||||||
<>
|
<>
|
||||||
{isCustomOpen && <span>Custom time range</span>}
|
{isCustomOpen && <span>Custom time range</span>}
|
||||||
{!isCustomOpen && <span>{rangeString}</span>}
|
{!isCustomOpen && <span>{rangeString}</span>}
|
||||||
{isUTC && <span className="time-picker-utc">UTC</span>}
|
{timeZone === 'utc' && <span className="time-picker-utc">UTC</span>}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
const isAbsolute = isDateTime(value.raw.to);
|
const isAbsolute = isDateTime(value.raw.to);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Libaries
|
// Libaries
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { toUtc, dateMath } from '@grafana/data';
|
import { toUtc } from '@grafana/data';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { DashboardModel } from '../../state';
|
import { DashboardModel } from '../../state';
|
||||||
@ -61,11 +61,9 @@ export class DashNavTimeControls extends Component<Props> {
|
|||||||
const panel = dashboard.timepicker;
|
const panel = dashboard.timepicker;
|
||||||
const hasDelay = panel.nowDelay && timeRange.raw.to === 'now';
|
const hasDelay = panel.nowDelay && timeRange.raw.to === 'now';
|
||||||
|
|
||||||
const adjustedFrom = dateMath.isMathString(timeRange.raw.from) ? timeRange.raw.from : timeRange.from;
|
|
||||||
const adjustedTo = dateMath.isMathString(timeRange.raw.to) ? timeRange.raw.to : timeRange.to;
|
|
||||||
const nextRange = {
|
const nextRange = {
|
||||||
from: adjustedFrom,
|
from: timeRange.raw.from,
|
||||||
to: hasDelay ? 'now-' + panel.nowDelay : adjustedTo,
|
to: hasDelay ? 'now-' + panel.nowDelay : timeRange.raw.to,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.timeSrv.setTime(nextRange);
|
this.timeSrv.setTime(nextRange);
|
||||||
|
Loading…
Reference in New Issue
Block a user