page.tsx 6.0 KB

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