alertBadge.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 color={color} icon={Icon}>
  38. <AlertIconBackground color={color} />
  39. <Icon color="white" />
  40. </AlertIconWrapper>
  41. {!hideText && <IncidentStatusValue color={color}>{statusText}</IncidentStatusValue>}
  42. </Wrapper>
  43. );
  44. }
  45. export default AlertBadge;
  46. const Wrapper = styled('div')`
  47. display: flex;
  48. align-items: center;
  49. `;
  50. const AlertIconWrapper = styled('div')<{color: Color; icon: React.ReactNode}>`
  51. width: 36px;
  52. height: 36px;
  53. position: relative;
  54. svg:last-child {
  55. width: ${p => (p.icon === IconIssues ? '13px' : '16px')};
  56. z-index: 2;
  57. position: absolute;
  58. top: 0;
  59. bottom: 0;
  60. left: 0;
  61. right: 0;
  62. margin: auto;
  63. }
  64. `;
  65. const AlertIconBackground = styled(IconDiamond)<{color: Color}>`
  66. width: 36px;
  67. height: 36px;
  68. `;
  69. const IncidentStatusValue = styled('div')`
  70. margin-left: ${space(1)};
  71. `;