replayMetaData.tsx 3.3 KB

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