replayOnboardingPanel.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import emptyStateImg from 'sentry-images/spot/replays-empty-state.svg';
  4. import Alert from 'sentry/components/alert';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import HookOrDefault from 'sentry/components/hookOrDefault';
  8. import ExternalLink from 'sentry/components/links/externalLink';
  9. import OnboardingPanel from 'sentry/components/onboardingPanel';
  10. import {useProjectCreationAccess} from 'sentry/components/projects/useProjectCreationAccess';
  11. import {Tooltip} from 'sentry/components/tooltip';
  12. import {replayPlatforms} from 'sentry/data/platformCategories';
  13. import {IconInfo} from 'sentry/icons';
  14. import {t, tct} from 'sentry/locale';
  15. import PreferencesStore from 'sentry/stores/preferencesStore';
  16. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  17. import {useReplayOnboardingSidebarPanel} from 'sentry/utils/replays/hooks/useReplayOnboarding';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import usePageFilters from 'sentry/utils/usePageFilters';
  20. import useProjects from 'sentry/utils/useProjects';
  21. import {useTeams} from 'sentry/utils/useTeams';
  22. type Breakpoints = {
  23. large: string;
  24. medium: string;
  25. small: string;
  26. xlarge: string;
  27. };
  28. const OnboardingCTAHook = HookOrDefault({
  29. hookName: 'component:replay-onboarding-cta',
  30. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  31. });
  32. const OnboardingAlertHook = HookOrDefault({
  33. hookName: 'component:replay-onboarding-alert',
  34. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  35. });
  36. export default function ReplayOnboardingPanel() {
  37. const preferences = useLegacyStore(PreferencesStore);
  38. const pageFilters = usePageFilters();
  39. const projects = useProjects();
  40. const organization = useOrganization();
  41. const {teams} = useTeams();
  42. const {canCreateProject} = useProjectCreationAccess({organization, teams});
  43. const selectedProjects = projects.projects.filter(p =>
  44. pageFilters.selection.projects.includes(Number(p.id))
  45. );
  46. const hasSelectedProjects = selectedProjects.length > 0;
  47. const allProjectsUnsupported = projects.projects.every(
  48. p => !replayPlatforms.includes(p.platform!)
  49. );
  50. const allSelectedProjectsUnsupported = selectedProjects.every(
  51. p => !replayPlatforms.includes(p.platform!)
  52. );
  53. // if all projects are unsupported we should prompt the user to create a project
  54. // else we prompt to setup
  55. const primaryAction = allProjectsUnsupported ? 'create' : 'setup';
  56. // disable "create" if the user has insufficient permissions
  57. // disable "setup" if the current selected pageFilters are not supported
  58. const primaryActionDisabled =
  59. primaryAction === 'create'
  60. ? !canCreateProject
  61. : allSelectedProjectsUnsupported && hasSelectedProjects;
  62. const breakpoints = preferences.collapsed
  63. ? {
  64. small: '800px',
  65. medium: '992px',
  66. large: '1210px',
  67. xlarge: '1450px',
  68. }
  69. : {
  70. small: '800px',
  71. medium: '1175px',
  72. large: '1375px',
  73. xlarge: '1450px',
  74. };
  75. return (
  76. <Fragment>
  77. <OnboardingAlertHook>
  78. {hasSelectedProjects && allSelectedProjectsUnsupported && (
  79. <Alert icon={<IconInfo />}>
  80. {tct(
  81. `[projectMsg] [action] a project using our [link], or equivalent framework SDK.`,
  82. {
  83. action: primaryAction === 'create' ? t('Create') : t('Select'),
  84. projectMsg: (
  85. <strong>
  86. {t(
  87. `Session Replay isn't available for project %s.`,
  88. selectedProjects[0].slug
  89. )}
  90. </strong>
  91. ),
  92. link: (
  93. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/">
  94. {t('Sentry browser SDK package')}
  95. </ExternalLink>
  96. ),
  97. }
  98. )}
  99. </Alert>
  100. )}
  101. </OnboardingAlertHook>
  102. <OnboardingPanel
  103. image={<HeroImage src={emptyStateImg} breakpoints={breakpoints} />}
  104. >
  105. <OnboardingCTAHook organization={organization}>
  106. <SetupReplaysCTA
  107. orgSlug={organization.slug}
  108. primaryAction={primaryAction}
  109. disabled={primaryActionDisabled}
  110. />
  111. </OnboardingCTAHook>
  112. </OnboardingPanel>
  113. </Fragment>
  114. );
  115. }
  116. interface SetupReplaysCTAProps {
  117. orgSlug: string;
  118. primaryAction: 'setup' | 'create';
  119. disabled?: boolean;
  120. }
  121. export function SetupReplaysCTA({
  122. disabled,
  123. primaryAction = 'setup',
  124. orgSlug,
  125. }: SetupReplaysCTAProps) {
  126. const {activateSidebar} = useReplayOnboardingSidebarPanel();
  127. function renderCTA() {
  128. if (primaryAction === 'setup') {
  129. return (
  130. <Tooltip
  131. title={
  132. <span data-test-id="setup-replays-tooltip">
  133. {t('Select a supported project from the projects dropdown.')}
  134. </span>
  135. }
  136. disabled={!disabled} // we only want to show the tooltip when the button is disabled
  137. >
  138. <Button
  139. data-test-id="setup-replays-btn"
  140. onClick={activateSidebar}
  141. priority="primary"
  142. disabled={disabled}
  143. >
  144. {t('Set Up Replays')}
  145. </Button>
  146. </Tooltip>
  147. );
  148. }
  149. return (
  150. <Tooltip
  151. title={
  152. <span data-test-id="create-project-tooltip">
  153. {t('You do not have permission to create a project.')}
  154. </span>
  155. }
  156. disabled={!disabled}
  157. >
  158. <Button
  159. data-test-id="create-project-btn"
  160. to={`/organizations/${orgSlug}/projects/new/`}
  161. priority="primary"
  162. disabled={disabled}
  163. >
  164. {t('Create Project')}
  165. </Button>
  166. </Tooltip>
  167. );
  168. }
  169. return (
  170. <Fragment>
  171. <h3>{t('Get to the root cause faster')}</h3>
  172. <p>
  173. {t(
  174. 'See a video-like reproduction of your user sessions so you can see what happened before, during, and after an error or latency issue occurred.'
  175. )}
  176. </p>
  177. <ButtonList gap={1}>
  178. {renderCTA()}
  179. <Button
  180. href="https://docs.sentry.io/platforms/javascript/session-replay/"
  181. external
  182. >
  183. {t('Read Docs')}
  184. </Button>
  185. </ButtonList>
  186. </Fragment>
  187. );
  188. }
  189. const HeroImage = styled('img')<{breakpoints: Breakpoints}>`
  190. @media (min-width: ${p => p.breakpoints.small}) {
  191. user-select: none;
  192. position: absolute;
  193. top: 0;
  194. bottom: 0;
  195. width: 220px;
  196. margin-top: auto;
  197. margin-bottom: auto;
  198. transform: translateX(-50%);
  199. left: 50%;
  200. }
  201. @media (min-width: ${p => p.breakpoints.medium}) {
  202. transform: translateX(-55%);
  203. width: 300px;
  204. min-width: 300px;
  205. }
  206. @media (min-width: ${p => p.breakpoints.large}) {
  207. transform: translateX(-60%);
  208. width: 380px;
  209. min-width: 380px;
  210. }
  211. @media (min-width: ${p => p.breakpoints.xlarge}) {
  212. transform: translateX(-65%);
  213. width: 420px;
  214. min-width: 420px;
  215. }
  216. `;
  217. const ButtonList = styled(ButtonBar)`
  218. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  219. `;