PanelPluginError.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 LoadError = class LoadError 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(LoadError);
  44. plugin.meta = meta;
  45. plugin.loadError = true;
  46. return plugin;
  47. }
  48. export function getPanelPluginNotFound(id: string): PanelPlugin {
  49. const NotFound = class NotFound extends PureComponent<PanelProps> {
  50. render() {
  51. return <PanelPluginError title={`Panel plugin not found: ${id}`} />;
  52. }
  53. };
  54. const plugin = new PanelPlugin(NotFound);
  55. plugin.meta = {
  56. id: id,
  57. name: id,
  58. sort: 100,
  59. type: PluginType.panel,
  60. module: '',
  61. baseUrl: '',
  62. info: {
  63. author: {
  64. name: '',
  65. },
  66. description: '',
  67. links: [],
  68. logos: {
  69. large: '',
  70. small: '',
  71. },
  72. screenshots: [],
  73. updated: '',
  74. version: '',
  75. },
  76. };
  77. return plugin;
  78. }