valueElement.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {Fragment, isValidElement} from 'react';
  2. import {t} from 'sentry/locale';
  3. import Redaction from './redaction';
  4. type Props = {
  5. value: React.ReactNode;
  6. meta?: Record<any, any>;
  7. };
  8. // If you find yourself modifying this component to fix some tooltip bug,
  9. // consider that `meta` is not properly passed into this component in the
  10. // first place. It's much more likely that `withMeta` is buggy or improperly
  11. // used than that this component has a bug.
  12. const ValueElement = ({value, meta}: Props) => {
  13. if (!!value && meta) {
  14. return <Redaction>{value}</Redaction>;
  15. }
  16. if (meta?.err?.length) {
  17. return (
  18. <Redaction withoutBackground>
  19. <i>{`<${t('invalid')}>`}</i>
  20. </Redaction>
  21. );
  22. }
  23. if (meta?.rem?.length) {
  24. return (
  25. <Redaction>
  26. <i>{`<${t('redacted')}>`}</i>
  27. </Redaction>
  28. );
  29. }
  30. if (isValidElement(value)) {
  31. return value;
  32. }
  33. return (
  34. <Fragment>
  35. {typeof value === 'object' || typeof value === 'boolean'
  36. ? JSON.stringify(value)
  37. : value}
  38. </Fragment>
  39. );
  40. };
  41. export default ValueElement;