statusBadge.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import type {Theme} from '@emotion/react';
  2. import {GroupStatusTag} from 'sentry/components/group/inboxBadges/groupStatusTag';
  3. import {t} from 'sentry/locale';
  4. import {Group, GroupSubstatus} from 'sentry/types';
  5. interface SubstatusBadgeProps {
  6. status: Group['status'];
  7. fontSize?: 'sm' | 'md';
  8. substatus?: Group['substatus'];
  9. }
  10. function getBadgeProperties(
  11. status: Group['status'],
  12. substatus: Group['substatus']
  13. ): {status: string; tagType: keyof Theme['tag']; tooltip?: string} | undefined {
  14. if (status === 'resolved') {
  15. return {
  16. tagType: 'highlight',
  17. status: t('Resolved'),
  18. };
  19. }
  20. if (status === 'unresolved') {
  21. if (substatus === GroupSubstatus.REGRESSED) {
  22. return {
  23. tagType: 'highlight',
  24. status: t('Regressed'),
  25. };
  26. }
  27. if (substatus === GroupSubstatus.ESCALATING) {
  28. return {
  29. tagType: 'error',
  30. status: t('Escalating'),
  31. };
  32. }
  33. if (substatus === GroupSubstatus.NEW) {
  34. return {
  35. tagType: 'warning',
  36. status: t('New'),
  37. };
  38. }
  39. return {
  40. tagType: 'default',
  41. status: t('Ongoing'),
  42. };
  43. }
  44. if (status === 'ignored') {
  45. return {
  46. tagType: 'default',
  47. status: t('Archived'),
  48. tooltip:
  49. substatus === GroupSubstatus.ARCHIVED_FOREVER
  50. ? t('Archived forever')
  51. : substatus === GroupSubstatus.ARCHIVED_UNTIL_ESCALATING
  52. ? t('Archived until escalating')
  53. : t('Archived until condition met'),
  54. };
  55. }
  56. return undefined;
  57. }
  58. /**
  59. * A replacement for the inbox badge that uses the group substatus
  60. * instead of the group inbox reason.
  61. */
  62. export function GroupStatusBadge(props: SubstatusBadgeProps) {
  63. const badge = getBadgeProperties(props.status, props.substatus);
  64. if (!badge) {
  65. return null;
  66. }
  67. return (
  68. <GroupStatusTag
  69. type={badge.tagType}
  70. tooltip={badge.tooltip}
  71. fontSize={props.fontSize}
  72. >
  73. {badge.status}
  74. </GroupStatusTag>
  75. );
  76. }