replayMetaData.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: 'error',
  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 seconds={replayRecord?.duration} abbreviation exact />
  59. </Fragment>
  60. ) : (
  61. <HeaderPlaceholder />
  62. )}
  63. </KeyMetricData>
  64. <KeyMetricData>
  65. {replayRecord ? (
  66. <Fragment>
  67. <ErrorTag to={errorsTabHref} icon={null} type="error">
  68. {replayRecord?.countErrors}
  69. </ErrorTag>
  70. <Link to={errorsTabHref}>{t('Errors')}</Link>
  71. </Fragment>
  72. ) : (
  73. <HeaderPlaceholder />
  74. )}
  75. </KeyMetricData>
  76. </KeyMetrics>
  77. );
  78. }
  79. export const HeaderPlaceholder = styled(
  80. (props: React.ComponentProps<typeof Placeholder>) => (
  81. <Placeholder width="80px" height="19px" {...props} />
  82. )
  83. )`
  84. background-color: ${p => p.theme.background};
  85. `;
  86. const KeyMetrics = styled('div')`
  87. display: grid;
  88. gap: ${space(3)};
  89. grid-template-columns: repeat(4, max-content);
  90. align-items: center;
  91. justify-content: end;
  92. font-size: ${p => p.theme.fontSizeMedium};
  93. `;
  94. const KeyMetricData = styled('div')`
  95. color: ${p => p.theme.textColor};
  96. font-weight: normal;
  97. display: grid;
  98. grid-template-columns: repeat(2, max-content);
  99. align-items: center;
  100. gap: ${space(1)};
  101. line-height: ${p => p.theme.text.lineHeightBody};
  102. `;
  103. const ErrorTag = styled(Tag)`
  104. ${Background} {
  105. background: ${p => p.theme.tag.error.iconColor};
  106. padding: 0 ${space(0.75)};
  107. span {
  108. color: white !important;
  109. }
  110. }
  111. `;
  112. export default ReplayMetaData;