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 {
  5. IssueAlertActionType,
  6. IssueAlertConditionType,
  7. type IssueAlertRule,
  8. } from 'sentry/types/alerts';
  9. import {AlertRuleComparisonType} from 'sentry/views/alerts/rules/metric/types';
  10. import {CHANGE_ALERT_PLACEHOLDERS_LABELS} from 'sentry/views/alerts/utils/constants';
  11. /**
  12. * Translate Issue Alert Conditions to text
  13. */
  14. export function TextCondition({
  15. condition,
  16. }: {
  17. condition: IssueAlertRule['conditions'][number];
  18. }) {
  19. if (
  20. condition.id === IssueAlertConditionType.EVENT_FREQUENCY_PERCENT ||
  21. condition.id === IssueAlertConditionType.EVENT_FREQUENCY ||
  22. condition.id === IssueAlertConditionType.EVENT_UNIQUE_USER_FREQUENCY
  23. ) {
  24. const subject = CHANGE_ALERT_PLACEHOLDERS_LABELS[condition.id];
  25. if (condition.comparisonType === AlertRuleComparisonType.PERCENT) {
  26. // This text does not translate well and should match the alert builder
  27. return (
  28. <Fragment>
  29. {subject} {condition.value}% higher in {condition.interval} compared to{' '}
  30. {condition.comparisonInterval} ago
  31. </Fragment>
  32. );
  33. }
  34. return (
  35. // This text does not translate well and should match the alert builder
  36. <Fragment>
  37. {subject} more than {condition.value} in {condition.interval}
  38. </Fragment>
  39. );
  40. }
  41. if (condition.id === IssueAlertConditionType.REAPPEARED_EVENT) {
  42. return (
  43. <Fragment>{t('The issue changes state from archived to escalating')}</Fragment>
  44. );
  45. }
  46. return <Fragment>{condition.name}</Fragment>;
  47. }
  48. // TODO(scttcper): Remove the teams/memberList prop drilling
  49. export function TextAction({
  50. action,
  51. memberList,
  52. teams,
  53. }: {
  54. action: IssueAlertRule['actions'][number];
  55. memberList: Member[];
  56. teams: Team[];
  57. }) {
  58. if (action.targetType === 'Member') {
  59. const user = memberList.find(
  60. member => member.user?.id === `${action.targetIdentifier}`
  61. );
  62. return (
  63. <Fragment>{t('Send a notification to %s', user?.email ?? t('unknown'))}</Fragment>
  64. );
  65. }
  66. if (action.targetType === 'Team') {
  67. const team = teams.find(tm => tm.id === `${action.targetIdentifier}`);
  68. return (
  69. <Fragment>{t('Send a notification to #%s', team?.name ?? t('unknown'))}</Fragment>
  70. );
  71. }
  72. if (action.id === IssueAlertActionType.SLACK) {
  73. const name = action.name
  74. // Hide the id "(optionally, an ID: XXX)"
  75. .replace(/\(optionally.*\)/, '')
  76. // Hide empty tags
  77. .replace('and show tags [] in notification', '');
  78. return <Fragment>{name}</Fragment>;
  79. }
  80. return <Fragment>{action.name}</Fragment>;
  81. }