utils.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import styled from '@emotion/styled';
  2. import Link from 'sentry/components/links/link';
  3. import {tct} from 'sentry/locale';
  4. import space from 'sentry/styles/space';
  5. import {ChunkType, Organization, Project} from 'sentry/types';
  6. import {convertRelayPiiConfig} from 'sentry/views/settings/components/dataScrubbing/convertRelayPiiConfig';
  7. import {getRuleDescription} from 'sentry/views/settings/components/dataScrubbing/utils';
  8. const REMARKS = {
  9. a: 'Annotated',
  10. x: 'Removed',
  11. s: 'Replaced',
  12. m: 'Masked',
  13. p: 'Pseudonymized',
  14. e: 'Encrypted',
  15. };
  16. const KNOWN_RULES = {
  17. '!limit': 'size limits',
  18. '!raw': 'raw payload',
  19. '!config': 'SDK configuration',
  20. };
  21. export function getTooltipText({
  22. remark = '',
  23. rule_id = '',
  24. organization,
  25. project,
  26. }: Pick<ChunkType, 'remark' | 'rule_id'> & {
  27. organization?: Organization;
  28. project?: Project;
  29. }) {
  30. const method = REMARKS[remark];
  31. // default data scrubbing
  32. if (KNOWN_RULES[rule_id]) {
  33. return tct('[method] because of the PII rule [break][rule-description]', {
  34. method,
  35. break: <br />,
  36. 'rule-description': KNOWN_RULES[rule_id],
  37. });
  38. }
  39. // advanced data scrubbing
  40. const [level, ruleId] = String(rule_id).split(':');
  41. if (level === 'organization') {
  42. // if organization is not available, fall back to the default message
  43. if (!organization) {
  44. return tct('[method] because of the PII rule [break][rule-description]', {
  45. method,
  46. break: <br />,
  47. 'rule-description': rule_id,
  48. });
  49. }
  50. const rules = convertRelayPiiConfig(organization?.relayPiiConfig);
  51. const rule = rules.find(({id}) => String(id) === ruleId);
  52. return (
  53. <Wrapper>
  54. {tct(
  55. '[method] because of the PII rule [break][rule-description] in the settings of the organization [break][slug]',
  56. {
  57. method,
  58. break: <br />,
  59. 'rule-description': (
  60. <RuleDescription>
  61. <Link
  62. to={`/settings/${organization.slug}/security-and-privacy/#advanced-data-scrubbing`}
  63. >
  64. {rule ? getRuleDescription(rule) : ruleId}
  65. </Link>
  66. </RuleDescription>
  67. ),
  68. slug: (
  69. <Slug>
  70. <Link
  71. to={`/settings/${organization.slug}/security-and-privacy/#advanced-data-scrubbing`}
  72. >
  73. {organization.slug}
  74. </Link>
  75. </Slug>
  76. ),
  77. }
  78. )}
  79. </Wrapper>
  80. );
  81. }
  82. // if project and organization are not available, fall back to the default message
  83. if (!project || !organization) {
  84. return tct('[method] because of the PII rule [break][rule-description]', {
  85. method,
  86. break: <br />,
  87. 'rule-description': rule_id,
  88. });
  89. }
  90. const rules = convertRelayPiiConfig(project?.relayPiiConfig);
  91. const rule = rules.find(({id}) => String(id) === ruleId);
  92. return tct(
  93. '[method] because of the PII rule [break][rule-description] in the settings of the project [break][slug]',
  94. {
  95. method,
  96. break: <br />,
  97. 'rule-description': (
  98. <RuleDescription>
  99. <Link
  100. to={`/settings/${organization.slug}/projects/${project.slug}/security-and-privacy/#advanced-data-scrubbing`}
  101. >
  102. {rule ? getRuleDescription(rule) : ruleId}
  103. </Link>
  104. </RuleDescription>
  105. ),
  106. slug: (
  107. <Slug>
  108. <Link
  109. to={`/settings/${organization.slug}/projects/${project?.slug}/security-and-privacy/#advanced-data-scrubbing`}
  110. >
  111. {project.slug}
  112. </Link>
  113. </Slug>
  114. ),
  115. }
  116. );
  117. }
  118. const Wrapper = styled('div')`
  119. display: grid;
  120. gap: ${space(0.5)};
  121. `;
  122. const RuleDescription = styled('div')`
  123. margin: ${space(0.5)} 0;
  124. `;
  125. const Slug = styled('div')`
  126. margin-top: ${space(0.5)};
  127. `;