combinedAlertBadge.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import AlertBadge from 'sentry/components/badge/alertBadge';
  2. import {Tooltip} from 'sentry/components/tooltip';
  3. import {t, tct} from 'sentry/locale';
  4. import {MonitorType} from 'sentry/types/alerts';
  5. import {UptimeMonitorStatus} from 'sentry/views/alerts/rules/uptime/types';
  6. import {
  7. ActivationStatus,
  8. type CombinedAlerts,
  9. CombinedAlertType,
  10. IncidentStatus,
  11. } from 'sentry/views/alerts/types';
  12. import {isIssueAlert} from 'sentry/views/alerts/utils';
  13. interface Props {
  14. rule: CombinedAlerts;
  15. }
  16. const IncidentStatusText: Record<IncidentStatus, string> = {
  17. [IncidentStatus.CRITICAL]: t('Critical'),
  18. [IncidentStatus.WARNING]: t('Warning'),
  19. [IncidentStatus.CLOSED]: t('Resolved'),
  20. [IncidentStatus.OPENED]: t('Open'),
  21. };
  22. const UptimeStatusText: Record<
  23. UptimeMonitorStatus,
  24. {incidentStatus: IncidentStatus; statusText: string}
  25. > = {
  26. [UptimeMonitorStatus.OK]: {statusText: t('Up'), incidentStatus: IncidentStatus.CLOSED},
  27. [UptimeMonitorStatus.FAILED]: {
  28. statusText: t('Down'),
  29. incidentStatus: IncidentStatus.WARNING,
  30. },
  31. };
  32. /**
  33. * Takes in an alert rule (activated metric, metric, issue) and renders the
  34. * appropriate tooltip and AlertBadge
  35. */
  36. export default function CombinedAlertBadge({rule}: Props) {
  37. if (rule.type === CombinedAlertType.UPTIME) {
  38. const {statusText, incidentStatus} = UptimeStatusText[rule.status];
  39. return (
  40. <Tooltip title={tct('Uptime Alert Status: [statusText]', {statusText})}>
  41. <AlertBadge status={incidentStatus} />
  42. </Tooltip>
  43. );
  44. }
  45. const isIssueAlertInstance = isIssueAlert(rule);
  46. if (!isIssueAlertInstance && rule.monitorType === MonitorType.ACTIVATED) {
  47. const isWaiting =
  48. !rule.activations?.length ||
  49. (rule.activations?.length && rule.activations[0].isComplete);
  50. return (
  51. <Tooltip
  52. title={tct('Metric Alert Status: [status]', {
  53. status: isWaiting ? 'Ready to monitor' : 'Monitoring',
  54. })}
  55. >
  56. <AlertBadge
  57. status={rule?.latestIncident?.status}
  58. activationStatus={
  59. isWaiting ? ActivationStatus.WAITING : ActivationStatus.MONITORING
  60. }
  61. />
  62. </Tooltip>
  63. );
  64. }
  65. return (
  66. <Tooltip
  67. title={
  68. isIssueAlert(rule)
  69. ? t('Issue Alert')
  70. : tct('Metric Alert Status: [status]', {
  71. status:
  72. IncidentStatusText[rule?.latestIncident?.status ?? IncidentStatus.CLOSED],
  73. })
  74. }
  75. >
  76. <AlertBadge status={rule?.latestIncident?.status} isIssue={isIssueAlert(rule)} />
  77. </Tooltip>
  78. );
  79. }