PreviewsSystemRequirements.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { config } from '@grafana/runtime/src';
  4. import { Alert, useStyles2 } from '@grafana/ui';
  5. export interface Props {
  6. showPreviews?: boolean;
  7. /** On click handler for alert button, mostly used for dismissing the alert */
  8. onRemove?: (event: React.MouseEvent) => void;
  9. topSpacing?: number;
  10. bottomSpacing?: number;
  11. }
  12. const MessageLink = ({ text }: { text: string }) => (
  13. <a
  14. href="https://grafana.com/grafana/plugins/grafana-image-renderer"
  15. target="_blank"
  16. rel="noopener noreferrer"
  17. className="external-link"
  18. >
  19. {text}
  20. </a>
  21. );
  22. const Message = ({ requiredImageRendererPluginVersion }: { requiredImageRendererPluginVersion?: string }) => {
  23. if (requiredImageRendererPluginVersion) {
  24. return (
  25. <>
  26. You must update the <MessageLink text="Grafana image renderer plugin" /> to version{' '}
  27. {requiredImageRendererPluginVersion} to enable dashboard previews. Please contact your Grafana administrator to
  28. update the plugin.
  29. </>
  30. );
  31. }
  32. return (
  33. <>
  34. You must install the <MessageLink text="Grafana image renderer plugin" /> to enable dashboard previews. Please
  35. contact your Grafana administrator to install the plugin.
  36. </>
  37. );
  38. };
  39. export const PreviewsSystemRequirements = ({ showPreviews, onRemove, topSpacing, bottomSpacing }: Props) => {
  40. const styles = useStyles2(getStyles);
  41. const previewsEnabled = config.featureToggles.dashboardPreviews;
  42. const rendererAvailable = config.rendererAvailable;
  43. const {
  44. systemRequirements: { met: systemRequirementsMet, requiredImageRendererPluginVersion },
  45. thumbnailsExist,
  46. } = config.dashboardPreviews;
  47. const arePreviewsEnabled = previewsEnabled && showPreviews;
  48. const areRequirementsMet = (rendererAvailable && systemRequirementsMet) || thumbnailsExist;
  49. const shouldDisplayRequirements = arePreviewsEnabled && !areRequirementsMet;
  50. const title = requiredImageRendererPluginVersion
  51. ? 'Image renderer plugin needs to be updated'
  52. : 'Image renderer plugin not installed';
  53. return (
  54. <>
  55. {shouldDisplayRequirements && (
  56. <div className={styles.wrapper}>
  57. <Alert
  58. className={styles.alert}
  59. topSpacing={topSpacing}
  60. bottomSpacing={bottomSpacing}
  61. severity="info"
  62. title={title}
  63. onRemove={onRemove}
  64. >
  65. <Message requiredImageRendererPluginVersion={requiredImageRendererPluginVersion} />
  66. </Alert>
  67. </div>
  68. )}
  69. </>
  70. );
  71. };
  72. const getStyles = () => {
  73. return {
  74. wrapper: css`
  75. display: flex;
  76. justify-content: center;
  77. `,
  78. alert: css`
  79. max-width: 800px;
  80. `,
  81. };
  82. };