monitorEnvironmentLabel.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import styled from '@emotion/styled';
  2. import {Tooltip} from 'sentry/components/tooltip';
  3. import {IconFix, IconMute} from 'sentry/icons';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import type {ColorOrAlias} from 'sentry/utils/theme';
  7. import {
  8. type Monitor,
  9. type MonitorEnvironment,
  10. MonitorStatus,
  11. type StatusNotice,
  12. } from 'sentry/views/monitors/types';
  13. import {statusIconColorMap} from 'sentry/views/monitors/utils/constants';
  14. interface Props {
  15. monitor: Monitor;
  16. monitorEnv: MonitorEnvironment;
  17. }
  18. const userNotifiedDisplay: StatusNotice = {
  19. label: t(
  20. 'This environment is likely broken due to being in an error state for multiple days.'
  21. ),
  22. icon: <IconFix color="subText" />,
  23. color: 'subText',
  24. };
  25. const envMutedDisplay: StatusNotice = {
  26. label: t(
  27. 'This environment is likely broken due to being in an error state for multiple days. It has been automatically muted.'
  28. ),
  29. icon: <IconMute color="subText" />,
  30. color: 'subText',
  31. };
  32. export default function MonitorEnvironmentLabel({monitorEnv, monitor}: Props) {
  33. const {name, status, isMuted, activeIncident} = monitorEnv;
  34. const {userNotifiedTimestamp, envMutedTimestamp} = activeIncident?.brokenNotice ?? {};
  35. const envStatus = monitor.isMuted || isMuted ? MonitorStatus.DISABLED : status;
  36. const {label, icon, color} = userNotifiedTimestamp
  37. ? userNotifiedDisplay
  38. : envMutedTimestamp
  39. ? envMutedDisplay
  40. : statusIconColorMap[envStatus];
  41. return (
  42. <EnvWithStatus>
  43. <MonitorEnvLabel color={color}>{name}</MonitorEnvLabel>
  44. <Tooltip title={label} skipWrapper>
  45. {icon}
  46. </Tooltip>
  47. </EnvWithStatus>
  48. );
  49. }
  50. const EnvWithStatus = styled('div')`
  51. display: grid;
  52. grid-template-columns: 1fr max-content;
  53. gap: ${space(0.5)};
  54. align-items: center;
  55. opacity: var(--disabled-opacity);
  56. `;
  57. const MonitorEnvLabel = styled('div')<{color: ColorOrAlias}>`
  58. text-overflow: ellipsis;
  59. overflow: hidden;
  60. white-space: nowrap;
  61. min-width: 0;
  62. color: ${p => p.theme[p.color]};
  63. opacity: var(--disabled-opacity);
  64. `;