PanelPluginError.tsx 2.0 KB

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