grafana/public/app/features/panel/components/PanelPluginError.tsx

86 lines
2.0 KiB
TypeScript
Raw Normal View History

// Libraries
import React, { PureComponent, ReactNode } from 'react';
// Types
import { AppNotificationSeverity } from 'app/types';
import { Alert } from '@grafana/ui';
import { PanelProps, PanelPlugin, PluginType, PanelPluginMeta } from '@grafana/data';
2018-11-12 10:54:44 -06:00
interface Props {
title: string;
text?: ReactNode;
2018-11-12 10:54:44 -06:00
}
class PanelPluginError extends PureComponent<Props> {
constructor(props: Props) {
2018-11-12 10:54:44 -06:00
super(props);
}
render() {
2018-11-13 00:54:02 -06:00
const style = {
display: 'flex',
2018-11-13 01:40:42 -06:00
alignItems: 'center',
2019-02-15 05:55:35 -06:00
justifyContent: 'center',
2018-11-13 00:54:02 -06:00
height: '100%',
};
return (
<div style={style}>
<Alert severity={AppNotificationSeverity.Error} {...this.props} />
2018-11-13 00:54:02 -06:00
</div>
);
2018-11-12 10:54:44 -06:00
}
}
2018-11-13 00:54:02 -06:00
export function getPanelPluginLoadError(meta: PanelPluginMeta, err: any): PanelPlugin {
const LoadError = class LoadError extends PureComponent<PanelProps> {
render() {
const text = (
<>
Check the server startup logs for more information. <br />
If this plugin was loaded from Git, then make sure it was compiled.
</>
);
return <PanelPluginError title={`Error loading: ${meta.id}`} text={text} />;
}
};
const plugin = new PanelPlugin(LoadError);
plugin.meta = meta;
plugin.loadError = true;
return plugin;
}
export function getPanelPluginNotFound(id: string, silent?: boolean): PanelPlugin {
2018-11-13 00:54:02 -06:00
const NotFound = class NotFound extends PureComponent<PanelProps> {
render() {
return <PanelPluginError title={`Panel plugin not found: ${id}`} />;
2018-11-13 00:54:02 -06:00
}
};
const plugin = new PanelPlugin(silent ? () => null : NotFound);
plugin.meta = {
2018-11-13 00:54:02 -06:00
id: id,
name: id,
sort: 100,
type: PluginType.panel,
2018-11-13 00:54:02 -06:00
module: '',
baseUrl: '',
info: {
author: {
name: '',
},
description: '',
links: [],
logos: {
large: '',
small: 'public/img/grafana_icon.svg',
},
screenshots: [],
updated: '',
version: '',
2018-11-13 00:54:02 -06:00
},
};
return plugin;
2018-11-13 00:54:02 -06:00
}