replayOnboardingPanel.tsx 11 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 {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 OnboardingCTAButton = HookOrDefault({
  35. hookName: 'component:replay-onboarding-cta-button',
  36. defaultComponent: null,
  37. });
  38. const OnboardingAlertHook = HookOrDefault({
  39. hookName: 'component:replay-onboarding-alert',
  40. defaultComponent: ({children}) => <Fragment>{children}</Fragment>,
  41. });
  42. export default function ReplayOnboardingPanel() {
  43. const preferences = useLegacyStore(PreferencesStore);
  44. const pageFilters = usePageFilters();
  45. const projects = useProjects();
  46. const organization = useOrganization();
  47. const {canCreateProject} = useProjectCreationAccess({organization});
  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 => !replayPlatforms.includes(p.platform!)
  54. );
  55. const allSelectedProjectsUnsupported = selectedProjects.every(
  56. p => !replayPlatforms.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. <OnboardingCTAButton />
  253. <Button
  254. href="https://docs.sentry.io/product/session-replay/getting-started/"
  255. external
  256. >
  257. {t('Read Docs')}
  258. </Button>
  259. </ButtonList>
  260. <StyledWidgetContainer>
  261. <StyledHeaderContainer>
  262. {t('FAQ')}
  263. <QuestionTooltip
  264. size="xs"
  265. isHoverable
  266. title={tct('See a [link:full list of FAQs].', {
  267. link: (
  268. <ExternalLink href="https://help.sentry.io/product-features/other/what-is-session-replay/" />
  269. ),
  270. })}
  271. />
  272. </StyledHeaderContainer>
  273. <Accordion
  274. items={FAQ}
  275. expandedIndex={expanded}
  276. setExpandedIndex={setExpanded}
  277. buttonOnLeft
  278. />
  279. </StyledWidgetContainer>
  280. </CenteredContent>
  281. );
  282. }
  283. const HeroImage = styled('img')<{breakpoints: Breakpoints}>`
  284. @media (min-width: ${p => p.breakpoints.small}) {
  285. user-select: none;
  286. position: absolute;
  287. top: 0;
  288. bottom: 0;
  289. width: 220px;
  290. margin-top: auto;
  291. margin-bottom: auto;
  292. transform: translateX(-50%);
  293. left: 50%;
  294. }
  295. @media (min-width: ${p => p.breakpoints.medium}) {
  296. transform: translateX(-55%);
  297. width: 300px;
  298. min-width: 300px;
  299. }
  300. @media (min-width: ${p => p.breakpoints.large}) {
  301. transform: translateX(-60%);
  302. width: 380px;
  303. min-width: 380px;
  304. }
  305. @media (min-width: ${p => p.breakpoints.xlarge}) {
  306. transform: translateX(-65%);
  307. width: 420px;
  308. min-width: 420px;
  309. }
  310. `;
  311. const ButtonList = styled(ButtonBar)`
  312. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  313. `;
  314. const StyledWidgetContainer = styled(WidgetContainer)`
  315. margin: ${space(4)} 0 ${space(1)} 0;
  316. `;
  317. const CenteredContent = styled('div')`
  318. padding: ${space(3)};
  319. `;
  320. const AnswerContent = styled('div')`
  321. display: grid;
  322. gap: ${space(2)};
  323. padding: ${space(2)};
  324. `;
  325. const QuestionContent = styled('div')`
  326. font-weight: bold;
  327. cursor: pointer;
  328. `;
  329. const StyledHeaderContainer = styled(HeaderContainer)`
  330. font-weight: bold;
  331. font-size: ${p => p.theme.fontSizeLarge};
  332. color: ${p => p.theme.gray300};
  333. display: flex;
  334. gap: ${space(0.5)};
  335. align-items: center;
  336. `;