Commit 09e79384 by Ryan McKinley Committed by Torkel Ödegaard

Gauge/BarGauge: Support decimals for min/max toFloatOrUndefined (#18368)

parent 202c1362
...@@ -55,3 +55,11 @@ export function toIntegerOrUndefined(value: string): number | undefined { ...@@ -55,3 +55,11 @@ export function toIntegerOrUndefined(value: string): number | undefined {
const v = parseInt(value, 10); const v = parseInt(value, 10);
return isNaN(v) ? undefined : v; return isNaN(v) ? undefined : v;
} }
export function toFloatOrUndefined(value: string): number | undefined {
if (!value) {
return undefined;
}
const v = parseFloat(value);
return isNaN(v) ? undefined : v;
}
...@@ -7,7 +7,7 @@ import { FormLabel } from '../FormLabel/FormLabel'; ...@@ -7,7 +7,7 @@ import { FormLabel } from '../FormLabel/FormLabel';
import { UnitPicker } from '../UnitPicker/UnitPicker'; import { UnitPicker } from '../UnitPicker/UnitPicker';
// Types // Types
import { toIntegerOrUndefined, Field, SelectableValue } from '@grafana/data'; import { toIntegerOrUndefined, Field, SelectableValue, toFloatOrUndefined, toNumberString } from '@grafana/data';
import { VAR_SERIES_NAME, VAR_FIELD_NAME, VAR_CALC, VAR_CELL_PREFIX } from '../../utils/fieldDisplay'; import { VAR_SERIES_NAME, VAR_FIELD_NAME, VAR_CALC, VAR_CELL_PREFIX } from '../../utils/fieldDisplay';
...@@ -25,8 +25,8 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi ...@@ -25,8 +25,8 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi
const [decimals, setDecimals] = useState( const [decimals, setDecimals] = useState(
value.decimals !== undefined && value.decimals !== null ? value.decimals.toString() : '' value.decimals !== undefined && value.decimals !== null ? value.decimals.toString() : ''
); );
const [min, setMin] = useState(value.min !== undefined && value.min !== null ? value.min.toString() : ''); const [min, setMin] = useState(toNumberString(value.min));
const [max, setMax] = useState(value.max !== undefined && value.max !== null ? value.max.toString() : ''); const [max, setMax] = useState(toNumberString(value.max));
const onTitleChange = (event: ChangeEvent<HTMLInputElement>) => { const onTitleChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...value, title: event.target.value }); onChange({ ...value, title: event.target.value });
...@@ -61,8 +61,8 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi ...@@ -61,8 +61,8 @@ export const FieldPropertiesEditor: React.FC<Props> = ({ value, onChange, showMi
onChange({ onChange({
...value, ...value,
decimals: toIntegerOrUndefined(decimals), decimals: toIntegerOrUndefined(decimals),
min: toIntegerOrUndefined(min), min: toFloatOrUndefined(min),
max: toIntegerOrUndefined(max), max: toFloatOrUndefined(max),
}); });
}, [min, max, decimals]); }, [min, max, decimals]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment