textRule.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 {AlertRuleComparisonType} from 'sentry/views/alerts/rules/metric/types';
  6. import {CHANGE_ALERT_CONDITION_IDS} from 'sentry/views/alerts/utils/constants';
  7. import {EVENT_FREQUENCY_PERCENT_CONDITION} from 'sentry/views/projectInstall/issueAlertOptions';
  8. /**
  9. * Translate Issue Alert Conditions to text
  10. */
  11. export function TextCondition({
  12. condition,
  13. }: {
  14. condition: IssueAlertRule['conditions'][number];
  15. }) {
  16. if (CHANGE_ALERT_CONDITION_IDS.includes(condition.id)) {
  17. if (condition.comparisonType === AlertRuleComparisonType.PERCENT) {
  18. if (condition.id === EVENT_FREQUENCY_PERCENT_CONDITION) {
  19. return (
  20. <Fragment>
  21. {t(
  22. // Double %% escapes
  23. 'Percent of sessions affected by an issue is %s%% higher in %s compared to %s ago',
  24. condition.value,
  25. condition.comparisonInterval,
  26. condition.interval
  27. )}
  28. </Fragment>
  29. );
  30. }
  31. return (
  32. <Fragment>
  33. {t(
  34. // Double %% escapes
  35. 'Number of events in an issue is %s%% higher in %s compared to %s ago',
  36. condition.value,
  37. condition.comparisonInterval,
  38. condition.interval
  39. )}
  40. </Fragment>
  41. );
  42. }
  43. return (
  44. <Fragment>
  45. {t(
  46. 'Number of events in an issue is more than %s in %s',
  47. condition.value,
  48. condition.interval
  49. )}
  50. </Fragment>
  51. );
  52. }
  53. return <Fragment>{condition.name}</Fragment>;
  54. }
  55. // TODO(scttcper): Remove the teams/memberList prop drilling
  56. export function TextAction({
  57. action,
  58. memberList,
  59. teams,
  60. }: {
  61. action: IssueAlertRule['actions'][number];
  62. memberList: Member[];
  63. teams: Team[];
  64. }) {
  65. if (action.targetType === 'Member') {
  66. const user = memberList.find(
  67. member => member.user.id === `${action.targetIdentifier}`
  68. );
  69. return <Fragment>{t('Send a notification to %s', user?.email)}</Fragment>;
  70. }
  71. if (action.targetType === 'Team') {
  72. const team = teams.find(tm => tm.id === `${action.targetIdentifier}`);
  73. return <Fragment>{t('Send a notification to #%s', team?.name)}</Fragment>;
  74. }
  75. if (action.id === 'sentry.integrations.slack.notify_action.SlackNotifyServiceAction') {
  76. // Remove (optionally, an ID: XXX) from slack action
  77. return <Fragment>{action.name.replace(/\(optionally.*\)/, '')}</Fragment>;
  78. }
  79. return <Fragment>{action.name}</Fragment>;
  80. }