PanelPluginError.tsx 1.9 KB

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