annotated.tsx 912 B

1234567891011121314151617181920212223242526272829303132
  1. import AnnotatedText from 'sentry/components/events/meta/annotatedText';
  2. import MetaData from 'sentry/components/events/meta/metaData';
  3. import {isFunction} from 'sentry/utils';
  4. type Props<Values> = {
  5. children: (value: string | null | React.ReactNode) => React.ReactNode | string;
  6. object: Values;
  7. objectKey: Extract<keyof Values, string>;
  8. required?: boolean;
  9. };
  10. /**
  11. * Returns the value of `object[prop]` and returns an annotated component if
  12. * there is meta data
  13. */
  14. const Annotated = <Values extends {}>({
  15. children,
  16. object,
  17. objectKey,
  18. required = false,
  19. }: Props<Values>) => {
  20. return (
  21. <MetaData object={object} prop={objectKey} required={required}>
  22. {(value, meta) => {
  23. const toBeReturned = <AnnotatedText value={value} meta={meta} />;
  24. return isFunction(children) ? children(toBeReturned) : toBeReturned;
  25. }}
  26. </MetaData>
  27. );
  28. };
  29. export default Annotated;