annotatedTextValue.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import styled from '@emotion/styled';
  2. import {Tooltip} from 'sentry/components/tooltip';
  3. import {Organization, Project} from 'sentry/types';
  4. import {Redaction} from './redaction';
  5. import {getTooltipText} from './utils';
  6. import {ValueElement} from './valueElement';
  7. type Props = {
  8. value: React.ReactNode;
  9. meta?: Record<any, any>;
  10. organization?: Organization;
  11. project?: Project;
  12. };
  13. export function AnnotatedTextValue({value, meta, organization, project}: Props) {
  14. if (meta?.chunks?.length && meta.chunks.length > 1) {
  15. return (
  16. <ChunksSpan>
  17. {meta.chunks.map((chunk, index) => {
  18. if (chunk.type === 'redaction') {
  19. return (
  20. <Tooltip
  21. skipWrapper
  22. title={getTooltipText({rule_id: chunk.rule_id, remark: chunk.remark})}
  23. key={index}
  24. >
  25. <Redaction>{chunk.text}</Redaction>
  26. </Tooltip>
  27. );
  28. }
  29. return chunk.text;
  30. })}
  31. </ChunksSpan>
  32. );
  33. }
  34. if (meta?.rem?.length) {
  35. return (
  36. <Tooltip
  37. title={getTooltipText({
  38. rule_id: meta.rem[0][0],
  39. remark: meta.rem[0][1],
  40. organization,
  41. project,
  42. })}
  43. isHoverable
  44. >
  45. <ValueElement value={value} meta={meta} />
  46. </Tooltip>
  47. );
  48. }
  49. return <ValueElement value={value} meta={meta} />;
  50. }
  51. const ChunksSpan = styled('span')`
  52. word-break: break-word;
  53. `;