thresholdsHoverWrapper.tsx 2.3 KB

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