module.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React, { PureComponent } from 'react';
  2. import Gauge from 'app/viz/Gauge';
  3. import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
  4. import ValueOptions from './ValueOptions';
  5. import GaugeOptions from './GaugeOptions';
  6. import Thresholds from './Thresholds';
  7. import ValueMappings from './ValueMappings';
  8. import {
  9. BasicGaugeColor,
  10. NullValueMode,
  11. PanelOptionsProps,
  12. PanelProps,
  13. RangeMap,
  14. Threshold,
  15. ValueMap,
  16. } from 'app/types';
  17. export interface OptionsProps {
  18. decimals: number;
  19. prefix: string;
  20. showThresholdLabels: boolean;
  21. showThresholdMarkers: boolean;
  22. stat: string;
  23. suffix: string;
  24. unit: string;
  25. thresholds: Threshold[];
  26. mappings: Array<RangeMap | ValueMap>;
  27. }
  28. export interface OptionModuleProps {
  29. onChange: (item: any) => void;
  30. options: OptionsProps;
  31. }
  32. export const defaultProps = {
  33. options: {
  34. minValue: 0,
  35. maxValue: 100,
  36. prefix: '',
  37. showThresholdMarkers: true,
  38. showThresholdLabels: false,
  39. suffix: '',
  40. decimals: 0,
  41. stat: '',
  42. unit: '',
  43. mappings: [],
  44. thresholds: [
  45. { index: 0, label: 'Min', value: 0, canRemove: false, color: BasicGaugeColor.Green },
  46. { index: 1, label: 'Max', value: 100, canRemove: false },
  47. ],
  48. },
  49. };
  50. interface Props extends PanelProps<OptionsProps> {}
  51. class GaugePanel extends PureComponent<Props> {
  52. render() {
  53. const { timeSeries, width, height } = this.props;
  54. const vmSeries = getTimeSeriesVMs({
  55. timeSeries: timeSeries,
  56. nullValueMode: NullValueMode.Ignore,
  57. });
  58. return <Gauge timeSeries={vmSeries} {...this.props.options} width={width} height={height} />;
  59. }
  60. }
  61. class Options extends PureComponent<PanelOptionsProps<OptionsProps>> {
  62. static defaultProps = defaultProps;
  63. render() {
  64. const { onChange, options } = this.props;
  65. return (
  66. <div>
  67. <div className="form-section">
  68. <ValueOptions onChange={onChange} options={options} />
  69. <GaugeOptions onChange={onChange} options={options} />
  70. <Thresholds onChange={onChange} options={options} />
  71. </div>
  72. <div className="form-section">
  73. <ValueMappings onChange={onChange} options={options} />
  74. </div>
  75. </div>
  76. );
  77. }
  78. }
  79. export { GaugePanel as Panel, Options as PanelOptions, defaultProps as PanelDefaults };