alertBadge.tsx 1.9 KB

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