mirror of https://github.com/grafana/grafana
Changed how react panels store their options (#15468)
Changed how react panels store their options * Added a ReactPanelPlugin as the interface that react panels export, this way react panels have clearer api, and gives us hooks to handle migrations and a way for panel to handle panel changes in the future * Moved gauge value options into a sub oject and made editor more generic, will be moved out of gauge pane later and shared between singlestat, gauge, bargauge, honecomb * Also remove nested options prop that was there due to bug * Added missing Gauge props * Fixed gauge issue that will require migration later and also value options editor did not handle null decimals or 0 decimals * Fixed unit tests * More fixes for react panelspull/15499/head
parent
a6cae5b2b8
commit
abddb442a1
@ -1,9 +1,14 @@ |
||||
// Libraries
|
||||
import React, { PureComponent } from 'react'; |
||||
import { FormField, PanelOptionsProps, PanelOptionsGroup, Switch } from '@grafana/ui'; |
||||
|
||||
// Components
|
||||
import { Switch, PanelOptionsGroup } from '@grafana/ui'; |
||||
|
||||
// Types
|
||||
import { FormField, PanelEditorProps } from '@grafana/ui'; |
||||
import { GaugeOptions } from './types'; |
||||
|
||||
export default class GaugeOptionsEditor extends PureComponent<PanelOptionsProps<GaugeOptions>> { |
||||
export class GaugeOptionsBox extends PureComponent<PanelEditorProps<GaugeOptions>> { |
||||
onToggleThresholdLabels = () => |
||||
this.props.onChange({ ...this.props.options, showThresholdLabels: !this.props.options.showThresholdLabels }); |
||||
|
@ -1,4 +1,10 @@ |
||||
import GaugePanelOptions, { defaultProps } from './GaugePanelOptions'; |
||||
import { ReactPanelPlugin } from '@grafana/ui'; |
||||
|
||||
import { GaugePanelEditor } from './GaugePanelEditor'; |
||||
import { GaugePanel } from './GaugePanel'; |
||||
import { GaugeOptions, defaults } from './types'; |
||||
|
||||
export const reactPanel = new ReactPanelPlugin<GaugeOptions>(GaugePanel); |
||||
|
||||
export { GaugePanel as Panel, GaugePanelOptions as PanelOptions, defaultProps as PanelDefaults }; |
||||
reactPanel.setEditor(GaugePanelEditor); |
||||
reactPanel.setDefaults(defaults); |
||||
|
@ -1,15 +1,35 @@ |
||||
import { Threshold, ValueMapping } from '@grafana/ui'; |
||||
|
||||
export interface GaugeOptions { |
||||
decimals: number; |
||||
valueMappings: ValueMapping[]; |
||||
maxValue: number; |
||||
minValue: number; |
||||
prefix: string; |
||||
showThresholdLabels: boolean; |
||||
showThresholdMarkers: boolean; |
||||
stat: string; |
||||
suffix: string; |
||||
thresholds: Threshold[]; |
||||
valueOptions: SingleStatValueOptions; |
||||
} |
||||
|
||||
export interface SingleStatValueOptions { |
||||
unit: string; |
||||
suffix: string; |
||||
stat: string; |
||||
prefix: string; |
||||
decimals?: number | null; |
||||
} |
||||
|
||||
export const defaults: GaugeOptions = { |
||||
minValue: 0, |
||||
maxValue: 100, |
||||
showThresholdMarkers: true, |
||||
showThresholdLabels: false, |
||||
valueOptions: { |
||||
prefix: '', |
||||
suffix: '', |
||||
decimals: null, |
||||
stat: 'avg', |
||||
unit: 'none', |
||||
}, |
||||
valueMappings: [], |
||||
thresholds: [], |
||||
}; |
||||
|
@ -1,4 +1,4 @@ |
||||
import { GraphPanel } from './GraphPanel'; |
||||
import { GraphPanelOptions } from './GraphPanelOptions'; |
||||
import { GraphPanelEditor } from './GraphPanelEditor'; |
||||
|
||||
export { GraphPanel as Panel, GraphPanelOptions as PanelOptions }; |
||||
export { GraphPanel as Panel, GraphPanelEditor as PanelOptions }; |
||||
|
Loading…
Reference in new issue