alertLastIncidentActivationInfo.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import TimeSince from 'sentry/components/timeSince';
  2. import {t, tct} from 'sentry/locale';
  3. import {MonitorType} from 'sentry/types/alerts';
  4. import getDuration from 'sentry/utils/duration/getDuration';
  5. import {hasActiveIncident} from 'sentry/views/alerts/list/rules/utils';
  6. import {
  7. type CombinedAlerts,
  8. CombinedAlertType,
  9. type IssueAlert,
  10. type MetricAlert,
  11. type UptimeAlert,
  12. } from 'sentry/views/alerts/types';
  13. interface Props {
  14. rule: CombinedAlerts;
  15. }
  16. /**
  17. * Displays the time since the last uptime incident given an uptime alert rule
  18. */
  19. function LastUptimeIncident({rule}: {rule: UptimeAlert}) {
  20. // TODO(davidenwang): Once we have a lastTriggered field returned from backend, display that info here
  21. return tct('Actively monitoring every [interval]', {
  22. interval: getDuration(rule.intervalSeconds),
  23. });
  24. }
  25. /**
  26. * Displays the last time an issue alert was triggered
  27. */
  28. function LastIssueTrigger({rule}: {rule: IssueAlert}) {
  29. if (!rule.lastTriggered) {
  30. return t('Alert not triggered yet');
  31. }
  32. return (
  33. <div>
  34. {t('Triggered ')}
  35. <TimeSince date={rule.lastTriggered} />
  36. </div>
  37. );
  38. }
  39. /**
  40. * Displays the last activation for activated alert rules or the last incident for continuous alerts
  41. */
  42. function LastMetricAlertIncident({rule}: {rule: MetricAlert}) {
  43. if (rule.monitorType === MonitorType.ACTIVATED) {
  44. if (!rule.activations?.length) {
  45. return t('Alert has not been activated yet');
  46. }
  47. return (
  48. <div>
  49. {t('Last activated ')}
  50. <TimeSince date={rule.activations[0].dateCreated} />
  51. </div>
  52. );
  53. }
  54. if (!rule.latestIncident) {
  55. return t('Alert not triggered yet');
  56. }
  57. const activeIncident = hasActiveIncident(rule);
  58. if (activeIncident) {
  59. return (
  60. <div>
  61. {t('Triggered ')}
  62. <TimeSince date={rule.latestIncident.dateCreated} />
  63. </div>
  64. );
  65. }
  66. return (
  67. <div>
  68. {t('Resolved ')}
  69. <TimeSince date={rule.latestIncident.dateClosed!} />
  70. </div>
  71. );
  72. }
  73. export default function AlertLastIncidentActivationInfo({rule}: Props) {
  74. // eslint-disable-next-line default-case
  75. switch (rule.type) {
  76. case CombinedAlertType.UPTIME:
  77. return <LastUptimeIncident rule={rule} />;
  78. case CombinedAlertType.ISSUE:
  79. return <LastIssueTrigger rule={rule} />;
  80. case CombinedAlertType.METRIC:
  81. return <LastMetricAlertIncident rule={rule} />;
  82. }
  83. }