TimePicker: some fixes and polish after testing feedback (#24585)

* make sure we render the delaynow value from dashboard to the time picker settings.

* Added the time zone in the tooltip.
This commit is contained in:
Marcus Andersson
2020-05-13 07:26:03 +02:00
committed by GitHub
parent 2d19c046f2
commit cab066f8ce
3 changed files with 31 additions and 9 deletions

View File

@@ -1,5 +1,18 @@
// List taken from https://stackoverflow.com/questions/38399465/how-to-get-list-of-all-timezones-in-javascript import { TimeZone } from '../types';
import { getTimeZone } from './common';
export const timeZoneFormatUserFriendly = (timeZone: TimeZone | undefined) => {
switch (getTimeZone({ timeZone })) {
case 'browser':
return 'Local browser time';
case 'utc':
return 'UTC';
default:
return timeZone;
}
};
// List taken from https://stackoverflow.com/questions/38399465/how-to-get-list-of-all-timezones-in-javascript
export const getTimeZoneGroups = () => { export const getTimeZoneGroups = () => {
const europeZones = [ const europeZones = [
'Europe/Amsterdam', 'Europe/Amsterdam',

View File

@@ -13,7 +13,7 @@ import { stylesFactory } from '../../themes/stylesFactory';
import { withTheme, useTheme } from '../../themes/ThemeContext'; import { withTheme, useTheme } from '../../themes/ThemeContext';
// Types // Types
import { isDateTime, rangeUtil, GrafanaTheme, dateTimeFormatWithAbbrevation } from '@grafana/data'; import { isDateTime, rangeUtil, GrafanaTheme, dateTimeFormat, timeZoneFormatUserFriendly } from '@grafana/data';
import { TimeRange, TimeOption, TimeZone, dateMath } from '@grafana/data'; import { TimeRange, TimeOption, TimeZone, dateMath } from '@grafana/data';
import { Themeable } from '../../types'; import { Themeable } from '../../types';
@@ -206,13 +206,21 @@ const ZoomOutTooltip = () => (
</> </>
); );
const TimePickerTooltip = ({ timeRange, timeZone }: { timeRange: TimeRange; timeZone?: TimeZone }) => ( const TimePickerTooltip = ({ timeRange, timeZone }: { timeRange: TimeRange; timeZone?: TimeZone }) => {
const theme = useTheme();
const styles = getLabelStyles(theme);
return (
<> <>
{dateTimeFormatWithAbbrevation(timeRange.from, { timeZone })} {dateTimeFormat(timeRange.from, { timeZone })}
<div className="text-center">to</div> <div className="text-center">to</div>
{dateTimeFormatWithAbbrevation(timeRange.to, { timeZone })} {dateTimeFormat(timeRange.to, { timeZone })}
<div className="text-center">
<span className={styles.utc}>{timeZoneFormatUserFriendly(timeZone)}</span>
</div>
</> </>
); );
};
const TimePickerButtonLabel = memo<Props>(({ hideText, value, timeZone }) => { const TimePickerButtonLabel = memo<Props>(({ hideText, value, timeZone }) => {
const theme = useTheme(); const theme = useTheme();

View File

@@ -133,6 +133,7 @@ export class TimePickerSettings extends PureComponent<Props, State> {
invalid={!this.state.isNowDelayValid} invalid={!this.state.isNowDelayValid}
placeholder="0m" placeholder="0m"
onChange={this.onNowDelayChange} onChange={this.onNowDelayChange}
defaultValue={dashboard.timepicker.nowDelay}
/> />
</Tooltip> </Tooltip>
</div> </div>