// Libraries import React, { PureComponent, ChangeEvent } from 'react'; // Components import { FormField, FormLabel, PanelOptionsGroup, StatsPicker, UnitPicker, ReducerID, SelectOptionItem, } from '@grafana/ui'; // Types import { SingleStatValueOptions } from './shared'; const labelWidth = 6; export interface Props { value: SingleStatValueOptions; onChange: (valueOptions: SingleStatValueOptions) => void; } export class SingleStatValueEditor extends PureComponent { // @ts-ignore onUnitChange = (unit: SelectOptionItem) => this.props.onChange({ ...this.props.value, unit: unit.value }); onStatsChange = (stats: string[]) => { const stat = stats[0] || ReducerID.mean; this.props.onChange({ ...this.props.value, stat }); }; onDecimalChange = (event: ChangeEvent) => { if (!isNaN(parseInt(event.target.value, 10))) { this.props.onChange({ ...this.props.value, decimals: parseInt(event.target.value, 10), }); } else { this.props.onChange({ ...this.props.value, decimals: null, }); } }; onPrefixChange = (event: ChangeEvent) => this.props.onChange({ ...this.props.value, prefix: event.target.value }); onSuffixChange = (event: ChangeEvent) => this.props.onChange({ ...this.props.value, suffix: event.target.value }); render() { const { stat, unit, decimals, prefix, suffix } = this.props.value; let decimalsString = ''; if (decimals !== null && decimals !== undefined && Number.isFinite(decimals as number)) { decimalsString = decimals.toString(); } return (
Show
Unit
); } }