replayOnboardingPanel.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 {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 useAllMobileProj from 'sentry/views/replays/detail/useAllMobileProj';
  24. import ReplayPanel from 'sentry/views/replays/list/replayPanel';
  25. type Breakpoints = {
  26. large: string;
  27. medium: string;
  28. small: string;
  29. xlarge: string;
  30. };
  31. const OnboardingCTAHook = HookOrDefault({
  32. hookName: 'component:replay-onboarding-cta',
  33. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  34. });
  35. const OnboardingAlertHook = HookOrDefault({
  36. hookName: 'component:replay-onboarding-alert',
  37. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  38. });
  39. export default function ReplayOnboardingPanel() {
  40. const preferences = useLegacyStore(PreferencesStore);
  41. const pageFilters = usePageFilters();
  42. const projects = useProjects();
  43. const organization = useOrganization();
  44. const {canCreateProject} = useProjectCreationAccess({organization});
  45. const supportedPlatforms = replayPlatforms;
  46. const selectedProjects = projects.projects.filter(p =>
  47. pageFilters.selection.projects.includes(Number(p.id))
  48. );
  49. const hasSelectedProjects = selectedProjects.length > 0;
  50. const allProjectsUnsupported = projects.projects.every(
  51. p => !supportedPlatforms.includes(p.platform!)
  52. );
  53. const allSelectedProjectsUnsupported = selectedProjects.every(
  54. p => !supportedPlatforms.includes(p.platform!)
  55. );
  56. // if all projects are unsupported we should prompt the user to create a project
  57. // else we prompt to setup
  58. const primaryAction = allProjectsUnsupported ? 'create' : 'setup';
  59. // disable "create" if the user has insufficient permissions
  60. // disable "setup" if the current selected pageFilters are not supported
  61. const primaryActionDisabled =
  62. primaryAction === 'create'
  63. ? !canCreateProject
  64. : allSelectedProjectsUnsupported && hasSelectedProjects;
  65. const breakpoints = preferences.collapsed
  66. ? {
  67. small: '800px',
  68. medium: '992px',
  69. large: '1210px',
  70. xlarge: '1450px',
  71. }
  72. : {
  73. small: '800px',
  74. medium: '1175px',
  75. large: '1375px',
  76. xlarge: '1450px',
  77. };
  78. return (
  79. <Fragment>
  80. <OnboardingAlertHook>
  81. {hasSelectedProjects && allSelectedProjectsUnsupported && (
  82. <ReplayUnsupportedAlert projectSlug={selectedProjects[0].slug} />
  83. )}
  84. </OnboardingAlertHook>
  85. <ReplayPanel image={<HeroImage src={emptyStateImg} breakpoints={breakpoints} />}>
  86. <OnboardingCTAHook organization={organization}>
  87. <SetupReplaysCTA
  88. orgSlug={organization.slug}
  89. primaryAction={primaryAction}
  90. disabled={primaryActionDisabled}
  91. />
  92. </OnboardingCTAHook>
  93. </ReplayPanel>
  94. </Fragment>
  95. );
  96. }
  97. interface SetupReplaysCTAProps {
  98. orgSlug: string;
  99. primaryAction: 'setup' | 'create';
  100. disabled?: boolean;
  101. }
  102. export function SetupReplaysCTA({
  103. disabled,
  104. primaryAction = 'setup',
  105. orgSlug,
  106. }: SetupReplaysCTAProps) {
  107. const {activateSidebar} = useReplayOnboardingSidebarPanel();
  108. const [expanded, setExpanded] = useState(-1);
  109. const {allMobileProj} = useAllMobileProj();
  110. const FAQ = [
  111. {
  112. header: (
  113. <QuestionContent>{t('Can I use Session Replay with my app?')}</QuestionContent>
  114. ),
  115. content: (
  116. <AnswerContent>
  117. <div>
  118. {t(
  119. 'Session Replay supports all browser-based applications and certain native mobile platforms, such as Android, iOS, and React Native. Our mobile SDKs are currently in beta. Features are still in progress and may have some bugs. We recognize the irony.'
  120. )}
  121. </div>
  122. <div>
  123. {t(
  124. '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.'
  125. )}
  126. </div>
  127. <div>
  128. {tct(
  129. 'To learn more about which SDKs we support, please visit [link:our docs].',
  130. {
  131. link: (
  132. <ExternalLink href="https://docs.sentry.io/product/session-replay/getting-started/" />
  133. ),
  134. }
  135. )}
  136. </div>
  137. </AnswerContent>
  138. ),
  139. },
  140. {
  141. header: <QuestionContent>{t('What’s the performance overhead?')}</QuestionContent>,
  142. content: (
  143. <AnswerContent>
  144. <div>
  145. {t(
  146. 'Session Replay adds a small amount of performance overhead to your web or mobile application. For most applications, 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.'
  147. )}
  148. </div>
  149. <div>
  150. {t(
  151. 'For web, 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.'
  152. )}
  153. </div>
  154. <div>
  155. {tct(
  156. 'With early customers of Mobile Replay, the overhead was not noticeable by end-users, but depending on your application complexity, you may discover the recording overhead may negatively impact your mobile application performance. If you do, please let us know on GitHub: [android:Android], [ios:iOS], and [rn:React Native].',
  157. {
  158. android: (
  159. <ExternalLink href="https://github.com/getsentry/sentry-java/issues/new/choose" />
  160. ),
  161. ios: (
  162. <ExternalLink href="https://github.com/getsentry/sentry-cocoa/issues/new/choose" />
  163. ),
  164. rn: (
  165. <ExternalLink href="https://github.com/getsentry/sentry-react-native/issues/new/choose" />
  166. ),
  167. }
  168. )}
  169. </div>
  170. <div>
  171. {tct(
  172. 'To learn more about how we’ve optimized our SDK, please visit [link:our docs].',
  173. {
  174. link: (
  175. <ExternalLink href="https://docs.sentry.io/product/explore/session-replay/performance-overhead/" />
  176. ),
  177. }
  178. )}
  179. </div>
  180. </AnswerContent>
  181. ),
  182. },
  183. {
  184. header: <QuestionContent>{t('How do you protect user data?')}</QuestionContent>,
  185. content: (
  186. <AnswerContent>
  187. <div>
  188. {t(
  189. '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.'
  190. )}
  191. </div>
  192. <div>
  193. {tct(
  194. 'To learn more about how we protect user privacy, please visit [link:our docs].',
  195. {
  196. link: (
  197. <ExternalLink href="https://docs.sentry.io/product/session-replay/protecting-user-privacy/" />
  198. ),
  199. }
  200. )}
  201. </div>
  202. </AnswerContent>
  203. ),
  204. },
  205. ];
  206. function renderCTA() {
  207. if (primaryAction === 'setup') {
  208. return (
  209. <Tooltip
  210. title={
  211. <span data-test-id="setup-replays-tooltip">
  212. {t('Select a supported project from the projects dropdown.')}
  213. </span>
  214. }
  215. disabled={!disabled} // we only want to show the tooltip when the button is disabled
  216. >
  217. <Button
  218. data-test-id="setup-replays-btn"
  219. onClick={activateSidebar}
  220. priority="primary"
  221. disabled={disabled}
  222. >
  223. {t('Set Up Replays')}
  224. </Button>
  225. </Tooltip>
  226. );
  227. }
  228. return (
  229. <Tooltip
  230. title={
  231. <span data-test-id="create-project-tooltip">
  232. {t('You do not have permission to create a project.')}
  233. </span>
  234. }
  235. disabled={!disabled}
  236. >
  237. <Button
  238. data-test-id="create-project-btn"
  239. to={`/organizations/${orgSlug}/projects/new/`}
  240. priority="primary"
  241. disabled={disabled}
  242. >
  243. {t('Create Project')}
  244. </Button>
  245. </Tooltip>
  246. );
  247. }
  248. return (
  249. <CenteredContent>
  250. <h3>{t('Get to the root cause faster')}</h3>
  251. <p>
  252. {t(
  253. '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.'
  254. )}
  255. </p>
  256. <ButtonList gap={1}>
  257. {renderCTA()}
  258. <Button
  259. href={
  260. allMobileProj
  261. ? 'https://docs.sentry.io/product/explore/session-replay/mobile/'
  262. : 'https://docs.sentry.io/product/explore/session-replay/'
  263. }
  264. external
  265. >
  266. {t('Read Docs')}
  267. </Button>
  268. </ButtonList>
  269. <StyledWidgetContainer>
  270. <StyledHeaderContainer>
  271. {t('FAQ')}
  272. <QuestionTooltip
  273. size="xs"
  274. isHoverable
  275. title={tct('See a [link:full list of FAQs].', {
  276. link: (
  277. <ExternalLink href="https://sentry.zendesk.com/hc/en-us/articles/23699186513947-Session-Replay-FAQ" />
  278. ),
  279. })}
  280. />
  281. </StyledHeaderContainer>
  282. <Accordion items={FAQ} expandedIndex={expanded} setExpandedIndex={setExpanded} />
  283. </StyledWidgetContainer>
  284. </CenteredContent>
  285. );
  286. }
  287. const HeroImage = styled('img')<{breakpoints: Breakpoints}>`
  288. @media (min-width: ${p => p.breakpoints.small}) {
  289. user-select: none;
  290. position: absolute;
  291. top: 0;
  292. bottom: 0;
  293. width: 220px;
  294. margin-top: auto;
  295. margin-bottom: auto;
  296. transform: translateX(-50%);
  297. left: 50%;
  298. }
  299. @media (min-width: ${p => p.breakpoints.medium}) {
  300. transform: translateX(-55%);
  301. width: 300px;
  302. min-width: 300px;
  303. }
  304. @media (min-width: ${p => p.breakpoints.large}) {
  305. transform: translateX(-60%);
  306. width: 380px;
  307. min-width: 380px;
  308. }
  309. @media (min-width: ${p => p.breakpoints.xlarge}) {
  310. transform: translateX(-65%);
  311. width: 420px;
  312. min-width: 420px;
  313. }
  314. `;
  315. const ButtonList = styled(ButtonBar)`
  316. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  317. `;
  318. const StyledWidgetContainer = styled(WidgetContainer)`
  319. margin: ${space(4)} 0 ${space(1)} 0;
  320. `;
  321. const CenteredContent = styled('div')`
  322. padding: ${space(3)};
  323. `;
  324. const AnswerContent = styled('div')`
  325. display: grid;
  326. gap: ${space(2)};
  327. padding: ${space(2)};
  328. `;
  329. const QuestionContent = styled('div')`
  330. font-weight: ${p => p.theme.fontWeightBold};
  331. cursor: pointer;
  332. `;
  333. const StyledHeaderContainer = styled(HeaderContainer)`
  334. font-weight: ${p => p.theme.fontWeightBold};
  335. font-size: ${p => p.theme.fontSizeLarge};
  336. color: ${p => p.theme.gray300};
  337. display: flex;
  338. gap: ${space(0.5)};
  339. align-items: center;
  340. `;