replayOnboardingPanel.tsx 7.1 KB

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