page.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 UserBadge from 'sentry/components/idBadge/userBadge';
  6. import FullViewport from 'sentry/components/layouts/fullViewport';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import ConfigureReplayCard from 'sentry/components/replays/configureReplayCard';
  9. import DetailsPageBreadcrumbs from 'sentry/components/replays/header/detailsPageBreadcrumbs';
  10. import FeedbackButton from 'sentry/components/replays/header/feedbackButton';
  11. import HeaderPlaceholder from 'sentry/components/replays/header/headerPlaceholder';
  12. import ReplayMetaData from 'sentry/components/replays/header/replayMetaData';
  13. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  14. import {IconDelete, IconEllipsis, IconUpload} from 'sentry/icons';
  15. import {t} from 'sentry/locale';
  16. import {space} from 'sentry/styles/space';
  17. import {defined} from 'sentry/utils';
  18. import useDeleteReplay from 'sentry/utils/replays/hooks/useDeleteReplay';
  19. import useShareReplayAtTimestamp from 'sentry/utils/replays/hooks/useShareReplayAtTimestamp';
  20. import type {ReplayError, ReplayRecord} from 'sentry/views/replays/types';
  21. type Props = {
  22. children: ReactNode;
  23. orgSlug: string;
  24. projectSlug: string | null;
  25. replayErrors: ReplayError[];
  26. replayRecord: undefined | ReplayRecord;
  27. };
  28. export default function Page({
  29. children,
  30. orgSlug,
  31. replayRecord,
  32. projectSlug,
  33. replayErrors,
  34. }: Props) {
  35. const title = replayRecord
  36. ? `${replayRecord.id} — Session Replay — ${orgSlug}`
  37. : `Session Replay — ${orgSlug}`;
  38. const onShareReplay = useShareReplayAtTimestamp();
  39. const onDeleteReplay = useDeleteReplay({replayId: replayRecord?.id, projectSlug});
  40. const dropdownItems: MenuItemProps[] = [
  41. {
  42. key: 'share',
  43. label: (
  44. <ItemSpacer>
  45. <IconUpload size="sm" />
  46. {t('Share')}
  47. </ItemSpacer>
  48. ),
  49. onAction: onShareReplay,
  50. },
  51. replayRecord?.id && projectSlug
  52. ? {
  53. key: 'delete',
  54. label: (
  55. <ItemSpacer>
  56. <IconDelete size="sm" />
  57. {t('Delete')}
  58. </ItemSpacer>
  59. ),
  60. onAction: onDeleteReplay,
  61. }
  62. : null,
  63. ].filter(defined);
  64. const header = replayRecord?.is_archived ? (
  65. <Header>
  66. <DetailsPageBreadcrumbs orgSlug={orgSlug} replayRecord={replayRecord} />
  67. </Header>
  68. ) : (
  69. <Header>
  70. <DetailsPageBreadcrumbs orgSlug={orgSlug} replayRecord={replayRecord} />
  71. <ButtonActionsWrapper>
  72. <FeedbackButton />
  73. <ConfigureReplayCard />
  74. <DropdownMenu
  75. position="bottom-end"
  76. triggerProps={{
  77. showChevron: false,
  78. icon: <IconEllipsis color="subText" />,
  79. }}
  80. size="sm"
  81. items={dropdownItems}
  82. />
  83. </ButtonActionsWrapper>
  84. {replayRecord ? (
  85. <UserBadge
  86. avatarSize={32}
  87. displayName={
  88. <Layout.Title>
  89. {replayRecord.user.display_name || t('Anonymous User')}
  90. </Layout.Title>
  91. }
  92. user={{
  93. name: replayRecord.user.display_name || '',
  94. email: replayRecord.user.email || '',
  95. username: replayRecord.user.username || '',
  96. ip_address: replayRecord.user.ip || '',
  97. id: replayRecord.user.id || '',
  98. }}
  99. hideEmail
  100. />
  101. ) : (
  102. <HeaderPlaceholder width="100%" height="58px" />
  103. )}
  104. <ReplayMetaData replayRecord={replayRecord} replayErrors={replayErrors} />
  105. </Header>
  106. );
  107. return (
  108. <SentryDocumentTitle title={title}>
  109. <FullViewport>
  110. {header}
  111. {children}
  112. </FullViewport>
  113. </SentryDocumentTitle>
  114. );
  115. }
  116. const Header = styled(Layout.Header)`
  117. gap: ${space(1)};
  118. padding-bottom: ${space(1.5)};
  119. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  120. gap: ${space(1)} ${space(3)};
  121. padding: ${space(2)} ${space(2)} ${space(1.5)} ${space(2)};
  122. }
  123. `;
  124. // TODO(replay); This could make a lot of sense to put inside HeaderActions by default
  125. const ButtonActionsWrapper = styled(Layout.HeaderActions)`
  126. flex-direction: row;
  127. justify-content: flex-end;
  128. gap: ${space(1)};
  129. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  130. margin-bottom: 0;
  131. }
  132. `;
  133. const ItemSpacer = styled('div')`
  134. display: flex;
  135. gap: ${space(1)};
  136. align-items: center;
  137. `;