DiffTitle.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { useStyles, Icon } from '@grafana/ui';
  5. import { DiffValues } from './DiffValues';
  6. import { Diff, getDiffText } from './utils';
  7. type DiffTitleProps = {
  8. diff?: Diff;
  9. title: string;
  10. };
  11. const replaceDiff: Diff = { op: 'replace', originalValue: undefined, path: [''], value: undefined, startLineNumber: 0 };
  12. export const DiffTitle: React.FC<DiffTitleProps> = ({ diff, title }) => {
  13. const styles = useStyles(getDiffTitleStyles);
  14. return diff ? (
  15. <>
  16. <Icon type="mono" name="circle" className={styles[diff.op]} /> <span className={styles.embolden}>{title}</span>{' '}
  17. <span>{getDiffText(diff, diff.path.length > 1)}</span> <DiffValues diff={diff} />
  18. </>
  19. ) : (
  20. <div className={styles.withoutDiff}>
  21. <Icon type="mono" name="circle" className={styles.replace} /> <span className={styles.embolden}>{title}</span>{' '}
  22. <span>{getDiffText(replaceDiff, false)}</span>
  23. </div>
  24. );
  25. };
  26. const getDiffTitleStyles = (theme: GrafanaTheme) => ({
  27. embolden: css`
  28. font-weight: ${theme.typography.weight.bold};
  29. `,
  30. add: css`
  31. color: ${theme.palette.online};
  32. `,
  33. replace: css`
  34. color: ${theme.palette.warn};
  35. `,
  36. move: css`
  37. color: ${theme.palette.warn};
  38. `,
  39. copy: css`
  40. color: ${theme.palette.warn};
  41. `,
  42. _get: css`
  43. color: ${theme.palette.warn};
  44. `,
  45. test: css`
  46. color: ${theme.palette.warn};
  47. `,
  48. remove: css`
  49. color: ${theme.palette.critical};
  50. `,
  51. withoutDiff: css`
  52. margin-bottom: ${theme.spacing.md};
  53. `,
  54. });