From 82be27a42a50c303a6632155d2164f20b5f741e8 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 22 Mar 2019 13:12:35 -0700 Subject: [PATCH] remove panel plugin setters --- packages/grafana-ui/src/types/panel.ts | 30 +++---------------- .../dashboard/dashgrid/DashboardPanel.tsx | 4 +-- public/app/plugins/panel/bargauge/module.tsx | 7 ++--- public/app/plugins/panel/gauge/module.tsx | 10 +++---- public/app/plugins/panel/graph2/module.tsx | 7 +++-- public/app/plugins/panel/graph2/types.ts | 6 ++++ public/app/plugins/panel/piechart/module.tsx | 5 ++-- .../app/plugins/panel/singlestat2/module.tsx | 11 ++++--- public/app/plugins/panel/table2/module.tsx | 5 ++-- public/app/plugins/panel/text2/module.tsx | 10 +++---- 10 files changed, 37 insertions(+), 58 deletions(-) diff --git a/packages/grafana-ui/src/types/panel.ts b/packages/grafana-ui/src/types/panel.ts index bd535655551..9341ef376e2 100644 --- a/packages/grafana-ui/src/types/panel.ts +++ b/packages/grafana-ui/src/types/panel.ts @@ -24,7 +24,7 @@ export interface PanelEditorProps { /** * Called when a panel is first loaded with existing options */ -export type PanelMigrationHook = (options: Partial) => Partial; +export type PanelMigrationHook = (options: any) => Partial; /** * Called before a panel is initalized @@ -40,35 +40,13 @@ export class ReactPanelPlugin { editor?: ComponentClass>; defaults?: TOptions; - panelMigrationHook?: PanelMigrationHook; - panelTypeChangedHook?: PanelTypeChangedHook; + onPanelMigration?: PanelMigrationHook; + onPanelTypeChanged?: PanelTypeChangedHook; - constructor(panel: ComponentClass>) { + constructor(panel: ComponentClass>, defaults?: TOptions) { this.panel = panel; - } - - setEditor(editor: ComponentClass>) { - this.editor = editor; - } - - setDefaults(defaults: TOptions) { this.defaults = defaults; } - - /** - * Called when the panel first loaded with - */ - setPanelMigrationHook(v: PanelMigrationHook) { - this.panelMigrationHook = v; - } - - /** - * Called when the visualization changes. - * Lets you keep whatever settings made sense in the previous panel - */ - setPanelTypeChangedHook(v: PanelTypeChangedHook) { - this.panelTypeChangedHook = v; - } } export interface PanelSize { diff --git a/public/app/features/dashboard/dashgrid/DashboardPanel.tsx b/public/app/features/dashboard/dashgrid/DashboardPanel.tsx index 243380c617e..e2111e4892d 100644 --- a/public/app/features/dashboard/dashgrid/DashboardPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardPanel.tsx @@ -94,12 +94,12 @@ export class DashboardPanel extends PureComponent { } else { let hook: PanelTypeChangedHook | null = null; if (plugin.exports.reactPanel) { - hook = plugin.exports.reactPanel.panelTypeChangedHook; + hook = plugin.exports.reactPanel.onPanelTypeChanged; } panel.changeType(pluginId, hook); } } else if (plugin.exports && plugin.exports.reactPanel && panel.options) { - const hook = plugin.exports.reactPanel.panelMigrationHook; + const hook = plugin.exports.reactPanel.onPanelMigration; if (hook) { panel.options = hook(panel.options); } diff --git a/public/app/plugins/panel/bargauge/module.tsx b/public/app/plugins/panel/bargauge/module.tsx index 3c46adeb4f9..d921fae236a 100644 --- a/public/app/plugins/panel/bargauge/module.tsx +++ b/public/app/plugins/panel/bargauge/module.tsx @@ -5,8 +5,7 @@ import { BarGaugePanelEditor } from './BarGaugePanelEditor'; import { BarGaugeOptions, defaults } from './types'; import { singleStatBaseOptionsCheck } from '../singlestat2/module'; -export const reactPanel = new ReactPanelPlugin(BarGaugePanel); +export const reactPanel = new ReactPanelPlugin(BarGaugePanel, defaults); -reactPanel.setEditor(BarGaugePanelEditor); -reactPanel.setDefaults(defaults); -reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck); +reactPanel.editor = BarGaugePanelEditor; +reactPanel.onPanelTypeChanged = singleStatBaseOptionsCheck; diff --git a/public/app/plugins/panel/gauge/module.tsx b/public/app/plugins/panel/gauge/module.tsx index 340af06a080..54c1465372b 100644 --- a/public/app/plugins/panel/gauge/module.tsx +++ b/public/app/plugins/panel/gauge/module.tsx @@ -3,10 +3,10 @@ import { ReactPanelPlugin } from '@grafana/ui'; import { GaugePanelEditor } from './GaugePanelEditor'; import { GaugePanel } from './GaugePanel'; import { GaugeOptions, defaults } from './types'; -import { singleStatBaseOptionsCheck } from '../singlestat2/module'; +import { singleStatBaseOptionsCheck, singleStatMigrationCheck } from '../singlestat2/module'; -export const reactPanel = new ReactPanelPlugin(GaugePanel); +export const reactPanel = new ReactPanelPlugin(GaugePanel, defaults); -reactPanel.setEditor(GaugePanelEditor); -reactPanel.setDefaults(defaults); -reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck); +reactPanel.editor = GaugePanelEditor; +reactPanel.onPanelTypeChanged = singleStatBaseOptionsCheck; +reactPanel.onPanelMigration = singleStatMigrationCheck; diff --git a/public/app/plugins/panel/graph2/module.tsx b/public/app/plugins/panel/graph2/module.tsx index 6dd6d4a77c4..67ed1ae6c7a 100644 --- a/public/app/plugins/panel/graph2/module.tsx +++ b/public/app/plugins/panel/graph2/module.tsx @@ -2,7 +2,8 @@ import { ReactPanelPlugin } from '@grafana/ui'; import { GraphPanelEditor } from './GraphPanelEditor'; import { GraphPanel } from './GraphPanel'; -import { Options } from './types'; +import { Options, defaults } from './types'; -export const reactPanel = new ReactPanelPlugin(GraphPanel); -reactPanel.setEditor(GraphPanelEditor); +export const reactPanel = new ReactPanelPlugin(GraphPanel, defaults); + +reactPanel.editor = GraphPanelEditor; diff --git a/public/app/plugins/panel/graph2/types.ts b/public/app/plugins/panel/graph2/types.ts index b9baaa09cd7..1f6e9c093dd 100644 --- a/public/app/plugins/panel/graph2/types.ts +++ b/public/app/plugins/panel/graph2/types.ts @@ -3,3 +3,9 @@ export interface Options { showLines: boolean; showPoints: boolean; } + +export const defaults: Options = { + showBars: false, + showLines: true, + showPoints: false, +}; diff --git a/public/app/plugins/panel/piechart/module.tsx b/public/app/plugins/panel/piechart/module.tsx index 3e0ef90dc6c..8336cd6803f 100644 --- a/public/app/plugins/panel/piechart/module.tsx +++ b/public/app/plugins/panel/piechart/module.tsx @@ -4,7 +4,6 @@ import PieChartPanelEditor from './PieChartPanelEditor'; import { PieChartPanel } from './PieChartPanel'; import { PieChartOptions, defaults } from './types'; -export const reactPanel = new ReactPanelPlugin(PieChartPanel); +export const reactPanel = new ReactPanelPlugin(PieChartPanel, defaults); -reactPanel.setEditor(PieChartPanelEditor); -reactPanel.setDefaults(defaults); +reactPanel.editor = PieChartPanelEditor; diff --git a/public/app/plugins/panel/singlestat2/module.tsx b/public/app/plugins/panel/singlestat2/module.tsx index 4b2c27c360a..42142c0f673 100644 --- a/public/app/plugins/panel/singlestat2/module.tsx +++ b/public/app/plugins/panel/singlestat2/module.tsx @@ -4,8 +4,6 @@ import { SingleStatPanel } from './SingleStatPanel'; import cloneDeep from 'lodash/cloneDeep'; import { SingleStatEditor } from './SingleStatEditor'; -export const reactPanel = new ReactPanelPlugin(SingleStatPanel); - const optionsToKeep = ['valueOptions', 'stat', 'maxValue', 'maxValue', 'thresholds', 'valueMappings']; export const singleStatBaseOptionsCheck = ( @@ -33,7 +31,8 @@ export const singleStatMigrationCheck = (options: Partial return options; }; -reactPanel.setEditor(SingleStatEditor); -reactPanel.setDefaults(defaults); -reactPanel.setPanelTypeChangedHook(singleStatBaseOptionsCheck); -reactPanel.setPanelMigrationHook(singleStatMigrationCheck); +export const reactPanel = new ReactPanelPlugin(SingleStatPanel, defaults); + +reactPanel.editor = SingleStatEditor; +reactPanel.onPanelTypeChanged = singleStatBaseOptionsCheck; +reactPanel.onPanelMigration = singleStatMigrationCheck; diff --git a/public/app/plugins/panel/table2/module.tsx b/public/app/plugins/panel/table2/module.tsx index d93e7911074..56135936540 100644 --- a/public/app/plugins/panel/table2/module.tsx +++ b/public/app/plugins/panel/table2/module.tsx @@ -4,6 +4,5 @@ import { TablePanelEditor } from './TablePanelEditor'; import { TablePanel } from './TablePanel'; import { Options, defaults } from './types'; -export const reactPanel = new ReactPanelPlugin(TablePanel); -reactPanel.setEditor(TablePanelEditor); -reactPanel.setDefaults(defaults); +export const reactPanel = new ReactPanelPlugin(TablePanel, defaults); +reactPanel.editor = TablePanelEditor; diff --git a/public/app/plugins/panel/text2/module.tsx b/public/app/plugins/panel/text2/module.tsx index b2e3057de34..d40071c983d 100644 --- a/public/app/plugins/panel/text2/module.tsx +++ b/public/app/plugins/panel/text2/module.tsx @@ -4,14 +4,12 @@ import { TextPanelEditor } from './TextPanelEditor'; import { TextPanel } from './TextPanel'; import { TextOptions, defaults } from './types'; -export const reactPanel = new ReactPanelPlugin(TextPanel); +export const reactPanel = new ReactPanelPlugin(TextPanel, defaults); -reactPanel.setEditor(TextPanelEditor); -reactPanel.setDefaults(defaults); -reactPanel.setPanelTypeChangedHook((options: TextOptions, prevPluginId: string, prevOptions: any) => { +reactPanel.editor = TextPanelEditor; +reactPanel.onPanelTypeChanged = (options: TextOptions, prevPluginId: string, prevOptions: any) => { if (prevPluginId === 'text') { return prevOptions as TextOptions; } - return options; -}); +};