alertLastIncidentActivationInfo.tsx 2.3 KB

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