textRule.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {Fragment} from 'react';
  2. import {t} from 'sentry/locale';
  3. import type {Member, Team} from 'sentry/types';
  4. import type {IssueAlertRule} from 'sentry/types/alerts';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import {AlertRuleComparisonType} from 'sentry/views/alerts/rules/metric/types';
  7. import {CHANGE_ALERT_CONDITION_IDS} from 'sentry/views/alerts/utils/constants';
  8. import {
  9. EVENT_FREQUENCY_PERCENT_CONDITION,
  10. REAPPEARED_EVENT_CONDITION,
  11. } from 'sentry/views/projectInstall/issueAlertOptions';
  12. /**
  13. * Translate Issue Alert Conditions to text
  14. */
  15. export function TextCondition({
  16. condition,
  17. }: {
  18. condition: IssueAlertRule['conditions'][number];
  19. }) {
  20. const organization = useOrganization();
  21. if (CHANGE_ALERT_CONDITION_IDS.includes(condition.id)) {
  22. if (condition.comparisonType === AlertRuleComparisonType.PERCENT) {
  23. if (condition.id === EVENT_FREQUENCY_PERCENT_CONDITION) {
  24. return (
  25. <Fragment>
  26. {t(
  27. // Double %% escapes
  28. 'Percent of sessions affected by an issue is %s%% higher in %s compared to %s ago',
  29. condition.value,
  30. condition.interval,
  31. condition.comparisonInterval
  32. )}
  33. </Fragment>
  34. );
  35. }
  36. return (
  37. <Fragment>
  38. {t(
  39. // Double %% escapes
  40. 'Number of events in an issue is %s%% higher in %s compared to %s ago',
  41. condition.value,
  42. condition.interval,
  43. condition.comparisonInterval
  44. )}
  45. </Fragment>
  46. );
  47. }
  48. return (
  49. <Fragment>
  50. {t(
  51. 'Number of events in an issue is more than %s in %s',
  52. condition.value,
  53. condition.interval
  54. )}
  55. </Fragment>
  56. );
  57. }
  58. if (
  59. condition.id === REAPPEARED_EVENT_CONDITION &&
  60. organization.features.includes('escalating-issues')
  61. ) {
  62. return (
  63. <Fragment>{t('The issue changes state from archived to escalating')}</Fragment>
  64. );
  65. }
  66. return <Fragment>{condition.name}</Fragment>;
  67. }
  68. // TODO(scttcper): Remove the teams/memberList prop drilling
  69. export function TextAction({
  70. action,
  71. memberList,
  72. teams,
  73. }: {
  74. action: IssueAlertRule['actions'][number];
  75. memberList: Member[];
  76. teams: Team[];
  77. }) {
  78. if (action.targetType === 'Member') {
  79. const user = memberList.find(
  80. member => member.user?.id === `${action.targetIdentifier}`
  81. );
  82. return (
  83. <Fragment>{t('Send a notification to %s', user?.email ?? t('unknown'))}</Fragment>
  84. );
  85. }
  86. if (action.targetType === 'Team') {
  87. const team = teams.find(tm => tm.id === `${action.targetIdentifier}`);
  88. return (
  89. <Fragment>{t('Send a notification to #%s', team?.name ?? t('unknown'))}</Fragment>
  90. );
  91. }
  92. if (action.id === 'sentry.integrations.slack.notify_action.SlackNotifyServiceAction') {
  93. const name = action.name
  94. // Hide the id "(optionally, an ID: XXX)"
  95. .replace(/\(optionally.*\)/, '')
  96. // Hide empty tags
  97. .replace('and show tags [] in notification', '');
  98. return <Fragment>{name}</Fragment>;
  99. }
  100. return <Fragment>{action.name}</Fragment>;
  101. }