replayOnboardingPanel.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 Accordion from 'sentry/components/accordion/accordion';
  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 {useProjectCreationAccess} from 'sentry/components/projects/useProjectCreationAccess';
  10. import QuestionTooltip from 'sentry/components/questionTooltip';
  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: () => (
  148. <QuestionContent>{t('What’s the performance overhead?')}</QuestionContent>
  149. ),
  150. content: () => (
  151. <AnswerContent>
  152. <div>
  153. {t(
  154. '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.'
  155. )}
  156. </div>
  157. <div>
  158. {t(
  159. '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.'
  160. )}
  161. </div>
  162. <div>
  163. {tct(
  164. 'To learn more about how we’ve optimized our SDK, please visit [link:our docs].',
  165. {
  166. link: (
  167. <ExternalLink href="https://docs.sentry.io/product/session-replay/performance-overhead/" />
  168. ),
  169. }
  170. )}
  171. </div>
  172. </AnswerContent>
  173. ),
  174. },
  175. {
  176. header: () => (
  177. <QuestionContent>{t('How do you protect user data?')}</QuestionContent>
  178. ),
  179. content: () => (
  180. <AnswerContent>
  181. <div>
  182. {t(
  183. '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.'
  184. )}
  185. </div>
  186. <div>
  187. {tct(
  188. 'To learn more about how we protect user privacy, please visit [link:our docs].',
  189. {
  190. link: (
  191. <ExternalLink href="https://docs.sentry.io/product/session-replay/protecting-user-privacy/" />
  192. ),
  193. }
  194. )}
  195. </div>
  196. </AnswerContent>
  197. ),
  198. },
  199. ];
  200. function renderCTA() {
  201. if (primaryAction === 'setup') {
  202. return (
  203. <Tooltip
  204. title={
  205. <span data-test-id="setup-replays-tooltip">
  206. {t('Select a supported project from the projects dropdown.')}
  207. </span>
  208. }
  209. disabled={!disabled} // we only want to show the tooltip when the button is disabled
  210. >
  211. <Button
  212. data-test-id="setup-replays-btn"
  213. onClick={activateSidebar}
  214. priority="primary"
  215. disabled={disabled}
  216. >
  217. {t('Set Up Replays')}
  218. </Button>
  219. </Tooltip>
  220. );
  221. }
  222. return (
  223. <Tooltip
  224. title={
  225. <span data-test-id="create-project-tooltip">
  226. {t('You do not have permission to create a project.')}
  227. </span>
  228. }
  229. disabled={!disabled}
  230. >
  231. <Button
  232. data-test-id="create-project-btn"
  233. to={`/organizations/${orgSlug}/projects/new/`}
  234. priority="primary"
  235. disabled={disabled}
  236. >
  237. {t('Create Project')}
  238. </Button>
  239. </Tooltip>
  240. );
  241. }
  242. return (
  243. <CenteredContent>
  244. <h3>{t('Get to the root cause faster')}</h3>
  245. <p>
  246. {t(
  247. '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.'
  248. )}
  249. </p>
  250. <ButtonList gap={1}>
  251. {renderCTA()}
  252. <Button
  253. href="https://docs.sentry.io/product/session-replay/getting-started/"
  254. external
  255. >
  256. {t('Read Docs')}
  257. </Button>
  258. </ButtonList>
  259. <StyledWidgetContainer>
  260. <StyledHeaderContainer>
  261. {t('FAQ')}
  262. <QuestionTooltip
  263. size="xs"
  264. isHoverable
  265. title={tct('See a [link:full list of FAQs].', {
  266. link: (
  267. <ExternalLink href="https://sentry.zendesk.com/hc/en-us/articles/23699186513947-Session-Replay-FAQ" />
  268. ),
  269. })}
  270. />
  271. </StyledHeaderContainer>
  272. <Accordion
  273. items={FAQ}
  274. expandedIndex={expanded}
  275. setExpandedIndex={setExpanded}
  276. buttonOnLeft
  277. />
  278. </StyledWidgetContainer>
  279. </CenteredContent>
  280. );
  281. }
  282. const HeroImage = styled('img')<{breakpoints: Breakpoints}>`
  283. @media (min-width: ${p => p.breakpoints.small}) {
  284. user-select: none;
  285. position: absolute;
  286. top: 0;
  287. bottom: 0;
  288. width: 220px;
  289. margin-top: auto;
  290. margin-bottom: auto;
  291. transform: translateX(-50%);
  292. left: 50%;
  293. }
  294. @media (min-width: ${p => p.breakpoints.medium}) {
  295. transform: translateX(-55%);
  296. width: 300px;
  297. min-width: 300px;
  298. }
  299. @media (min-width: ${p => p.breakpoints.large}) {
  300. transform: translateX(-60%);
  301. width: 380px;
  302. min-width: 380px;
  303. }
  304. @media (min-width: ${p => p.breakpoints.xlarge}) {
  305. transform: translateX(-65%);
  306. width: 420px;
  307. min-width: 420px;
  308. }
  309. `;
  310. const ButtonList = styled(ButtonBar)`
  311. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  312. `;
  313. const StyledWidgetContainer = styled(WidgetContainer)`
  314. margin: ${space(4)} 0 ${space(1)} 0;
  315. `;
  316. const CenteredContent = styled('div')`
  317. padding: ${space(3)};
  318. `;
  319. const AnswerContent = styled('div')`
  320. display: grid;
  321. gap: ${space(2)};
  322. padding: ${space(2)};
  323. `;
  324. const QuestionContent = styled('div')`
  325. font-weight: bold;
  326. cursor: pointer;
  327. `;
  328. const StyledHeaderContainer = styled(HeaderContainer)`
  329. font-weight: bold;
  330. font-size: ${p => p.theme.fontSizeLarge};
  331. color: ${p => p.theme.gray300};
  332. display: flex;
  333. gap: ${space(0.5)};
  334. align-items: center;
  335. `;