monitorEnvironmentLabel.tsx 2.0 KB

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