LibraryPanelInfo.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { DateTimeInput, GrafanaTheme } from '@grafana/data';
  4. import { useStyles } from '@grafana/ui';
  5. import { isPanelModelLibraryPanel } from '../../guard';
  6. import { PanelModelWithLibraryPanel } from '../../types';
  7. interface Props {
  8. panel: PanelModelWithLibraryPanel;
  9. formatDate?: (dateString: DateTimeInput, format?: string) => string;
  10. }
  11. export const LibraryPanelInformation: React.FC<Props> = ({ panel, formatDate }) => {
  12. const styles = useStyles(getStyles);
  13. if (!isPanelModelLibraryPanel(panel)) {
  14. return null;
  15. }
  16. return (
  17. <div className={styles.info}>
  18. <div className={styles.libraryPanelInfo}>
  19. {`Used on ${panel.libraryPanel.meta.connectedDashboards} `}
  20. {panel.libraryPanel.meta.connectedDashboards === 1 ? 'dashboard' : 'dashboards'}
  21. </div>
  22. <div className={styles.libraryPanelInfo}>
  23. Last edited on {formatDate?.(panel.libraryPanel.meta.updated, 'L') ?? panel.libraryPanel.meta.updated} by
  24. {panel.libraryPanel.meta.updatedBy.avatarUrl && (
  25. <img
  26. width="22"
  27. height="22"
  28. className={styles.userAvatar}
  29. src={panel.libraryPanel.meta.updatedBy.avatarUrl}
  30. alt={`Avatar for ${panel.libraryPanel.meta.updatedBy.name}`}
  31. />
  32. )}
  33. {panel.libraryPanel.meta.updatedBy.name}
  34. </div>
  35. </div>
  36. );
  37. };
  38. const getStyles = (theme: GrafanaTheme) => {
  39. return {
  40. info: css`
  41. line-height: 1;
  42. `,
  43. libraryPanelInfo: css`
  44. color: ${theme.colors.textSemiWeak};
  45. font-size: ${theme.typography.size.sm};
  46. `,
  47. userAvatar: css`
  48. border-radius: 50%;
  49. box-sizing: content-box;
  50. width: 22px;
  51. height: 22px;
  52. padding-left: ${theme.spacing.sm};
  53. padding-right: ${theme.spacing.sm};
  54. `,
  55. };
  56. };