ValueOptions.tsx 2.7 KB

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