utils.tsx 4.5 KB

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