Merge branch 'react-panel-options' into bar-gauge-poc

This commit is contained in:
Torkel Ödegaard
2019-02-16 16:34:56 +01:00
6 changed files with 28 additions and 11 deletions
@@ -9,7 +9,7 @@ import { Themeable } from '../../index';
type GaugeValue = string | number | null; type GaugeValue = string | number | null;
export interface Props extends Themeable { export interface Props extends Themeable {
decimals: number; decimals?: number | null;
height: number; height: number;
valueMappings: ValueMapping[]; valueMappings: ValueMapping[];
maxValue: number; maxValue: number;
@@ -78,7 +78,7 @@ exports[`DashboardPage Dashboard init completed Should render dashboard grid 1`
], ],
"refresh": undefined, "refresh": undefined,
"revision": undefined, "revision": undefined,
"schemaVersion": 17, "schemaVersion": 18,
"snapshot": undefined, "snapshot": undefined,
"style": "dark", "style": "dark",
"tags": Array [], "tags": Array [],
@@ -190,7 +190,7 @@ exports[`DashboardPage Dashboard init completed Should render dashboard grid 1`
], ],
"refresh": undefined, "refresh": undefined,
"revision": undefined, "revision": undefined,
"schemaVersion": 17, "schemaVersion": 18,
"snapshot": undefined, "snapshot": undefined,
"style": "dark", "style": "dark",
"tags": Array [], "tags": Array [],
@@ -313,7 +313,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti
], ],
"refresh": undefined, "refresh": undefined,
"revision": undefined, "revision": undefined,
"schemaVersion": 17, "schemaVersion": 18,
"snapshot": undefined, "snapshot": undefined,
"style": "dark", "style": "dark",
"tags": Array [], "tags": Array [],
@@ -423,7 +423,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti
], ],
"refresh": undefined, "refresh": undefined,
"revision": undefined, "revision": undefined,
"schemaVersion": 17, "schemaVersion": 18,
"snapshot": undefined, "snapshot": undefined,
"style": "dark", "style": "dark",
"tags": Array [], "tags": Array [],
@@ -518,7 +518,7 @@ exports[`DashboardPage When dashboard has editview url state should render setti
], ],
"refresh": undefined, "refresh": undefined,
"revision": undefined, "revision": undefined,
"schemaVersion": 17, "schemaVersion": 18,
"snapshot": undefined, "snapshot": undefined,
"style": "dark", "style": "dark",
"tags": Array [], "tags": Array [],
@@ -127,7 +127,7 @@ describe('DashboardModel', () => {
}); });
it('dashboard schema version should be set to latest', () => { it('dashboard schema version should be set to latest', () => {
expect(model.schemaVersion).toBe(17); expect(model.schemaVersion).toBe(18);
}); });
it('graph thresholds should be migrated', () => { it('graph thresholds should be migrated', () => {
@@ -50,6 +50,10 @@ export class GaugePanel extends PureComponent<Props> {
decimals={valueOptions.decimals} decimals={valueOptions.decimals}
thresholds={options.thresholds} thresholds={options.thresholds}
valueMappings={options.valueMappings} valueMappings={options.valueMappings}
showThresholdLabels={options.showThresholdLabels}
showThresholdMarkers={options.showThresholdMarkers}
minValue={options.minValue}
maxValue={options.maxValue}
theme={theme} theme={theme}
/> />
)} )}
@@ -35,7 +35,15 @@ export class SingleStatValueEditor extends PureComponent<Props> {
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,
});
} }
}; };
@@ -45,6 +53,11 @@ export class SingleStatValueEditor extends PureComponent<Props> {
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">
@@ -65,7 +78,7 @@ export class SingleStatValueEditor extends PureComponent<Props> {
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 || ''} />
+2 -2
View File
@@ -15,7 +15,7 @@ export interface SingleStatValueOptions {
suffix: string; suffix: string;
stat: string; stat: string;
prefix: string; prefix: string;
decimals: number; decimals?: number | null;
} }
export const defaults: GaugeOptions = { export const defaults: GaugeOptions = {
@@ -26,7 +26,7 @@ export const defaults: GaugeOptions = {
valueOptions: { valueOptions: {
prefix: '', prefix: '',
suffix: '', suffix: '',
decimals: 0, decimals: null,
stat: 'avg', stat: 'avg',
unit: 'none', unit: 'none',
}, },