import React, { PureComponent } from 'react'; import { Switch } from 'app/core/components/Switch/Switch'; import { Input } from 'app/core/components/Form'; import { isValidTimeSpan } from 'app/core/utils/rangeutil'; import { ValidationEvents } from 'app/types'; import { EventsWithValidation } from 'app/core/components/Form/Input'; import { PanelModel } from '../panel_model'; import { InputStatus } from 'app/core/components/Form/Input'; const timeRangeValidationEvents: ValidationEvents = { [EventsWithValidation.onBlur]: [ { rule: value => { if (!value) { return true; } return isValidTimeSpan(value); }, errorMessage: 'Not a valid timespan', }, ], }; const emptyToNull = (value: string) => { return value === '' ? null : value; }; interface Props { panel: PanelModel; } export class TimeRangeOptions extends PureComponent { onOverrideTime = (evt, status: InputStatus) => { const { value } = evt.target; const { panel } = this.props; const emptyToNullValue = emptyToNull(value); if (status === InputStatus.Valid && panel.timeFrom !== emptyToNullValue) { panel.timeFrom = emptyToNullValue; panel.refresh(); } }; onTimeShift = (evt, status: InputStatus) => { const { value } = evt.target; const { panel } = this.props; const emptyToNullValue = emptyToNull(value); if (status === InputStatus.Valid && panel.timeShift !== emptyToNullValue) { panel.timeShift = emptyToNullValue; panel.refresh(); } }; onToggleTimeOverride = () => { const { panel } = this.props; panel.hideTimeOverride = !panel.hideTimeOverride; panel.refresh(); }; render = () => { const hideTimeOverride = this.props.panel.hideTimeOverride; return ( <>
Time Range
Override relative time
Add time shift
); }; }