replayMetaData.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {Fragment} from 'react';
  2. import {Link} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Duration from 'sentry/components/duration';
  5. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  6. import Placeholder from 'sentry/components/placeholder';
  7. import Tag, {Background} from 'sentry/components/tag';
  8. import TimeSince from 'sentry/components/timeSince';
  9. import {IconCalendar, IconClock} from 'sentry/icons';
  10. import {tn} from 'sentry/locale';
  11. import space from 'sentry/styles/space';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import {useParams} from 'sentry/utils/useParams';
  14. import useProjects from 'sentry/utils/useProjects';
  15. import type {ReplayRecord} from 'sentry/views/replays/types';
  16. type Props = {
  17. replayRecord: ReplayRecord | undefined;
  18. };
  19. function ReplayMetaData({replayRecord}: Props) {
  20. const {pathname, query} = useLocation();
  21. const {replaySlug} = useParams();
  22. const {projects} = useProjects();
  23. const [slug] = replaySlug.split(':');
  24. const errorsTabHref = {
  25. pathname,
  26. query: {
  27. ...query,
  28. t_main: 'console',
  29. f_c_logLevel: 'issue',
  30. f_c_search: undefined,
  31. },
  32. };
  33. return (
  34. <KeyMetrics>
  35. {replayRecord ? (
  36. <ProjectBadge
  37. project={projects.find(p => p.id === replayRecord.projectId) || {slug}}
  38. avatarSize={16}
  39. />
  40. ) : (
  41. <HeaderPlaceholder />
  42. )}
  43. <KeyMetricData>
  44. {replayRecord ? (
  45. <Fragment>
  46. <IconCalendar color="gray300" />
  47. <TimeSince date={replayRecord.startedAt} shorten />
  48. </Fragment>
  49. ) : (
  50. <HeaderPlaceholder />
  51. )}
  52. </KeyMetricData>
  53. <KeyMetricData>
  54. {replayRecord ? (
  55. <Fragment>
  56. <IconClock color="gray300" />
  57. <Duration
  58. seconds={Math.trunc(replayRecord?.duration.asSeconds())}
  59. abbreviation
  60. exact
  61. />
  62. </Fragment>
  63. ) : (
  64. <HeaderPlaceholder />
  65. )}
  66. </KeyMetricData>
  67. {replayRecord ? (
  68. <StyledLink to={errorsTabHref}>
  69. <ErrorTag
  70. icon={null}
  71. type={replayRecord.countErrors ? 'error' : 'black'}
  72. level={replayRecord.countErrors ? 'fatal' : 'default'}
  73. >
  74. {replayRecord.countErrors}
  75. </ErrorTag>
  76. {tn('Error', 'Errors', replayRecord.countErrors)}
  77. </StyledLink>
  78. ) : (
  79. <HeaderPlaceholder />
  80. )}
  81. </KeyMetrics>
  82. );
  83. }
  84. export const HeaderPlaceholder = styled(
  85. (props: React.ComponentProps<typeof Placeholder>) => (
  86. <Placeholder width="80px" height="19px" {...props} />
  87. )
  88. )`
  89. background-color: ${p => p.theme.background};
  90. `;
  91. const KeyMetrics = styled('div')`
  92. display: flex;
  93. gap: ${space(3)};
  94. align-items: center;
  95. justify-content: end;
  96. font-size: ${p => p.theme.fontSizeMedium};
  97. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  98. justify-content: start;
  99. }
  100. `;
  101. const KeyMetricData = styled('div')`
  102. color: ${p => p.theme.textColor};
  103. font-weight: normal;
  104. display: flex;
  105. align-items: center;
  106. gap: ${space(1)};
  107. line-height: ${p => p.theme.text.lineHeightBody};
  108. `;
  109. const StyledLink = styled(Link)`
  110. display: flex;
  111. gap: ${space(1)};
  112. `;
  113. const ErrorTag = styled(Tag)<{level: 'fatal' | 'default'}>`
  114. ${Background} {
  115. background: ${p => p.theme.level[p.level]};
  116. border-color: ${p => p.theme.level[p.level]};
  117. padding: 0 ${space(0.75)};
  118. span {
  119. color: ${p => p.theme.buttonCountActive} !important;
  120. }
  121. }
  122. `;
  123. export default ReplayMetaData;