module.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React, { PureComponent } from 'react';
  2. import Gauge from 'app/viz/Gauge';
  3. import { NullValueMode, PanelOptionsProps, PanelProps, Threshold } from 'app/types';
  4. import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
  5. import ValueOptions from './ValueOptions';
  6. import GaugeOptions from './GaugeOptions';
  7. import Thresholds from './Thresholds';
  8. export interface OptionsProps {
  9. decimals: number;
  10. prefix: string;
  11. showThresholdLabels: boolean;
  12. showThresholdMarkers: boolean;
  13. stat: string;
  14. suffix: string;
  15. unit: string;
  16. thresholds: Threshold[];
  17. }
  18. export interface OptionModuleProps {
  19. onChange: (item: any) => void;
  20. options: OptionsProps;
  21. }
  22. export const defaultProps = {
  23. options: {
  24. minValue: 0,
  25. maxValue: 100,
  26. prefix: '',
  27. showThresholdMarkers: true,
  28. showThresholdLabels: false,
  29. suffix: '',
  30. },
  31. };
  32. interface Props extends PanelProps<OptionsProps> {}
  33. class GaugePanel extends PureComponent<Props> {
  34. render() {
  35. const { timeSeries, width, height } = this.props;
  36. const vmSeries = getTimeSeriesVMs({
  37. timeSeries: timeSeries,
  38. nullValueMode: NullValueMode.Ignore,
  39. });
  40. return <Gauge timeSeries={vmSeries} {...this.props.options} width={width} height={height} />;
  41. }
  42. }
  43. class Options extends PureComponent<PanelOptionsProps<OptionsProps>> {
  44. static defaultProps = defaultProps;
  45. render() {
  46. return (
  47. <div>
  48. <ValueOptions onChange={this.props.onChange} options={this.props.options} />
  49. <GaugeOptions onChange={this.props.onChange} options={this.props.options} />
  50. <Thresholds onChange={this.props.onChange} options={this.props.options} />
  51. </div>
  52. );
  53. }
  54. }
  55. export { GaugePanel as Panel, Options as PanelOptions, defaultProps as PanelDefaults };