monitorEnvironmentLabel.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import styled from '@emotion/styled';
  2. import {Tooltip} from 'sentry/components/tooltip';
  3. import {
  4. IconCheckmark,
  5. IconFire,
  6. IconFix,
  7. IconMute,
  8. IconTimer,
  9. IconUnsubscribed,
  10. } from 'sentry/icons';
  11. import {t} from 'sentry/locale';
  12. import {space} from 'sentry/styles/space';
  13. import type {ColorOrAlias} from 'sentry/utils/theme';
  14. import {
  15. type MonitorEnvironment,
  16. MonitorStatus,
  17. type StatusNotice,
  18. } from 'sentry/views/monitors/types';
  19. interface Props {
  20. monitorEnv: MonitorEnvironment;
  21. }
  22. export const statusIconColorMap: Record<MonitorStatus, StatusNotice> = {
  23. ok: {
  24. icon: <IconCheckmark color="successText" />,
  25. color: 'successText',
  26. },
  27. error: {
  28. icon: <IconFire color="errorText" />,
  29. color: 'errorText',
  30. },
  31. active: {
  32. icon: <IconTimer color="subText" />,
  33. color: 'subText',
  34. label: t('Waiting For Check-In'),
  35. },
  36. disabled: {
  37. icon: <IconUnsubscribed color="subText" size="xs" />,
  38. color: 'subText',
  39. label: t('Muted'),
  40. },
  41. };
  42. const userNotifiedDisplay: StatusNotice = {
  43. label: t(
  44. 'This environment is likely broken due to being in an error state for multiple days.'
  45. ),
  46. icon: <IconFix color="subText" />,
  47. color: 'subText',
  48. };
  49. const envMutedDisplay: StatusNotice = {
  50. label: t(
  51. 'This environment is likely broken due to being in an error state for multiple days. It has been automatically muted.'
  52. ),
  53. icon: <IconMute color="subText" />,
  54. color: 'subText',
  55. };
  56. export default function MonitorEnvironmentLabel({monitorEnv}: Props) {
  57. const {name, status, isMuted, activeIncident} = monitorEnv;
  58. const {userNotifiedTimestamp, environmentMutedTimestamp} =
  59. activeIncident?.brokenNotice ?? {};
  60. const envStatus = isMuted ? MonitorStatus.DISABLED : status;
  61. const {label, icon, color} = environmentMutedTimestamp
  62. ? envMutedDisplay
  63. : userNotifiedTimestamp
  64. ? userNotifiedDisplay
  65. : statusIconColorMap[envStatus];
  66. return (
  67. <EnvWithStatus>
  68. <MonitorEnvLabel color={color}>{name}</MonitorEnvLabel>
  69. <Tooltip disabled={!label} title={label} skipWrapper>
  70. {icon}
  71. </Tooltip>
  72. </EnvWithStatus>
  73. );
  74. }
  75. const EnvWithStatus = styled('div')`
  76. display: grid;
  77. grid-template-columns: 1fr max-content;
  78. gap: ${space(0.5)};
  79. align-items: center;
  80. opacity: var(--disabled-opacity);
  81. `;
  82. const MonitorEnvLabel = styled('div')<{color: ColorOrAlias}>`
  83. text-overflow: ellipsis;
  84. overflow: hidden;
  85. white-space: nowrap;
  86. min-width: 0;
  87. color: ${p => p.theme[p.color]};
  88. opacity: var(--disabled-opacity);
  89. `;