alertBadge.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import styled from '@emotion/styled';
  2. import {DiamondStatus} from 'sentry/components/diamondStatus';
  3. import {
  4. IconCheckmark,
  5. IconEllipsis,
  6. IconExclamation,
  7. IconFire,
  8. IconIssues,
  9. IconShow,
  10. } from 'sentry/icons';
  11. import type {SVGIconProps} from 'sentry/icons/svgIcon';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import type {ColorOrAlias} from 'sentry/utils/theme';
  15. import {ActivationStatus, IncidentStatus} from 'sentry/views/alerts/types';
  16. type Props = {
  17. /**
  18. * The rule is actively monitoring
  19. */
  20. activationStatus?: ActivationStatus;
  21. /**
  22. * @deprecated use withText
  23. */
  24. hideText?: true;
  25. /**
  26. * There is no status for issue, this is to facilitate this custom usage.
  27. */
  28. isIssue?: boolean;
  29. /**
  30. * The incident status
  31. */
  32. status?: IncidentStatus;
  33. /**
  34. * Includes a label
  35. */
  36. withText?: boolean;
  37. };
  38. /**
  39. * This badge is a composition of DiamondStatus specifically used for incident
  40. * alerts.
  41. */
  42. function AlertBadge({status, withText, isIssue, activationStatus}: Props) {
  43. let statusText = t('Resolved');
  44. let Icon: React.ComponentType<SVGIconProps> = IconCheckmark;
  45. let color: ColorOrAlias = 'successText';
  46. if (isIssue) {
  47. statusText = t('Issue');
  48. Icon = SizedIconIssue;
  49. color = 'subText';
  50. } else if (status === IncidentStatus.CRITICAL) {
  51. statusText = t('Critical');
  52. Icon = IconFire;
  53. color = 'errorText';
  54. } else if (status === IncidentStatus.WARNING) {
  55. statusText = t('Warning');
  56. Icon = IconExclamation;
  57. color = 'warningText';
  58. }
  59. if (activationStatus === ActivationStatus.WAITING) {
  60. statusText = t('Ready');
  61. Icon = IconEllipsis;
  62. color = 'purple300';
  63. } else if (activationStatus === ActivationStatus.MONITORING) {
  64. statusText = t('Monitoring');
  65. Icon = IconShow;
  66. }
  67. return (
  68. <Wrapper data-test-id="alert-badge">
  69. <DiamondStatus
  70. icon={Icon}
  71. color={color}
  72. aria-label={!withText ? statusText : undefined}
  73. />
  74. {withText && <div>{statusText}</div>}
  75. </Wrapper>
  76. );
  77. }
  78. export default AlertBadge;
  79. /**
  80. * The size of the issue icon needs to be marginally adjusted to fit into the diamond well
  81. */
  82. const SizedIconIssue = styled(IconIssues)`
  83. width: 13px;
  84. `;
  85. const Wrapper = styled('div')`
  86. display: flex;
  87. align-items: center;
  88. gap: ${space(1)};
  89. `;