DiffValues.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { css } from '@emotion/css';
  2. import { isArray, isObject, isUndefined } from 'lodash';
  3. import React from 'react';
  4. import { GrafanaTheme2 } from '@grafana/data';
  5. import { useStyles2, Icon } from '@grafana/ui';
  6. import { Diff } from './utils';
  7. type DiffProps = {
  8. diff: Diff;
  9. };
  10. export const DiffValues: React.FC<DiffProps> = ({ diff }) => {
  11. const styles = useStyles2(getStyles);
  12. const hasLeftValue =
  13. !isUndefined(diff.originalValue) && !isArray(diff.originalValue) && !isObject(diff.originalValue);
  14. const hasRightValue = !isUndefined(diff.value) && !isArray(diff.value) && !isObject(diff.value);
  15. return (
  16. <>
  17. {hasLeftValue && <span className={styles}>{String(diff.originalValue)}</span>}
  18. {hasLeftValue && hasRightValue ? <Icon name="arrow-right" /> : null}
  19. {hasRightValue && <span className={styles}>{String(diff.value)}</span>}
  20. </>
  21. );
  22. };
  23. const getStyles = (theme: GrafanaTheme2) => css`
  24. background-color: ${theme.colors.action.hover};
  25. border-radius: ${theme.shape.borderRadius()};
  26. color: ${theme.colors.text.primary};
  27. font-size: ${theme.typography.body.fontSize};
  28. margin: 0 ${theme.spacing(0.5)};
  29. padding: ${theme.spacing(0.5, 1)};
  30. `;