import { isEmpty } from 'lodash'; import React, { PureComponent } from 'react'; import { rangeUtil, TimeZone } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { CollapsableSection, Field, Input, Switch, TimeZonePicker, WeekStartPicker } from '@grafana/ui'; import { AutoRefreshIntervals } from './AutoRefreshIntervals'; interface Props { onWeekStartChange: (weekStart: string) => void; onTimeZoneChange: (timeZone: TimeZone) => void; onRefreshIntervalChange: (interval: string[]) => void; onNowDelayChange: (nowDelay: string) => void; onHideTimePickerChange: (hide: boolean) => void; onLiveNowChange: (liveNow: boolean) => void; refreshIntervals: string[]; timePickerHidden: boolean; nowDelay: string; timezone: TimeZone; weekStart: string; liveNow: boolean; } interface State { isNowDelayValid: boolean; } export class TimePickerSettings extends PureComponent { state: State = { isNowDelayValid: true }; onNowDelayChange = (event: React.FormEvent) => { const value = event.currentTarget.value; if (isEmpty(value)) { this.setState({ isNowDelayValid: true }); return this.props.onNowDelayChange(value); } if (rangeUtil.isValidTimeSpan(value)) { this.setState({ isNowDelayValid: true }); return this.props.onNowDelayChange(value); } this.setState({ isNowDelayValid: false }); }; onHideTimePickerChange = () => { this.props.onHideTimePickerChange(!this.props.timePickerHidden); }; onLiveNowChange = () => { this.props.onLiveNowChange(!this.props.liveNow); }; onTimeZoneChange = (timeZone?: string) => { if (typeof timeZone !== 'string') { return; } this.props.onTimeZoneChange(timeZone); }; onWeekStartChange = (weekStart: string) => { this.props.onWeekStartChange(weekStart); }; render() { return ( ); } }