PiechartValueEditor.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { PureComponent } from 'react';
  2. import { FormLabel, PanelOptionsGroup, Select } from '@grafana/ui';
  3. import UnitPicker from 'app/core/components/Select/UnitPicker';
  4. import { PiechartValueOptions } 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. ];
  12. const labelWidth = 6;
  13. export interface Props {
  14. options: PiechartValueOptions;
  15. onChange: (valueOptions: PiechartValueOptions) => void;
  16. }
  17. export default class PiechartValueEditor extends PureComponent<Props> {
  18. onUnitChange = unit =>
  19. this.props.onChange({
  20. ...this.props.options,
  21. unit: unit.value,
  22. });
  23. onStatChange = stat =>
  24. this.props.onChange({
  25. ...this.props.options,
  26. stat: stat.value,
  27. });
  28. render() {
  29. const { stat, unit } = this.props.options;
  30. return (
  31. <PanelOptionsGroup title="Value">
  32. <div className="gf-form">
  33. <FormLabel width={labelWidth}>Stat</FormLabel>
  34. <Select
  35. width={12}
  36. options={statOptions}
  37. onChange={this.onStatChange}
  38. value={statOptions.find(option => option.value === stat)}
  39. />
  40. </div>
  41. <div className="gf-form">
  42. <FormLabel width={labelWidth}>Unit</FormLabel>
  43. <UnitPicker defaultValue={unit} onChange={this.onUnitChange} />
  44. </div>
  45. </PanelOptionsGroup>
  46. );
  47. }
  48. }