1// Libraries 2import React, { PureComponent, ReactNode } from 'react'; 3 4// Types 5import { AppNotificationSeverity } from 'app/types'; 6import { Alert } from '@grafana/ui'; 7import { PanelProps, PanelPlugin, PluginType, PanelPluginMeta } from '@grafana/data'; 8 9interface Props { 10 title: string; 11 text?: ReactNode; 12} 13 14class PanelPluginError extends PureComponent<Props> { 15 constructor(props: Props) { 16 super(props); 17 } 18 19 render() { 20 const style = { 21 display: 'flex', 22 alignItems: 'center', 23 justifyContent: 'center', 24 height: '100%', 25 }; 26 27 return ( 28 <div style={style}> 29 <Alert severity={AppNotificationSeverity.Error} {...this.props} /> 30 </div> 31 ); 32 } 33} 34 35export function getPanelPluginLoadError(meta: PanelPluginMeta, err: any): PanelPlugin { 36 const LoadError = class LoadError extends PureComponent<PanelProps> { 37 render() { 38 const text = ( 39 <> 40 Check the server startup logs for more information. <br /> 41 If this plugin was loaded from Git, then make sure it was compiled. 42 </> 43 ); 44 return <PanelPluginError title={`Error loading: ${meta.id}`} text={text} />; 45 } 46 }; 47 const plugin = new PanelPlugin(LoadError); 48 plugin.meta = meta; 49 plugin.loadError = true; 50 return plugin; 51} 52 53export function getPanelPluginNotFound(id: string, silent?: boolean): PanelPlugin { 54 const NotFound = class NotFound extends PureComponent<PanelProps> { 55 render() { 56 return <PanelPluginError title={`Panel plugin not found: ${id}`} />; 57 } 58 }; 59 60 const plugin = new PanelPlugin(silent ? () => null : NotFound); 61 62 plugin.meta = { 63 id: id, 64 name: id, 65 sort: 100, 66 type: PluginType.panel, 67 module: '', 68 baseUrl: '', 69 info: { 70 author: { 71 name: '', 72 }, 73 description: '', 74 links: [], 75 logos: { 76 large: '', 77 small: 'public/img/grafana_icon.svg', 78 }, 79 screenshots: [], 80 updated: '', 81 version: '', 82 }, 83 }; 84 return plugin; 85} 86