ValueOptions.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React, { PureComponent } from 'react';
  2. import { Label } from 'app/core/components/Label/Label';
  3. import Select from 'app/core/components/Select/Select';
  4. import UnitPicker from 'app/core/components/Select/UnitPicker';
  5. import { OptionModuleProps } from './module';
  6. const statOptions = [
  7. { value: 'min', label: 'Min' },
  8. { value: 'max', label: 'Max' },
  9. { value: 'avg', label: 'Average' },
  10. { value: 'current', label: 'Current' },
  11. { value: 'total', label: 'Total' },
  12. { value: 'name', label: 'Name' },
  13. { value: 'first', label: 'First' },
  14. { value: 'delta', label: 'Delta' },
  15. { value: 'diff', label: 'Difference' },
  16. { value: 'range', label: 'Range' },
  17. { value: 'last_time', label: '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="section-heading">Value</h5>
  35. <div className="gf-form">
  36. <Label width={labelWidth}>Stat</Label>
  37. <Select
  38. width={12}
  39. options={statOptions}
  40. onChange={this.onStatChange}
  41. value={statOptions.find(option => option.value === stat)}
  42. />
  43. </div>
  44. <div className="gf-form">
  45. <Label width={labelWidth}>Unit</Label>
  46. <UnitPicker defaultValue={unit} onChange={this.onUnitChange} />
  47. </div>
  48. <div className="gf-form">
  49. <Label width={labelWidth}>Decimals</Label>
  50. <input
  51. className="gf-form-input width-12"
  52. type="number"
  53. placeholder="auto"
  54. value={decimals || ''}
  55. onChange={this.onDecimalChange}
  56. />
  57. </div>
  58. <div className="gf-form">
  59. <Label width={labelWidth}>Prefix</Label>
  60. <input className="gf-form-input width-12" type="text" value={prefix || ''} onChange={this.onPrefixChange} />
  61. </div>
  62. <div className="gf-form">
  63. <Label width={labelWidth}>Suffix</Label>
  64. <input className="gf-form-input width-12" type="text" value={suffix || ''} onChange={this.onSuffixChange} />
  65. </div>
  66. </div>
  67. );
  68. }
  69. }