PluginsErrorsInfo.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { PluginErrorCode, PluginSignatureStatus } from '@grafana/data';
  4. import { selectors } from '@grafana/e2e-selectors';
  5. import { HorizontalGroup, InfoBox, List, PluginSignatureBadge, useTheme } from '@grafana/ui';
  6. import { useGetErrors, useFetchStatus } from '../admin/state/hooks';
  7. export function PluginsErrorsInfo(): React.ReactElement | null {
  8. const errors = useGetErrors();
  9. const { isLoading } = useFetchStatus();
  10. const theme = useTheme();
  11. if (isLoading || errors.length === 0) {
  12. return null;
  13. }
  14. return (
  15. <InfoBox
  16. aria-label={selectors.pages.PluginsList.signatureErrorNotice}
  17. severity="warning"
  18. urlTitle="Read more about plugin signing"
  19. url="https://grafana.com/docs/grafana/latest/plugins/plugin-signatures/"
  20. >
  21. <div>
  22. <p>
  23. Unsigned plugins were found during plugin initialization. Grafana Labs cannot guarantee the integrity of these
  24. plugins. We recommend only using signed plugins.
  25. </p>
  26. The following plugins are disabled and not shown in the list below:
  27. <List
  28. items={errors}
  29. className={css`
  30. list-style-type: circle;
  31. `}
  32. renderItem={(error) => (
  33. <div
  34. className={css`
  35. margin-top: ${theme.spacing.sm};
  36. `}
  37. >
  38. <HorizontalGroup spacing="sm" justify="flex-start" align="center">
  39. <strong>{error.pluginId}</strong>
  40. <PluginSignatureBadge
  41. status={mapPluginErrorCodeToSignatureStatus(error.errorCode)}
  42. className={css`
  43. margin-top: 0;
  44. `}
  45. />
  46. </HorizontalGroup>
  47. </div>
  48. )}
  49. />
  50. </div>
  51. </InfoBox>
  52. );
  53. }
  54. function mapPluginErrorCodeToSignatureStatus(code: PluginErrorCode) {
  55. switch (code) {
  56. case PluginErrorCode.invalidSignature:
  57. return PluginSignatureStatus.invalid;
  58. case PluginErrorCode.missingSignature:
  59. return PluginSignatureStatus.missing;
  60. case PluginErrorCode.modifiedSignature:
  61. return PluginSignatureStatus.modified;
  62. default:
  63. return PluginSignatureStatus.missing;
  64. }
  65. }