spanSummaryHeader.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import styled from '@emotion/styled';
  2. import {SectionHeading} from 'sentry/components/charts/styles';
  3. import Count from 'sentry/components/count';
  4. import PerformanceDuration from 'sentry/components/performanceDuration';
  5. import {t, tct} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {defined} from 'sentry/utils';
  8. import {formatMetricUsingUnit} from 'sentry/utils/metrics/formatters';
  9. import {DataTitles} from 'sentry/views/insights/common/views/spans/types';
  10. type Props = {
  11. avgDuration: number | undefined;
  12. spanCount: number | undefined;
  13. spanDescription: string | undefined;
  14. spanOp: string | undefined;
  15. timeSpent: number | undefined;
  16. };
  17. export default function SpanSummaryHeader(props: Props) {
  18. const {spanOp, spanDescription, avgDuration, timeSpent, spanCount} = props;
  19. return (
  20. <ContentHeader>
  21. <HeaderInfo data-test-id="header-operation-name">
  22. <StyledSectionHeading>{t('Span')}</StyledSectionHeading>
  23. <SectionBody>
  24. <SpanLabelContainer data-test-id="header-span-description">
  25. {spanDescription ? spanDescription : emptyValue}
  26. </SpanLabelContainer>
  27. </SectionBody>
  28. <SectionSubtext data-test-id="operation-name">
  29. {spanOp ? spanOp : emptyValue}
  30. </SectionSubtext>
  31. </HeaderInfo>
  32. <HeaderInfo data-test-id="header-avg-duration">
  33. <StyledSectionHeading>{DataTitles.avg}</StyledSectionHeading>
  34. <NumericSectionWrapper>
  35. <SectionBody>
  36. {defined(avgDuration)
  37. ? formatMetricUsingUnit(avgDuration, 'milliseconds')
  38. : '\u2014'}
  39. </SectionBody>
  40. </NumericSectionWrapper>
  41. </HeaderInfo>
  42. <HeaderInfo data-test-id="header-total-time-spent">
  43. <StyledSectionHeading>{DataTitles.timeSpent}</StyledSectionHeading>
  44. <NumericSectionWrapper>
  45. <SectionBody>
  46. {defined(timeSpent) ? (
  47. <PerformanceDuration abbreviation milliseconds={timeSpent} />
  48. ) : (
  49. '\u2014'
  50. )}
  51. </SectionBody>
  52. <SectionSubtext data-test-id="total-span-count">
  53. {defined(spanCount)
  54. ? tct('[spanCount] spans', {spanCount: <Count value={spanCount} />})
  55. : '\u2014'}
  56. </SectionSubtext>
  57. </NumericSectionWrapper>
  58. </HeaderInfo>
  59. </ContentHeader>
  60. );
  61. }
  62. const ContentHeader = styled('div')`
  63. display: grid;
  64. grid-template-columns: 1fr;
  65. gap: ${space(4)};
  66. margin-bottom: ${space(2)};
  67. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  68. grid-template-columns: 1fr repeat(3, max-content);
  69. }
  70. `;
  71. const HeaderInfo = styled('div')`
  72. ${p => p.theme.overflowEllipsis};
  73. height: 78px;
  74. `;
  75. const StyledSectionHeading = styled(SectionHeading)`
  76. margin: 0;
  77. `;
  78. const NumericSectionWrapper = styled('div')`
  79. text-align: right;
  80. `;
  81. const SectionBody = styled('div')<{overflowEllipsis?: boolean}>`
  82. font-size: ${p => p.theme.fontSizeExtraLarge};
  83. padding: ${space(0.5)} 0;
  84. max-height: 32px;
  85. `;
  86. const SectionSubtext = styled('div')`
  87. color: ${p => p.theme.subText};
  88. font-size: ${p => p.theme.fontSizeMedium};
  89. `;
  90. export const SpanLabelContainer = styled('div')`
  91. ${p => p.theme.overflowEllipsis};
  92. `;
  93. const EmptyValueContainer = styled('span')`
  94. color: ${p => p.theme.gray300};
  95. `;
  96. const emptyValue = <EmptyValueContainer>{'\u2014'}</EmptyValueContainer>;