2018-12-23 02:15:32 -06:00
|
|
|
// Libraries
|
2018-11-12 10:54:44 -06:00
|
|
|
import _ from 'lodash';
|
2019-08-22 00:04:02 -05:00
|
|
|
import React, { PureComponent, ReactNode } from 'react';
|
2018-12-23 02:15:32 -06:00
|
|
|
|
2019-02-15 05:55:35 -06:00
|
|
|
// Components
|
|
|
|
import { AlertBox } from 'app/core/components/AlertBox/AlertBox';
|
|
|
|
|
2018-12-23 02:15:32 -06:00
|
|
|
// Types
|
2019-04-29 10:17:35 -05:00
|
|
|
import { AppNotificationSeverity } from 'app/types';
|
2019-08-22 00:04:02 -05:00
|
|
|
import { PanelProps, PanelPlugin, PluginType, PanelPluginMeta } from '@grafana/ui';
|
2018-11-12 10:54:44 -06:00
|
|
|
|
|
|
|
interface Props {
|
2019-08-22 00:04:02 -05:00
|
|
|
title: string;
|
|
|
|
text?: ReactNode;
|
2018-11-12 10:54:44 -06:00
|
|
|
}
|
|
|
|
|
2019-08-22 00:04:02 -05:00
|
|
|
class PanelPluginError extends PureComponent<Props> {
|
2019-05-01 00:36:46 -05:00
|
|
|
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}>
|
2019-08-22 00:04:02 -05:00
|
|
|
<AlertBox 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
|
|
|
|
2019-08-22 00:04:02 -05:00
|
|
|
export function getPanelPluginLoadError(meta: PanelPluginMeta, err: any): PanelPlugin {
|
2019-08-27 01:43:45 -05:00
|
|
|
const LoadError = class LoadError extends PureComponent<PanelProps> {
|
2019-08-22 00:04:02 -05:00
|
|
|
render() {
|
|
|
|
const text = (
|
|
|
|
<>
|
|
|
|
Check the server startup logs for more information. <br />
|
|
|
|
If this plugin was loaded from git, make sure it was compiled.
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
return <PanelPluginError title={`Error loading: ${meta.id}`} text={text} />;
|
|
|
|
}
|
|
|
|
};
|
2019-08-27 01:43:45 -05:00
|
|
|
const plugin = new PanelPlugin(LoadError);
|
2019-08-22 00:04:02 -05:00
|
|
|
plugin.meta = meta;
|
2019-08-27 01:43:45 -05:00
|
|
|
plugin.loadError = true;
|
2019-08-22 00:04:02 -05:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
2019-05-01 00:36:46 -05:00
|
|
|
export function getPanelPluginNotFound(id: string): PanelPlugin {
|
2018-11-13 00:54:02 -06:00
|
|
|
const NotFound = class NotFound extends PureComponent<PanelProps> {
|
|
|
|
render() {
|
2019-08-22 00:04:02 -05:00
|
|
|
return <PanelPluginError title={`Panel plugin not found: ${id}`} />;
|
2018-11-13 00:54:02 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-01 00:36:46 -05:00
|
|
|
const plugin = new PanelPlugin(NotFound);
|
|
|
|
plugin.meta = {
|
2018-11-13 00:54:02 -06:00
|
|
|
id: id,
|
|
|
|
name: id,
|
|
|
|
sort: 100,
|
2019-04-12 06:46:42 -05:00
|
|
|
type: PluginType.panel,
|
2018-11-13 00:54:02 -06:00
|
|
|
module: '',
|
|
|
|
baseUrl: '',
|
2018-11-13 01:09:12 -06:00
|
|
|
info: {
|
|
|
|
author: {
|
|
|
|
name: '',
|
|
|
|
},
|
|
|
|
description: '',
|
|
|
|
links: [],
|
|
|
|
logos: {
|
|
|
|
large: '',
|
|
|
|
small: '',
|
|
|
|
},
|
|
|
|
screenshots: [],
|
|
|
|
updated: '',
|
|
|
|
version: '',
|
2018-11-13 00:54:02 -06:00
|
|
|
},
|
|
|
|
};
|
2019-05-01 00:36:46 -05:00
|
|
|
return plugin;
|
2018-11-13 00:54:02 -06:00
|
|
|
}
|