replayOnboardingPanel.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import emptyStateImg from 'sentry-images/spot/replays-empty-state.svg';
  4. import {Button} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import HookOrDefault from 'sentry/components/hookOrDefault';
  7. import ExternalLink from 'sentry/components/links/externalLink';
  8. import {useProjectCreationAccess} from 'sentry/components/projects/useProjectCreationAccess';
  9. import QuestionTooltip from 'sentry/components/questionTooltip';
  10. import Accordion from 'sentry/components/replays/accordion';
  11. import ReplayUnsupportedAlert from 'sentry/components/replays/alerts/replayUnsupportedAlert';
  12. import {Tooltip} from 'sentry/components/tooltip';
  13. import {mobile, replayPlatforms} from 'sentry/data/platformCategories';
  14. import {t, tct} from 'sentry/locale';
  15. import PreferencesStore from 'sentry/stores/preferencesStore';
  16. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  17. import {space} from 'sentry/styles/space';
  18. import {useReplayOnboardingSidebarPanel} from 'sentry/utils/replays/hooks/useReplayOnboarding';
  19. import useOrganization from 'sentry/utils/useOrganization';
  20. import usePageFilters from 'sentry/utils/usePageFilters';
  21. import useProjects from 'sentry/utils/useProjects';
  22. import {HeaderContainer, WidgetContainer} from 'sentry/views/profiling/landing/styles';
  23. import ReplayPanel from 'sentry/views/replays/list/replayPanel';
  24. type Breakpoints = {
  25. large: string;
  26. medium: string;
  27. small: string;
  28. xlarge: string;
  29. };
  30. const OnboardingCTAHook = HookOrDefault({
  31. hookName: 'component:replay-onboarding-cta',
  32. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  33. });
  34. const OnboardingAlertHook = HookOrDefault({
  35. hookName: 'component:replay-onboarding-alert',
  36. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  37. });
  38. export default function ReplayOnboardingPanel() {
  39. const preferences = useLegacyStore(PreferencesStore);
  40. const pageFilters = usePageFilters();
  41. const projects = useProjects();
  42. const organization = useOrganization();
  43. const {canCreateProject} = useProjectCreationAccess({organization});
  44. const hasMobileReplays = organization.features.includes('session-replay-mobile-player');
  45. const supportedPlatforms = hasMobileReplays
  46. ? replayPlatforms.concat(mobile)
  47. : replayPlatforms;
  48. const selectedProjects = projects.projects.filter(p =>
  49. pageFilters.selection.projects.includes(Number(p.id))
  50. );
  51. const hasSelectedProjects = selectedProjects.length > 0;
  52. const allProjectsUnsupported = projects.projects.every(
  53. p => !supportedPlatforms.includes(p.platform!)
  54. );
  55. const allSelectedProjectsUnsupported = selectedProjects.every(
  56. p => !supportedPlatforms.includes(p.platform!)
  57. );
  58. // if all projects are unsupported we should prompt the user to create a project
  59. // else we prompt to setup
  60. const primaryAction = allProjectsUnsupported ? 'create' : 'setup';
  61. // disable "create" if the user has insufficient permissions
  62. // disable "setup" if the current selected pageFilters are not supported
  63. const primaryActionDisabled =
  64. primaryAction === 'create'
  65. ? !canCreateProject
  66. : allSelectedProjectsUnsupported && hasSelectedProjects;
  67. const breakpoints = preferences.collapsed
  68. ? {
  69. small: '800px',
  70. medium: '992px',
  71. large: '1210px',
  72. xlarge: '1450px',
  73. }
  74. : {
  75. small: '800px',
  76. medium: '1175px',
  77. large: '1375px',
  78. xlarge: '1450px',
  79. };
  80. return (
  81. <Fragment>
  82. <OnboardingAlertHook>
  83. {hasSelectedProjects && allSelectedProjectsUnsupported && (
  84. <ReplayUnsupportedAlert projectSlug={selectedProjects[0].slug} />
  85. )}
  86. </OnboardingAlertHook>
  87. <ReplayPanel image={<HeroImage src={emptyStateImg} breakpoints={breakpoints} />}>
  88. <OnboardingCTAHook organization={organization}>
  89. <SetupReplaysCTA
  90. orgSlug={organization.slug}
  91. primaryAction={primaryAction}
  92. disabled={primaryActionDisabled}
  93. />
  94. </OnboardingCTAHook>
  95. </ReplayPanel>
  96. </Fragment>
  97. );
  98. }
  99. interface SetupReplaysCTAProps {
  100. orgSlug: string;
  101. primaryAction: 'setup' | 'create';
  102. disabled?: boolean;
  103. }
  104. export function SetupReplaysCTA({
  105. disabled,
  106. primaryAction = 'setup',
  107. orgSlug,
  108. }: SetupReplaysCTAProps) {
  109. const {activateSidebar} = useReplayOnboardingSidebarPanel();
  110. const [expanded, setExpanded] = useState(-1);
  111. const FAQ = [
  112. {
  113. header: (
  114. <QuestionContent>{t('Can I use Session Replay with my app?')}</QuestionContent>
  115. ),
  116. content: (
  117. <AnswerContent>
  118. <div>
  119. {t(
  120. 'Session Replay supports all browser-based applications and certain native mobile platforms, such as iOS and Android. Our native Android and iOS SDKs are currently in alpha. Features are still in progress and may have some bugs. We recognize the irony.'
  121. )}
  122. </div>
  123. <div>
  124. {tct('To access Session Replay for mobile, join our [link:waitlist].', {
  125. link: <ExternalLink href="https://sentry.io/lp/mobile-replay-beta/" />,
  126. })}
  127. </div>
  128. <div>
  129. {t(
  130. 'For browser-based applications, this includes static websites, single-page applications, and also server-side rendered applications. The only prerequisite is that your application uses Sentry JavaScript SDK (version 7.2.0 or greater) either with NPM/Yarn or with our JS Loader script.'
  131. )}
  132. </div>
  133. <div>
  134. {tct(
  135. 'To learn more about which SDKs we support, please visit [link:our docs].',
  136. {
  137. link: (
  138. <ExternalLink href="https://docs.sentry.io/product/session-replay/getting-started/" />
  139. ),
  140. }
  141. )}
  142. </div>
  143. </AnswerContent>
  144. ),
  145. },
  146. {
  147. header: <QuestionContent>{t('What’s the performance overhead?')}</QuestionContent>,
  148. content: (
  149. <AnswerContent>
  150. <div>
  151. {t(
  152. 'Session Replay adds a small amount of performance overhead to your web application. For most web apps, the performance overhead of our client SDK will be imperceptible to end-users. For example, the Sentry site has Replay enabled and we have not seen any significant slowdowns.'
  153. )}
  154. </div>
  155. <div>
  156. {t(
  157. 'The performance overhead generally scales linearly with the DOM complexity of your application. The more DOM state changes that occur in the application lifecycle, the more events that are captured, transmitted, etc.'
  158. )}
  159. </div>
  160. <div>
  161. {tct(
  162. 'To learn more about how we’ve optimized our SDK, please visit [link:our docs].',
  163. {
  164. link: (
  165. <ExternalLink href="https://docs.sentry.io/product/session-replay/performance-overhead/" />
  166. ),
  167. }
  168. )}
  169. </div>
  170. </AnswerContent>
  171. ),
  172. },
  173. {
  174. header: <QuestionContent>{t('How do you protect user data?')}</QuestionContent>,
  175. content: (
  176. <AnswerContent>
  177. <div>
  178. {t(
  179. 'We offer a range of privacy controls to let developers ensure that no sensitive user information leaves the browser. By default, our privacy configuration is very aggressive and masks all text and images, but you can choose to just mask user input text, for example.'
  180. )}
  181. </div>
  182. <div>
  183. {tct(
  184. 'To learn more about how we protect user privacy, please visit [link:our docs].',
  185. {
  186. link: (
  187. <ExternalLink href="https://docs.sentry.io/product/session-replay/protecting-user-privacy/" />
  188. ),
  189. }
  190. )}
  191. </div>
  192. </AnswerContent>
  193. ),
  194. },
  195. ];
  196. function renderCTA() {
  197. if (primaryAction === 'setup') {
  198. return (
  199. <Tooltip
  200. title={
  201. <span data-test-id="setup-replays-tooltip">
  202. {t('Select a supported project from the projects dropdown.')}
  203. </span>
  204. }
  205. disabled={!disabled} // we only want to show the tooltip when the button is disabled
  206. >
  207. <Button
  208. data-test-id="setup-replays-btn"
  209. onClick={activateSidebar}
  210. priority="primary"
  211. disabled={disabled}
  212. >
  213. {t('Set Up Replays')}
  214. </Button>
  215. </Tooltip>
  216. );
  217. }
  218. return (
  219. <Tooltip
  220. title={
  221. <span data-test-id="create-project-tooltip">
  222. {t('You do not have permission to create a project.')}
  223. </span>
  224. }
  225. disabled={!disabled}
  226. >
  227. <Button
  228. data-test-id="create-project-btn"
  229. to={`/organizations/${orgSlug}/projects/new/`}
  230. priority="primary"
  231. disabled={disabled}
  232. >
  233. {t('Create Project')}
  234. </Button>
  235. </Tooltip>
  236. );
  237. }
  238. return (
  239. <CenteredContent>
  240. <h3>{t('Get to the root cause faster')}</h3>
  241. <p>
  242. {t(
  243. '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.'
  244. )}
  245. </p>
  246. <ButtonList gap={1}>
  247. {renderCTA()}
  248. <Button
  249. href="https://docs.sentry.io/product/session-replay/getting-started/"
  250. external
  251. >
  252. {t('Read Docs')}
  253. </Button>
  254. </ButtonList>
  255. <StyledWidgetContainer>
  256. <StyledHeaderContainer>
  257. {t('FAQ')}
  258. <QuestionTooltip
  259. size="xs"
  260. isHoverable
  261. title={tct('See a [link:full list of FAQs].', {
  262. link: (
  263. <ExternalLink href="https://sentry.zendesk.com/hc/en-us/articles/23699186513947-Session-Replay-FAQ" />
  264. ),
  265. })}
  266. />
  267. </StyledHeaderContainer>
  268. <Accordion items={FAQ} expandedIndex={expanded} setExpandedIndex={setExpanded} />
  269. </StyledWidgetContainer>
  270. </CenteredContent>
  271. );
  272. }
  273. const HeroImage = styled('img')<{breakpoints: Breakpoints}>`
  274. @media (min-width: ${p => p.breakpoints.small}) {
  275. user-select: none;
  276. position: absolute;
  277. top: 0;
  278. bottom: 0;
  279. width: 220px;
  280. margin-top: auto;
  281. margin-bottom: auto;
  282. transform: translateX(-50%);
  283. left: 50%;
  284. }
  285. @media (min-width: ${p => p.breakpoints.medium}) {
  286. transform: translateX(-55%);
  287. width: 300px;
  288. min-width: 300px;
  289. }
  290. @media (min-width: ${p => p.breakpoints.large}) {
  291. transform: translateX(-60%);
  292. width: 380px;
  293. min-width: 380px;
  294. }
  295. @media (min-width: ${p => p.breakpoints.xlarge}) {
  296. transform: translateX(-65%);
  297. width: 420px;
  298. min-width: 420px;
  299. }
  300. `;
  301. const ButtonList = styled(ButtonBar)`
  302. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  303. `;
  304. const StyledWidgetContainer = styled(WidgetContainer)`
  305. margin: ${space(4)} 0 ${space(1)} 0;
  306. `;
  307. const CenteredContent = styled('div')`
  308. padding: ${space(3)};
  309. `;
  310. const AnswerContent = styled('div')`
  311. display: grid;
  312. gap: ${space(2)};
  313. padding: ${space(2)};
  314. `;
  315. const QuestionContent = styled('div')`
  316. font-weight: ${p => p.theme.fontWeightBold};
  317. cursor: pointer;
  318. `;
  319. const StyledHeaderContainer = styled(HeaderContainer)`
  320. font-weight: ${p => p.theme.fontWeightBold};
  321. font-size: ${p => p.theme.fontSizeLarge};
  322. color: ${p => p.theme.gray300};
  323. display: flex;
  324. gap: ${space(0.5)};
  325. align-items: center;
  326. `;