PluginSignatureDetailsBadge.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { css } from '@emotion/css';
  2. import { capitalize } from 'lodash';
  3. import React from 'react';
  4. import { GrafanaTheme2, PluginSignatureType } from '@grafana/data';
  5. import { useStyles2, Icon, Badge, IconName } from '@grafana/ui';
  6. const SIGNATURE_ICONS: Record<string, IconName> = {
  7. [PluginSignatureType.grafana]: 'grafana',
  8. [PluginSignatureType.commercial]: 'shield',
  9. [PluginSignatureType.community]: 'shield',
  10. DEFAULT: 'shield-exclamation',
  11. };
  12. type Props = {
  13. signatureType?: PluginSignatureType;
  14. signatureOrg?: string;
  15. };
  16. // Shows more information about a valid signature
  17. export function PluginSignatureDetailsBadge({ signatureType, signatureOrg = '' }: Props): React.ReactElement | null {
  18. const styles = useStyles2(getStyles);
  19. if (!signatureType && !signatureOrg) {
  20. return null;
  21. }
  22. const signatureTypeText = signatureType === PluginSignatureType.grafana ? 'Grafana Labs' : capitalize(signatureType);
  23. const signatureIcon = SIGNATURE_ICONS[signatureType || ''] || SIGNATURE_ICONS.DEFAULT;
  24. return (
  25. <>
  26. <DetailsBadge>
  27. <strong className={styles.strong}>Level:&nbsp;</strong>
  28. <Icon size="xs" name={signatureIcon} />
  29. &nbsp;
  30. {signatureTypeText}
  31. </DetailsBadge>
  32. <DetailsBadge>
  33. <strong className={styles.strong}>Signed by:</strong> {signatureOrg}
  34. </DetailsBadge>
  35. </>
  36. );
  37. }
  38. export const DetailsBadge: React.FC = ({ children }) => {
  39. const styles = useStyles2(getStyles);
  40. return <Badge color="green" className={styles.badge} text={<>{children}</>} />;
  41. };
  42. const getStyles = (theme: GrafanaTheme2) => ({
  43. badge: css`
  44. background-color: ${theme.colors.background.canvas};
  45. border-color: ${theme.colors.border.strong};
  46. color: ${theme.colors.text.secondary};
  47. margin-left: ${theme.spacing()};
  48. `,
  49. strong: css`
  50. color: ${theme.colors.text.primary};
  51. `,
  52. icon: css`
  53. margin-right: ${theme.spacing(0.5)};
  54. `,
  55. });