thresholdsHoverWrapper.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import type React from 'react';
  2. import styled from '@emotion/styled';
  3. import CircleIndicator from 'sentry/components/circleIndicator';
  4. import {Hovercard} from 'sentry/components/hovercard';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import theme from 'sentry/utils/theme';
  8. import type {ThresholdsConfig} from './thresholdsStep';
  9. type Props = {
  10. children: React.ReactNode;
  11. thresholds: ThresholdsConfig;
  12. type?: string;
  13. };
  14. export function ThresholdsHoverWrapper({children, thresholds, type}: Props) {
  15. const {
  16. unit,
  17. max_values: {max1, max2},
  18. } = thresholds;
  19. const formattedUnit =
  20. unit && (type === 'duration' ? `${unit}s` : `/${unit.split('/')[1]}`);
  21. const title = unit ? t(`Thresholds in %s`, formattedUnit) : t('Thresholds');
  22. const notSetMsg = t('Not set');
  23. const maxOneValue = max1 ?? notSetMsg;
  24. const maxTwoValue = max2 ?? notSetMsg;
  25. return (
  26. <StyledHoverCard
  27. skipWrapper
  28. body={
  29. <BodyWrapper>
  30. <ContextTitle>{title}</ContextTitle>
  31. <Row>
  32. <StyledIndicator color={theme.green300} size={10} />
  33. <span>0 - {maxOneValue}</span>
  34. </Row>
  35. <Row>
  36. <StyledIndicator color={theme.yellow300} size={10} />
  37. <span>
  38. {maxOneValue} - {maxTwoValue}
  39. </span>
  40. </Row>
  41. <Row>
  42. <StyledIndicator color={theme.red300} size={10} />
  43. <span>
  44. {maxTwoValue} - {t('No max')}
  45. </span>
  46. </Row>
  47. </BodyWrapper>
  48. }
  49. >
  50. {children}
  51. </StyledHoverCard>
  52. );
  53. }
  54. const StyledHoverCard = styled(Hovercard)`
  55. width: fit-content;
  56. `;
  57. const BodyWrapper = styled('div')`
  58. display: flex;
  59. flex-direction: column;
  60. gap: ${space(1)};
  61. `;
  62. const Row = styled('span')`
  63. display: flex;
  64. gap: ${space(0.5)};
  65. align-items: center;
  66. `;
  67. const ContextTitle = styled('h6')`
  68. color: ${p => p.theme.subText};
  69. margin-bottom: 0 !important;
  70. `;
  71. const StyledIndicator = styled(CircleIndicator)`
  72. margin-right: ${space(1)};
  73. `;