alertBadge.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import styled from '@emotion/styled';
  2. import {
  3. IconCheckmark,
  4. IconDiamond,
  5. IconExclamation,
  6. IconFire,
  7. IconIssues,
  8. } from 'sentry/icons';
  9. import {t} from 'sentry/locale';
  10. import space from 'sentry/styles/space';
  11. import {Color} from 'sentry/utils/theme';
  12. import {IncidentStatus} from 'sentry/views/alerts/types';
  13. type Props = {
  14. hideText?: boolean;
  15. isIssue?: boolean;
  16. status?: IncidentStatus;
  17. };
  18. function AlertBadge({status, hideText = false, isIssue}: Props) {
  19. let statusText = t('Resolved');
  20. let Icon = IconCheckmark;
  21. let color: Color = 'green300';
  22. if (isIssue) {
  23. statusText = t('Issue');
  24. Icon = IconIssues;
  25. color = 'gray300';
  26. } else if (status === IncidentStatus.CRITICAL) {
  27. statusText = t('Critical');
  28. Icon = IconFire;
  29. color = 'red300';
  30. } else if (status === IncidentStatus.WARNING) {
  31. statusText = t('Warning');
  32. Icon = IconExclamation;
  33. color = 'yellow300';
  34. }
  35. return (
  36. <Wrapper data-test-id="alert-badge">
  37. <AlertIconWrapper
  38. role="img"
  39. aria-label={hideText ? statusText : undefined}
  40. color={color}
  41. icon={Icon}
  42. >
  43. <AlertIconBackground color={color} />
  44. <Icon color="white" />
  45. </AlertIconWrapper>
  46. {!hideText && <IncidentStatusValue color={color}>{statusText}</IncidentStatusValue>}
  47. </Wrapper>
  48. );
  49. }
  50. export default AlertBadge;
  51. const Wrapper = styled('div')`
  52. display: flex;
  53. align-items: center;
  54. `;
  55. const AlertIconWrapper = styled('div')<{color: Color; icon: React.ReactNode}>`
  56. width: 36px;
  57. height: 36px;
  58. position: relative;
  59. svg:last-child {
  60. width: ${p => (p.icon === IconIssues ? '13px' : '16px')};
  61. z-index: 2;
  62. position: absolute;
  63. top: 0;
  64. bottom: 0;
  65. left: 0;
  66. right: 0;
  67. margin: auto;
  68. }
  69. `;
  70. const AlertIconBackground = styled(IconDiamond)<{color: Color}>`
  71. width: 36px;
  72. height: 36px;
  73. `;
  74. const IncidentStatusValue = styled('div')`
  75. margin-left: ${space(1)};
  76. `;