page.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import type {ReactNode} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {MenuItemProps} from 'sentry/components/dropdownMenu';
  4. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  5. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  6. import UserBadge from 'sentry/components/idBadge/userBadge';
  7. import FullViewport from 'sentry/components/layouts/fullViewport';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import ConfigureReplayCard from 'sentry/components/replays/configureReplayCard';
  10. import DetailsPageBreadcrumbs from 'sentry/components/replays/header/detailsPageBreadcrumbs';
  11. import FeedbackButton from 'sentry/components/replays/header/feedbackButton';
  12. import HeaderPlaceholder from 'sentry/components/replays/header/headerPlaceholder';
  13. import ReplayMetaData from 'sentry/components/replays/header/replayMetaData';
  14. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  15. import TimeSince from 'sentry/components/timeSince';
  16. import {IconCalendar, IconDelete, IconEllipsis, IconUpload} from 'sentry/icons';
  17. import {t} from 'sentry/locale';
  18. import {space} from 'sentry/styles/space';
  19. import {defined} from 'sentry/utils';
  20. import useDeleteReplay from 'sentry/utils/replays/hooks/useDeleteReplay';
  21. import useShareReplayAtTimestamp from 'sentry/utils/replays/hooks/useShareReplayAtTimestamp';
  22. import type {ReplayError, ReplayRecord} from 'sentry/views/replays/types';
  23. type Props = {
  24. children: ReactNode;
  25. orgSlug: string;
  26. projectSlug: string | null;
  27. replayErrors: ReplayError[];
  28. replayRecord: undefined | ReplayRecord;
  29. isVideoReplay?: boolean;
  30. };
  31. export default function Page({
  32. children,
  33. orgSlug,
  34. replayRecord,
  35. projectSlug,
  36. replayErrors,
  37. isVideoReplay,
  38. }: Props) {
  39. const title = replayRecord
  40. ? `${replayRecord.id} — Session Replay — ${orgSlug}`
  41. : `Session Replay — ${orgSlug}`;
  42. const onShareReplay = useShareReplayAtTimestamp();
  43. const onDeleteReplay = useDeleteReplay({replayId: replayRecord?.id, projectSlug});
  44. const dropdownItems: MenuItemProps[] = [
  45. {
  46. key: 'share',
  47. label: (
  48. <ItemSpacer>
  49. <IconUpload size="sm" />
  50. {t('Share')}
  51. </ItemSpacer>
  52. ),
  53. onAction: onShareReplay,
  54. },
  55. replayRecord?.id && projectSlug
  56. ? {
  57. key: 'delete',
  58. label: (
  59. <ItemSpacer>
  60. <IconDelete size="sm" />
  61. {t('Delete')}
  62. </ItemSpacer>
  63. ),
  64. onAction: onDeleteReplay,
  65. }
  66. : null,
  67. ].filter(defined);
  68. const header = replayRecord?.is_archived ? (
  69. <Header>
  70. <DetailsPageBreadcrumbs orgSlug={orgSlug} replayRecord={replayRecord} />
  71. </Header>
  72. ) : (
  73. <Header>
  74. <DetailsPageBreadcrumbs orgSlug={orgSlug} replayRecord={replayRecord} />
  75. <ButtonActionsWrapper>
  76. {isVideoReplay ? <FeedbackWidgetButton /> : <FeedbackButton />}
  77. <ConfigureReplayCard />
  78. <DropdownMenu
  79. position="bottom-end"
  80. triggerProps={{
  81. showChevron: false,
  82. icon: <IconEllipsis color="subText" />,
  83. }}
  84. size="sm"
  85. items={dropdownItems}
  86. />
  87. </ButtonActionsWrapper>
  88. {replayRecord ? (
  89. <UserBadge
  90. avatarSize={24}
  91. displayName={
  92. <DisplayHeader>
  93. <Title>{replayRecord.user.display_name || t('Anonymous User')}</Title>
  94. {replayRecord && (
  95. <TimeContainer>
  96. <IconCalendar color="gray300" size="xs" />
  97. <TimeSince
  98. date={replayRecord.started_at}
  99. isTooltipHoverable
  100. unitStyle="regular"
  101. />
  102. </TimeContainer>
  103. )}
  104. </DisplayHeader>
  105. }
  106. user={{
  107. name: replayRecord.user.display_name || '',
  108. email: replayRecord.user.email || '',
  109. username: replayRecord.user.username || '',
  110. ip_address: replayRecord.user.ip || '',
  111. id: replayRecord.user.id || '',
  112. }}
  113. hideEmail
  114. />
  115. ) : (
  116. <HeaderPlaceholder width="100%" height="58px" />
  117. )}
  118. <ReplayMetaData
  119. replayRecord={replayRecord}
  120. replayErrors={replayErrors}
  121. showDeadRageClicks={!isVideoReplay}
  122. />
  123. </Header>
  124. );
  125. return (
  126. <SentryDocumentTitle title={title}>
  127. <FullViewport>
  128. {header}
  129. {children}
  130. </FullViewport>
  131. </SentryDocumentTitle>
  132. );
  133. }
  134. const Header = styled(Layout.Header)`
  135. gap: ${space(1)};
  136. padding-bottom: ${space(1.5)};
  137. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  138. gap: ${space(1)} ${space(3)};
  139. padding: ${space(2)} ${space(2)} ${space(1.5)} ${space(2)};
  140. }
  141. `;
  142. // TODO(replay); This could make a lot of sense to put inside HeaderActions by default
  143. const ButtonActionsWrapper = styled(Layout.HeaderActions)`
  144. flex-direction: row;
  145. justify-content: flex-end;
  146. gap: ${space(1)};
  147. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  148. margin-bottom: 0;
  149. }
  150. `;
  151. const ItemSpacer = styled('div')`
  152. display: flex;
  153. gap: ${space(1)};
  154. align-items: center;
  155. `;
  156. const Title = styled('h1')`
  157. ${p => p.theme.overflowEllipsis};
  158. ${p => p.theme.text.pageTitle};
  159. font-size: ${p => p.theme.fontSizeExtraLarge};
  160. color: ${p => p.theme.headingColor};
  161. margin: 0;
  162. line-height: 1.4;
  163. `;
  164. const TimeContainer = styled('div')`
  165. display: flex;
  166. gap: ${space(1)};
  167. align-items: center;
  168. color: ${p => p.theme.gray300};
  169. font-size: ${p => p.theme.fontSizeMedium};
  170. line-height: 1.4;
  171. `;
  172. const DisplayHeader = styled('div')`
  173. display: flex;
  174. flex-direction: column;
  175. `;