Browse Source

use onOptionsChange

ryan 6 năm trước cách đây
mục cha
commit
3d16528459

+ 1 - 1
packages/grafana-ui/src/types/panel.ts

@@ -22,7 +22,7 @@ export interface PanelData {
 
 export interface PanelEditorProps<T = any> {
   options: T;
-  updateOptions: (options: T) => void;
+  onOptionsChange: (options: T) => void;
 }
 
 export class ReactPanelPlugin<TOptions = any> {

+ 1 - 1
public/app/features/dashboard/panel_editor/VisualizationTab.tsx

@@ -66,7 +66,7 @@ export class VisualizationTab extends PureComponent<Props, State> {
       const PanelEditor = plugin.exports.reactPanel.editor;
 
       if (PanelEditor) {
-        return <PanelEditor options={this.getReactPanelOptions()} updateOptions={this.onPanelOptionsChanged} />;
+        return <PanelEditor options={this.getReactPanelOptions()} onOptionsChange={this.onPanelOptionsChanged} />;
       }
     }
 

+ 7 - 4
public/app/plugins/panel/gauge/GaugeOptionsBox.tsx

@@ -10,14 +10,17 @@ import { GaugeOptions } from './types';
 
 export class GaugeOptionsBox extends PureComponent<PanelEditorProps<GaugeOptions>> {
   onToggleThresholdLabels = () =>
-    this.props.updateOptions({ ...this.props.options, showThresholdLabels: !this.props.options.showThresholdLabels });
+    this.props.onOptionsChange({ ...this.props.options, showThresholdLabels: !this.props.options.showThresholdLabels });
 
   onToggleThresholdMarkers = () =>
-    this.props.updateOptions({ ...this.props.options, showThresholdMarkers: !this.props.options.showThresholdMarkers });
+    this.props.onOptionsChange({
+      ...this.props.options,
+      showThresholdMarkers: !this.props.options.showThresholdMarkers,
+    });
 
-  onMinValueChange = ({ target }) => this.props.updateOptions({ ...this.props.options, minValue: target.value });
+  onMinValueChange = ({ target }) => this.props.onOptionsChange({ ...this.props.options, minValue: target.value });
 
-  onMaxValueChange = ({ target }) => this.props.updateOptions({ ...this.props.options, maxValue: target.value });
+  onMaxValueChange = ({ target }) => this.props.onOptionsChange({ ...this.props.options, maxValue: target.value });
 
   render() {
     const { options } = this.props;

+ 5 - 5
public/app/plugins/panel/gauge/GaugePanelEditor.tsx

@@ -14,31 +14,31 @@ import { GaugeOptions, SingleStatValueOptions } from './types';
 
 export class GaugePanelEditor extends PureComponent<PanelEditorProps<GaugeOptions>> {
   onThresholdsChanged = (thresholds: Threshold[]) =>
-    this.props.updateOptions({
+    this.props.onOptionsChange({
       ...this.props.options,
       thresholds,
     });
 
   onValueMappingsChanged = (valueMappings: ValueMapping[]) =>
-    this.props.updateOptions({
+    this.props.onOptionsChange({
       ...this.props.options,
       valueMappings,
     });
 
   onValueOptionsChanged = (valueOptions: SingleStatValueOptions) =>
-    this.props.updateOptions({
+    this.props.onOptionsChange({
       ...this.props.options,
       valueOptions,
     });
 
   render() {
-    const { updateOptions, options } = this.props;
+    const { onOptionsChange, options } = this.props;
 
     return (
       <>
         <PanelOptionsGrid>
           <SingleStatValueEditor onChange={this.onValueOptionsChanged} options={options.valueOptions} />
-          <GaugeOptionsBox updateOptions={updateOptions} options={options} />
+          <GaugeOptionsBox onOptionsChange={onOptionsChange} options={options} />
           <ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={options.thresholds} />
         </PanelOptionsGrid>
 

+ 3 - 3
public/app/plugins/panel/graph2/GraphPanelEditor.tsx

@@ -8,15 +8,15 @@ import { Options } from './types';
 
 export class GraphPanelEditor extends PureComponent<PanelEditorProps<Options>> {
   onToggleLines = () => {
-    this.props.updateOptions({ ...this.props.options, showLines: !this.props.options.showLines });
+    this.props.onOptionsChange({ ...this.props.options, showLines: !this.props.options.showLines });
   };
 
   onToggleBars = () => {
-    this.props.updateOptions({ ...this.props.options, showBars: !this.props.options.showBars });
+    this.props.onOptionsChange({ ...this.props.options, showBars: !this.props.options.showBars });
   };
 
   onTogglePoints = () => {
-    this.props.updateOptions({ ...this.props.options, showPoints: !this.props.options.showPoints });
+    this.props.onOptionsChange({ ...this.props.options, showPoints: !this.props.options.showPoints });
   };
 
   render() {