ValueOptions.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, { PureComponent } from 'react';
  2. import { Label } from 'app/core/components/Label/Label';
  3. import SimplePicker from 'app/core/components/Picker/SimplePicker';
  4. import UnitPicker from 'app/core/components/Picker/Unit/UnitPicker';
  5. import { OptionModuleProps } from './module';
  6. const statOptions = [
  7. { value: 'min', text: 'Min' },
  8. { value: 'max', text: 'Max' },
  9. { value: 'avg', text: 'Average' },
  10. { value: 'current', text: 'Current' },
  11. { value: 'total', text: 'Total' },
  12. { value: 'name', text: 'Name' },
  13. { value: 'first', text: 'First' },
  14. { value: 'delta', text: 'Delta' },
  15. { value: 'diff', text: 'Difference' },
  16. { value: 'range', text: 'Range' },
  17. { value: 'last_time', text: 'Time of last point' },
  18. ];
  19. const labelWidth = 6;
  20. export default class ValueOptions extends PureComponent<OptionModuleProps> {
  21. onUnitChange = unit => this.props.onChange({ ...this.props.options, unit: unit.value });
  22. onStatChange = stat => this.props.onChange({ ...this.props.options, stat: stat.value });
  23. onDecimalChange = event => {
  24. if (!isNaN(event.target.value)) {
  25. this.props.onChange({ ...this.props.options, decimals: event.target.value });
  26. }
  27. };
  28. onPrefixChange = event => this.props.onChange({ ...this.props.options, prefix: event.target.value });
  29. onSuffixChange = event => this.props.onChange({ ...this.props.options, suffix: event.target.value });
  30. render() {
  31. const { stat, unit, decimals, prefix, suffix } = this.props.options;
  32. return (
  33. <div className="section gf-form-group">
  34. <h5 className="page-heading">Value</h5>
  35. <div className="gf-form-inline">
  36. <Label width={labelWidth}>Stat</Label>
  37. <SimplePicker
  38. width={12}
  39. options={statOptions}
  40. getOptionLabel={i => i.text}
  41. getOptionValue={i => i.value}
  42. onSelected={this.onStatChange}
  43. value={statOptions.find(option => option.value === stat)}
  44. />
  45. </div>
  46. <div className="gf-form-inline">
  47. <Label width={labelWidth}>Unit</Label>
  48. <UnitPicker defaultValue={unit} onSelected={value => this.onUnitChange(value)} />
  49. </div>
  50. <div className="gf-form-inline">
  51. <Label width={labelWidth}>Decimals</Label>
  52. <input
  53. className="gf-form-input width-12"
  54. type="number"
  55. placeholder="auto"
  56. value={decimals || ''}
  57. onChange={this.onDecimalChange}
  58. />
  59. </div>
  60. <div className="gf-form-inline">
  61. <Label width={labelWidth}>Prefix</Label>
  62. <input className="gf-form-input width-12" type="text" value={prefix || ''} onChange={this.onPrefixChange} />
  63. </div>
  64. <div className="gf-form-inline">
  65. <Label width={labelWidth}>Suffix</Label>
  66. <input className="gf-form-input width-12" type="text" value={suffix || ''} onChange={this.onSuffixChange} />
  67. </div>
  68. </div>
  69. );
  70. }
  71. }