GaugePanelOptions.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React, { PureComponent } from 'react';
  2. import {
  3. PanelOptionsProps,
  4. ThresholdsEditor,
  5. Threshold,
  6. PanelOptionsGrid,
  7. ValueMappingsEditor,
  8. ValueMapping,
  9. } from '@grafana/ui';
  10. import ValueOptions from 'app/plugins/panel/gauge/ValueOptions';
  11. import GaugeOptionsEditor from './GaugeOptionsEditor';
  12. import { GaugeOptions } from './types';
  13. import { ThemeProvider } from 'app/core/utils/ConfigProvider';
  14. export const defaultProps = {
  15. options: {
  16. minValue: 0,
  17. maxValue: 100,
  18. prefix: '',
  19. showThresholdMarkers: true,
  20. showThresholdLabels: false,
  21. suffix: '',
  22. decimals: 0,
  23. stat: 'avg',
  24. unit: 'none',
  25. valueMappings: [],
  26. thresholds: [],
  27. },
  28. };
  29. export default class GaugePanelOptions extends PureComponent<PanelOptionsProps<GaugeOptions>> {
  30. static defaultProps = defaultProps;
  31. onThresholdsChanged = (thresholds: Threshold[]) =>
  32. this.props.onChange({
  33. ...this.props.options,
  34. thresholds,
  35. });
  36. onValueMappingsChanged = (valueMappings: ValueMapping[]) =>
  37. this.props.onChange({
  38. ...this.props.options,
  39. valueMappings,
  40. });
  41. render() {
  42. const { onChange, options } = this.props;
  43. return (
  44. <ThemeProvider>
  45. {(theme) => (
  46. <>
  47. <PanelOptionsGrid>
  48. <ValueOptions onChange={onChange} options={options} />
  49. <GaugeOptionsEditor onChange={onChange} options={options} />
  50. <ThresholdsEditor
  51. onChange={this.onThresholdsChanged}
  52. thresholds={options.thresholds}
  53. theme={theme}
  54. />
  55. </PanelOptionsGrid>
  56. <ValueMappingsEditor onChange={this.onValueMappingsChanged} valueMappings={options.valueMappings} />
  57. </>
  58. )}
  59. </ThemeProvider>
  60. );
  61. }
  62. }