mirror of https://github.com/grafana/grafana
parent
e0064ed38e
commit
4e1f49f883
@ -0,0 +1,42 @@ |
||||
import React, { PureComponent } from 'react'; |
||||
import { OptionsProps } from './Options'; |
||||
import { Switch } from 'app/core/components/Switch/Switch'; |
||||
|
||||
interface Props { |
||||
onChange: (item: any) => any; |
||||
options: OptionsProps; |
||||
} |
||||
|
||||
export default class GaugeOptions extends PureComponent<Props> { |
||||
toggleThresholdLabels = () => |
||||
this.props.onChange({ ...this.props.options, showThresholdLabels: !this.props.options.showThresholdLabels }); |
||||
|
||||
toggleThresholdMarkers = () => |
||||
this.props.onChange({ ...this.props.options, showThresholdMarkers: !this.props.options.showThresholdMarkers }); |
||||
|
||||
render() { |
||||
const { showThresholdLabels, showThresholdMarkers } = this.props.options; |
||||
|
||||
return ( |
||||
<div className="section gf-form-group"> |
||||
<h5 className="page-heading">Gauge</h5> |
||||
<div className="gf-form-inline"> |
||||
<Switch |
||||
label="Threshold labels" |
||||
labelClass="width-10" |
||||
checked={showThresholdLabels} |
||||
onChange={this.toggleThresholdLabels} |
||||
/> |
||||
</div> |
||||
<div className="gf-form-inline"> |
||||
<Switch |
||||
label="Threshold labels" |
||||
labelClass="width-10" |
||||
checked={showThresholdMarkers} |
||||
onChange={this.toggleThresholdMarkers} |
||||
/> |
||||
</div> |
||||
</div> |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
import React, { PureComponent } from 'react'; |
||||
import ValueOptions from './ValueOptions'; |
||||
import { PanelOptionsProps } from 'app/types'; |
||||
import GaugeOptions from './GaugeOptions'; |
||||
|
||||
export interface OptionsProps { |
||||
decimals: number; |
||||
prefix: string; |
||||
showThresholdLabels: boolean; |
||||
showThresholdMarkers: boolean; |
||||
stat: string; |
||||
suffix: string; |
||||
unit: string; |
||||
thresholds: number[]; |
||||
minValue: number; |
||||
maxValue: number; |
||||
} |
||||
|
||||
export default class Options extends PureComponent<PanelOptionsProps<OptionsProps>> { |
||||
render() { |
||||
return ( |
||||
<div> |
||||
<ValueOptions onChange={this.props.onChange} options={this.props.options} /> |
||||
<GaugeOptions onChange={this.props.onChange} options={this.props.options} /> |
||||
</div> |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,85 @@ |
||||
import React, { PureComponent } from 'react'; |
||||
import { Label } from 'app/core/components/Label/Label'; |
||||
import SimplePicker from 'app/core/components/Picker/SimplePicker'; |
||||
import UnitPicker from 'app/core/components/Picker/Unit/UnitPicker'; |
||||
import { OptionsProps } from './Options'; |
||||
|
||||
const statOptions = [ |
||||
{ value: 'min', text: 'Min' }, |
||||
{ value: 'max', text: 'Max' }, |
||||
{ value: 'avg', text: 'Average' }, |
||||
{ value: 'current', text: 'Current' }, |
||||
{ value: 'total', text: 'Total' }, |
||||
{ value: 'name', text: 'Name' }, |
||||
{ value: 'first', text: 'First' }, |
||||
{ value: 'delta', text: 'Delta' }, |
||||
{ value: 'diff', text: 'Difference' }, |
||||
{ value: 'range', text: 'Range' }, |
||||
{ value: 'last_time', text: 'Time of last point' }, |
||||
]; |
||||
|
||||
const labelWidth = 6; |
||||
|
||||
interface Props { |
||||
onChange: (arg: any) => void; |
||||
options: OptionsProps; |
||||
} |
||||
|
||||
export default class ValueOptions 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 }); |
||||
|
||||
onDecimalChange = event => { |
||||
if (!isNaN(event.target.value)) { |
||||
this.props.onChange({ ...this.props.options, decimals: 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 }); |
||||
|
||||
render() { |
||||
const { stat, unit, decimals, prefix, suffix } = this.props.options; |
||||
|
||||
return ( |
||||
<div className="section gf-form-group"> |
||||
<h5 className="page-heading">Value</h5> |
||||
<div className="gf-form-inline"> |
||||
<Label width={labelWidth}>Stat</Label> |
||||
<SimplePicker |
||||
width={12} |
||||
options={statOptions} |
||||
getOptionLabel={i => i.text} |
||||
getOptionValue={i => i.value} |
||||
onSelected={this.onStatChange} |
||||
value={statOptions.find(option => option.value === stat)} |
||||
/> |
||||
</div> |
||||
<div className="gf-form-inline"> |
||||
<Label width={labelWidth}>Unit</Label> |
||||
<UnitPicker defaultValue={unit} onSelected={value => this.onUnitChange(value)} /> |
||||
</div> |
||||
<div className="gf-form-inline"> |
||||
<Label width={labelWidth}>Decimals</Label> |
||||
<input |
||||
className="gf-form-input width-12" |
||||
type="number" |
||||
placeholder="auto" |
||||
value={decimals || ''} |
||||
onChange={this.onDecimalChange} |
||||
/> |
||||
</div> |
||||
<div className="gf-form-inline"> |
||||
<Label width={labelWidth}>Prefix</Label> |
||||
<input className="gf-form-input width-12" type="text" value={prefix || ''} onChange={this.onPrefixChange} /> |
||||
</div> |
||||
<div className="gf-form-inline"> |
||||
<Label width={labelWidth}>Suffix</Label> |
||||
<input className="gf-form-input width-12" type="text" value={suffix || ''} onChange={this.onSuffixChange} /> |
||||
</div> |
||||
</div> |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue