textRule.tsx 2.1 KB

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