mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
remove panel plugin setters
This commit is contained in:
parent
0f0f76b602
commit
82be27a42a
@ -24,7 +24,7 @@ export interface PanelEditorProps<T = any> {
|
|||||||
/**
|
/**
|
||||||
* Called when a panel is first loaded with existing options
|
* Called when a panel is first loaded with existing options
|
||||||
*/
|
*/
|
||||||
export type PanelMigrationHook<TOptions = any> = (options: Partial<TOptions>) => Partial<TOptions>;
|
export type PanelMigrationHook<TOptions = any> = (options: any) => Partial<TOptions>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before a panel is initalized
|
* Called before a panel is initalized
|
||||||
@ -40,35 +40,13 @@ export class ReactPanelPlugin<TOptions = any> {
|
|||||||
editor?: ComponentClass<PanelEditorProps<TOptions>>;
|
editor?: ComponentClass<PanelEditorProps<TOptions>>;
|
||||||
defaults?: TOptions;
|
defaults?: TOptions;
|
||||||
|
|
||||||
panelMigrationHook?: PanelMigrationHook<TOptions>;
|
onPanelMigration?: PanelMigrationHook<TOptions>;
|
||||||
panelTypeChangedHook?: PanelTypeChangedHook<TOptions>;
|
onPanelTypeChanged?: PanelTypeChangedHook<TOptions>;
|
||||||
|
|
||||||
constructor(panel: ComponentClass<PanelProps<TOptions>>) {
|
constructor(panel: ComponentClass<PanelProps<TOptions>>, defaults?: TOptions) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
}
|
|
||||||
|
|
||||||
setEditor(editor: ComponentClass<PanelEditorProps<TOptions>>) {
|
|
||||||
this.editor = editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
setDefaults(defaults: TOptions) {
|
|
||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the panel first loaded with
|
|
||||||
*/
|
|
||||||
setPanelMigrationHook(v: PanelMigrationHook<TOptions>) {
|
|
||||||
this.panelMigrationHook = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the visualization changes.
|
|
||||||
* Lets you keep whatever settings made sense in the previous panel
|
|
||||||
*/
|
|
||||||
setPanelTypeChangedHook(v: PanelTypeChangedHook<TOptions>) {
|
|
||||||
this.panelTypeChangedHook = v;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PanelSize {
|
export interface PanelSize {
|
||||||
|
@ -94,12 +94,12 @@ export class DashboardPanel extends PureComponent<Props, State> {
|
|||||||
} else {
|
} else {
|
||||||
let hook: PanelTypeChangedHook | null = null;
|
let hook: PanelTypeChangedHook | null = null;
|
||||||
if (plugin.exports.reactPanel) {
|
if (plugin.exports.reactPanel) {
|
||||||
hook = plugin.exports.reactPanel.panelTypeChangedHook;
|
hook = plugin.exports.reactPanel.onPanelTypeChanged;
|
||||||
}
|
}
|
||||||
panel.changeType(pluginId, hook);
|
panel.changeType(pluginId, hook);
|
||||||
}
|
}
|
||||||
} else if (plugin.exports && plugin.exports.reactPanel && panel.options) {
|
} else if (plugin.exports && plugin.exports.reactPanel && panel.options) {
|
||||||
const hook = plugin.exports.reactPanel.panelMigrationHook;
|
const hook = plugin.exports.reactPanel.onPanelMigration;
|
||||||
if (hook) {
|
if (hook) {
|
||||||
panel.options = hook(panel.options);
|
panel.options = hook(panel.options);
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@ import { BarGaugePanelEditor } from './BarGaugePanelEditor';
|
|||||||
import { BarGaugeOptions, defaults } from './types';
|
import { BarGaugeOptions, defaults } from './types';
|
||||||
import { singleStatBaseOptionsCheck } from '../singlestat2/module';
|
import { singleStatBaseOptionsCheck } from '../singlestat2/module';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<BarGaugeOptions>(BarGaugePanel);
|
export const reactPanel = new ReactPanelPlugin<BarGaugeOptions>(BarGaugePanel, defaults);
|
||||||
|
|
||||||
reactPanel.setEditor(BarGaugePanelEditor);
|
reactPanel.editor = BarGaugePanelEditor;
|
||||||
reactPanel.setDefaults(defaults);
|
reactPanel.onPanelTypeChanged = singleStatBaseOptionsCheck;
|
||||||
reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck);
|
|
||||||
|
@ -3,10 +3,10 @@ import { ReactPanelPlugin } from '@grafana/ui';
|
|||||||
import { GaugePanelEditor } from './GaugePanelEditor';
|
import { GaugePanelEditor } from './GaugePanelEditor';
|
||||||
import { GaugePanel } from './GaugePanel';
|
import { GaugePanel } from './GaugePanel';
|
||||||
import { GaugeOptions, defaults } from './types';
|
import { GaugeOptions, defaults } from './types';
|
||||||
import { singleStatBaseOptionsCheck } from '../singlestat2/module';
|
import { singleStatBaseOptionsCheck, singleStatMigrationCheck } from '../singlestat2/module';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<GaugeOptions>(GaugePanel);
|
export const reactPanel = new ReactPanelPlugin<GaugeOptions>(GaugePanel, defaults);
|
||||||
|
|
||||||
reactPanel.setEditor(GaugePanelEditor);
|
reactPanel.editor = GaugePanelEditor;
|
||||||
reactPanel.setDefaults(defaults);
|
reactPanel.onPanelTypeChanged = singleStatBaseOptionsCheck;
|
||||||
reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck);
|
reactPanel.onPanelMigration = singleStatMigrationCheck;
|
||||||
|
@ -2,7 +2,8 @@ import { ReactPanelPlugin } from '@grafana/ui';
|
|||||||
|
|
||||||
import { GraphPanelEditor } from './GraphPanelEditor';
|
import { GraphPanelEditor } from './GraphPanelEditor';
|
||||||
import { GraphPanel } from './GraphPanel';
|
import { GraphPanel } from './GraphPanel';
|
||||||
import { Options } from './types';
|
import { Options, defaults } from './types';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<Options>(GraphPanel);
|
export const reactPanel = new ReactPanelPlugin<Options>(GraphPanel, defaults);
|
||||||
reactPanel.setEditor(GraphPanelEditor);
|
|
||||||
|
reactPanel.editor = GraphPanelEditor;
|
||||||
|
@ -3,3 +3,9 @@ export interface Options {
|
|||||||
showLines: boolean;
|
showLines: boolean;
|
||||||
showPoints: boolean;
|
showPoints: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaults: Options = {
|
||||||
|
showBars: false,
|
||||||
|
showLines: true,
|
||||||
|
showPoints: false,
|
||||||
|
};
|
||||||
|
@ -4,7 +4,6 @@ import PieChartPanelEditor from './PieChartPanelEditor';
|
|||||||
import { PieChartPanel } from './PieChartPanel';
|
import { PieChartPanel } from './PieChartPanel';
|
||||||
import { PieChartOptions, defaults } from './types';
|
import { PieChartOptions, defaults } from './types';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<PieChartOptions>(PieChartPanel);
|
export const reactPanel = new ReactPanelPlugin<PieChartOptions>(PieChartPanel, defaults);
|
||||||
|
|
||||||
reactPanel.setEditor(PieChartPanelEditor);
|
reactPanel.editor = PieChartPanelEditor;
|
||||||
reactPanel.setDefaults(defaults);
|
|
||||||
|
@ -4,8 +4,6 @@ import { SingleStatPanel } from './SingleStatPanel';
|
|||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import { SingleStatEditor } from './SingleStatEditor';
|
import { SingleStatEditor } from './SingleStatEditor';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<SingleStatOptions>(SingleStatPanel);
|
|
||||||
|
|
||||||
const optionsToKeep = ['valueOptions', 'stat', 'maxValue', 'maxValue', 'thresholds', 'valueMappings'];
|
const optionsToKeep = ['valueOptions', 'stat', 'maxValue', 'maxValue', 'thresholds', 'valueMappings'];
|
||||||
|
|
||||||
export const singleStatBaseOptionsCheck = (
|
export const singleStatBaseOptionsCheck = (
|
||||||
@ -33,7 +31,8 @@ export const singleStatMigrationCheck = (options: Partial<SingleStatBaseOptions>
|
|||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
reactPanel.setEditor(SingleStatEditor);
|
export const reactPanel = new ReactPanelPlugin<SingleStatOptions>(SingleStatPanel, defaults);
|
||||||
reactPanel.setDefaults(defaults);
|
|
||||||
reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck);
|
reactPanel.editor = SingleStatEditor;
|
||||||
reactPanel.setPanelMigrationHook(singleStatMigrationCheck);
|
reactPanel.onPanelTypeChanged = singleStatBaseOptionsCheck;
|
||||||
|
reactPanel.onPanelMigration = singleStatMigrationCheck;
|
||||||
|
@ -4,6 +4,5 @@ import { TablePanelEditor } from './TablePanelEditor';
|
|||||||
import { TablePanel } from './TablePanel';
|
import { TablePanel } from './TablePanel';
|
||||||
import { Options, defaults } from './types';
|
import { Options, defaults } from './types';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<Options>(TablePanel);
|
export const reactPanel = new ReactPanelPlugin<Options>(TablePanel, defaults);
|
||||||
reactPanel.setEditor(TablePanelEditor);
|
reactPanel.editor = TablePanelEditor;
|
||||||
reactPanel.setDefaults(defaults);
|
|
||||||
|
@ -4,14 +4,12 @@ import { TextPanelEditor } from './TextPanelEditor';
|
|||||||
import { TextPanel } from './TextPanel';
|
import { TextPanel } from './TextPanel';
|
||||||
import { TextOptions, defaults } from './types';
|
import { TextOptions, defaults } from './types';
|
||||||
|
|
||||||
export const reactPanel = new ReactPanelPlugin<TextOptions>(TextPanel);
|
export const reactPanel = new ReactPanelPlugin<TextOptions>(TextPanel, defaults);
|
||||||
|
|
||||||
reactPanel.setEditor(TextPanelEditor);
|
reactPanel.editor = TextPanelEditor;
|
||||||
reactPanel.setDefaults(defaults);
|
reactPanel.onPanelTypeChanged = (options: TextOptions, prevPluginId: string, prevOptions: any) => {
|
||||||
reactPanel.setPanelTypeChangedHook((options: TextOptions, prevPluginId: string, prevOptions: any) => {
|
|
||||||
if (prevPluginId === 'text') {
|
if (prevPluginId === 'text') {
|
||||||
return prevOptions as TextOptions;
|
return prevOptions as TextOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
});
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user