replayMetaData.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import Duration from 'sentry/components/duration';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import Placeholder from 'sentry/components/placeholder';
  6. import TimeSince from 'sentry/components/timeSince';
  7. import {IconCalendar, IconClock, IconFire} from 'sentry/icons';
  8. import space from 'sentry/styles/space';
  9. import useProjects from 'sentry/utils/useProjects';
  10. import {useRouteContext} from 'sentry/utils/useRouteContext';
  11. import type {ReplayRecord} from 'sentry/views/replays/types';
  12. type Props = {
  13. replayRecord: ReplayRecord | undefined;
  14. };
  15. function ReplayMetaData({replayRecord}: Props) {
  16. const {
  17. params: {replaySlug},
  18. } = useRouteContext();
  19. const {projects} = useProjects();
  20. const [slug] = replaySlug.split(':');
  21. return (
  22. <KeyMetrics>
  23. {replayRecord ? (
  24. <ProjectBadge
  25. project={
  26. projects.find(p => p.id === replayRecord.projectId) || {
  27. slug,
  28. }
  29. }
  30. avatarSize={16}
  31. />
  32. ) : (
  33. <HeaderPlaceholder />
  34. )}
  35. <KeyMetricData>
  36. {replayRecord ? (
  37. <React.Fragment>
  38. <IconCalendar color="gray300" />
  39. <TimeSince date={replayRecord.startedAt} shorten />
  40. </React.Fragment>
  41. ) : (
  42. <HeaderPlaceholder />
  43. )}
  44. </KeyMetricData>
  45. <KeyMetricData>
  46. {replayRecord ? (
  47. <React.Fragment>
  48. <IconClock color="gray300" />
  49. <Duration seconds={replayRecord?.duration} abbreviation exact />
  50. </React.Fragment>
  51. ) : (
  52. <HeaderPlaceholder />
  53. )}
  54. </KeyMetricData>
  55. <KeyMetricData>
  56. {replayRecord ? (
  57. <React.Fragment>
  58. <IconFire color="red300" />
  59. {replayRecord?.countErrors}
  60. </React.Fragment>
  61. ) : (
  62. <HeaderPlaceholder />
  63. )}
  64. </KeyMetricData>
  65. </KeyMetrics>
  66. );
  67. }
  68. export const HeaderPlaceholder = styled(function HeaderPlaceholder(
  69. props: React.ComponentProps<typeof Placeholder>
  70. ) {
  71. return <Placeholder width="80px" height="19px" {...props} />;
  72. })`
  73. background-color: ${p => p.theme.background};
  74. `;
  75. const KeyMetrics = styled('div')`
  76. display: grid;
  77. gap: ${space(3)};
  78. grid-template-columns: repeat(4, max-content);
  79. align-items: center;
  80. justify-content: end;
  81. font-size: ${p => p.theme.fontSizeMedium};
  82. `;
  83. const KeyMetricData = styled('div')`
  84. color: ${p => p.theme.textColor};
  85. font-weight: normal;
  86. display: grid;
  87. grid-template-columns: repeat(2, max-content);
  88. align-items: center;
  89. gap: ${space(1)};
  90. line-height: ${p => p.theme.text.lineHeightBody};
  91. `;
  92. export default ReplayMetaData;