grafana/public/app/features/panel/components/PanelPluginError.tsx
Torkel Ödegaard d62ca1283c
PanelState: Introduce a new separate redux panel state not keyed by panel.id (#40302)
* Initial pass to move panel state to it's own, and make it by key not panel.id

* Progress

* Not making much progress, having panel.key be mutable is causing a lot of issues

* Think this is starting to work

* Began fixing tests

* Add selector

* Bug fixes and changes to cleanup, and fixing all flicking when switching library panels

* Removed console.log

* fixes after merge

* fixing tests

* fixing tests

* Added new test for changePlugin thunk
2021-10-13 08:53:36 +02:00

86 lines
2.0 KiB
TypeScript

// 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';
interface Props {
title: string;
text?: ReactNode;
}
class PanelPluginError extends PureComponent<Props> {
constructor(props: Props) {
super(props);
}
render() {
const style = {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
};
return (
<div style={style}>
<Alert severity={AppNotificationSeverity.Error} {...this.props} />
</div>
);
}
}
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 {
const NotFound = class NotFound extends PureComponent<PanelProps> {
render() {
return <PanelPluginError title={`Panel plugin not found: ${id}`} />;
}
};
const plugin = new PanelPlugin(silent ? () => null : NotFound);
plugin.meta = {
id: id,
name: id,
sort: 100,
type: PluginType.panel,
module: '',
baseUrl: '',
info: {
author: {
name: '',
},
description: '',
links: [],
logos: {
large: '',
small: 'public/img/grafana_icon.svg',
},
screenshots: [],
updated: '',
version: '',
},
};
return plugin;
}