PluginDetailsHeaderDependencies.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useStyles2, Icon } from '@grafana/ui';
  5. import { Version, CatalogPlugin, PluginIconName } from '../types';
  6. type Props = {
  7. plugin: CatalogPlugin;
  8. latestCompatibleVersion?: Version;
  9. className?: string;
  10. };
  11. export function PluginDetailsHeaderDependencies({
  12. plugin,
  13. latestCompatibleVersion,
  14. className,
  15. }: Props): React.ReactElement | null {
  16. const styles = useStyles2(getStyles);
  17. const pluginDependencies = plugin.details?.pluginDependencies;
  18. const grafanaDependency = plugin.isInstalled
  19. ? plugin.details?.grafanaDependency
  20. : latestCompatibleVersion?.grafanaDependency || plugin.details?.grafanaDependency;
  21. const hasNoDependencyInfo = !grafanaDependency && (!pluginDependencies || !pluginDependencies.length);
  22. if (hasNoDependencyInfo) {
  23. return null;
  24. }
  25. return (
  26. <div className={className}>
  27. <div className={styles.dependencyTitle}>Dependencies:</div>
  28. {/* Grafana dependency */}
  29. {Boolean(grafanaDependency) && (
  30. <div>
  31. <Icon name="grafana" className={styles.icon} />
  32. Grafana {grafanaDependency}
  33. </div>
  34. )}
  35. {/* Plugin dependencies */}
  36. {pluginDependencies && pluginDependencies.length > 0 && (
  37. <div>
  38. {pluginDependencies.map((p) => {
  39. return (
  40. <span key={p.name}>
  41. <Icon name={PluginIconName[p.type]} className={styles.icon} />
  42. {p.name} {p.version}
  43. </span>
  44. );
  45. })}
  46. </div>
  47. )}
  48. </div>
  49. );
  50. }
  51. export const getStyles = (theme: GrafanaTheme2) => {
  52. return {
  53. dependencyTitle: css`
  54. font-weight: ${theme.typography.fontWeightBold};
  55. margin-right: ${theme.spacing(0.5)};
  56. &::after {
  57. content: '';
  58. padding: 0;
  59. }
  60. `,
  61. icon: css`
  62. color: ${theme.colors.text.secondary};
  63. margin-right: ${theme.spacing(0.5)};
  64. `,
  65. };
  66. };