check types better

This commit is contained in:
ryan 2019-03-13 13:11:49 -07:00
parent 0c086795e3
commit 68f7e046ab
3 changed files with 6 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import { PanelEditor } from '../panel_editor/PanelEditor';
import { PanelModel, DashboardModel } from '../state'; import { PanelModel, DashboardModel } from '../state';
import { PanelPlugin } from 'app/types'; import { PanelPlugin } from 'app/types';
import { PanelResizer } from './PanelResizer'; import { PanelResizer } from './PanelResizer';
import { PanelTypeChangedHook } from '@grafana/ui';
export interface Props { export interface Props {
panel: PanelModel; panel: PanelModel;
@ -91,8 +92,11 @@ export class DashboardPanel extends PureComponent<Props, State> {
this.props.panel.changeType(pluginId); this.props.panel.changeType(pluginId);
} else { } else {
const { reactPanel } = plugin.exports; let hook: PanelTypeChangedHook | null = null;
panel.changeType(pluginId, reactPanel.panelTypeChangedHook); if (plugin.exports.reactPanel) {
hook = plugin.exports.reactPanel.panelTypeChangedHook;
}
panel.changeType(pluginId, hook);
} }
} }

View File

@ -9,8 +9,6 @@ export const reactPanel = new ReactPanelPlugin<BarGaugeOptions>(BarGaugePanel);
reactPanel.setEditor(BarGaugePanelEditor); reactPanel.setEditor(BarGaugePanelEditor);
reactPanel.setDefaults(defaults); reactPanel.setDefaults(defaults);
reactPanel.setPanelTypeChangedHook((options: BarGaugeOptions, prevPluginId?: string, prevOptions?: any) => { reactPanel.setPanelTypeChangedHook((options: BarGaugeOptions, prevPluginId?: string, prevOptions?: any) => {
console.log('BAR Gauge', options, prevPluginId, prevOptions);
if (prevOptions && prevOptions.valueOptions) { if (prevOptions && prevOptions.valueOptions) {
options.valueOptions = prevOptions.valueOptions; options.valueOptions = prevOptions.valueOptions;
options.thresholds = prevOptions.thresholds; options.thresholds = prevOptions.thresholds;

View File

@ -9,8 +9,6 @@ export const reactPanel = new ReactPanelPlugin<GaugeOptions>(GaugePanel);
reactPanel.setEditor(GaugePanelEditor); reactPanel.setEditor(GaugePanelEditor);
reactPanel.setDefaults(defaults); reactPanel.setDefaults(defaults);
reactPanel.setPanelTypeChangedHook((options: GaugeOptions, prevPluginId?: string, prevOptions?: any) => { reactPanel.setPanelTypeChangedHook((options: GaugeOptions, prevPluginId?: string, prevOptions?: any) => {
console.log('BAR Gauge', options, prevPluginId, prevOptions);
if (prevOptions && prevOptions.valueOptions) { if (prevOptions && prevOptions.valueOptions) {
options.valueOptions = prevOptions.valueOptions; options.valueOptions = prevOptions.valueOptions;
options.thresholds = prevOptions.thresholds; options.thresholds = prevOptions.thresholds;