|
@@ -1,7 +1,12 @@
|
|
|
|
|
+// Libraries
|
|
|
import React, { PureComponent } from 'react';
|
|
import React, { PureComponent } from 'react';
|
|
|
-import { FormField, FormLabel, PanelOptionsProps, PanelOptionsGroup, Select } from '@grafana/ui';
|
|
|
|
|
|
|
+
|
|
|
|
|
+// Components
|
|
|
import UnitPicker from 'app/core/components/Select/UnitPicker';
|
|
import UnitPicker from 'app/core/components/Select/UnitPicker';
|
|
|
-import { GaugeOptions } from './types';
|
|
|
|
|
|
|
+import { FormField, FormLabel, PanelOptionsGroup, Select } from '@grafana/ui';
|
|
|
|
|
+
|
|
|
|
|
+// Types
|
|
|
|
|
+import { SingleStatValueOptions } from './types';
|
|
|
|
|
|
|
|
const statOptions = [
|
|
const statOptions = [
|
|
|
{ value: 'min', label: 'Min' },
|
|
{ value: 'min', label: 'Min' },
|
|
@@ -19,24 +24,40 @@ const statOptions = [
|
|
|
|
|
|
|
|
const labelWidth = 6;
|
|
const labelWidth = 6;
|
|
|
|
|
|
|
|
-export default class ValueOptions extends PureComponent<PanelOptionsProps<GaugeOptions>> {
|
|
|
|
|
- onUnitChange = unit => this.props.onChange({ ...this.props.options, unit: unit.value });
|
|
|
|
|
|
|
+export interface Props {
|
|
|
|
|
+ options: SingleStatValueOptions;
|
|
|
|
|
+ onChange: (valueOptions: SingleStatValueOptions) => void;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+export class SingleStatValueEditor extends PureComponent<Props> {
|
|
|
|
|
+ onUnitChange = unit => this.props.onChange({ ...this.props.options, unit: unit.value });
|
|
|
onStatChange = stat => this.props.onChange({ ...this.props.options, stat: stat.value });
|
|
onStatChange = stat => this.props.onChange({ ...this.props.options, stat: stat.value });
|
|
|
|
|
|
|
|
onDecimalChange = event => {
|
|
onDecimalChange = event => {
|
|
|
if (!isNaN(event.target.value)) {
|
|
if (!isNaN(event.target.value)) {
|
|
|
- this.props.onChange({ ...this.props.options, decimals: event.target.value });
|
|
|
|
|
|
|
+ this.props.onChange({
|
|
|
|
|
+ ...this.props.options,
|
|
|
|
|
+ decimals: parseInt(event.target.value, 10),
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.props.onChange({
|
|
|
|
|
+ ...this.props.options,
|
|
|
|
|
+ decimals: null,
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
onPrefixChange = event => this.props.onChange({ ...this.props.options, prefix: event.target.value });
|
|
onPrefixChange = event => this.props.onChange({ ...this.props.options, prefix: event.target.value });
|
|
|
-
|
|
|
|
|
onSuffixChange = event => this.props.onChange({ ...this.props.options, suffix: event.target.value });
|
|
onSuffixChange = event => this.props.onChange({ ...this.props.options, suffix: event.target.value });
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const { stat, unit, decimals, prefix, suffix } = this.props.options;
|
|
const { stat, unit, decimals, prefix, suffix } = this.props.options;
|
|
|
|
|
|
|
|
|
|
+ let decimalsString = '';
|
|
|
|
|
+ if (Number.isFinite(decimals)) {
|
|
|
|
|
+ decimalsString = decimals.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<PanelOptionsGroup title="Value">
|
|
<PanelOptionsGroup title="Value">
|
|
|
<div className="gf-form">
|
|
<div className="gf-form">
|
|
@@ -57,7 +78,7 @@ export default class ValueOptions extends PureComponent<PanelOptionsProps<GaugeO
|
|
|
labelWidth={labelWidth}
|
|
labelWidth={labelWidth}
|
|
|
placeholder="auto"
|
|
placeholder="auto"
|
|
|
onChange={this.onDecimalChange}
|
|
onChange={this.onDecimalChange}
|
|
|
- value={decimals || ''}
|
|
|
|
|
|
|
+ value={decimalsString}
|
|
|
type="number"
|
|
type="number"
|
|
|
/>
|
|
/>
|
|
|
<FormField label="Prefix" labelWidth={labelWidth} onChange={this.onPrefixChange} value={prefix || ''} />
|
|
<FormField label="Prefix" labelWidth={labelWidth} onChange={this.onPrefixChange} value={prefix || ''} />
|