replayOnboardingPanel.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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
  85. primaryAction={primaryAction}
  86. projectSlug={selectedProjects[0].slug}
  87. />
  88. )}
  89. </OnboardingAlertHook>
  90. <ReplayPanel image={<HeroImage src={emptyStateImg} breakpoints={breakpoints} />}>
  91. <OnboardingCTAHook organization={organization}>
  92. <SetupReplaysCTA
  93. orgSlug={organization.slug}
  94. primaryAction={primaryAction}
  95. disabled={primaryActionDisabled}
  96. />
  97. </OnboardingCTAHook>
  98. </ReplayPanel>
  99. </Fragment>
  100. );
  101. }
  102. interface SetupReplaysCTAProps {
  103. orgSlug: string;
  104. primaryAction: 'setup' | 'create';
  105. disabled?: boolean;
  106. }
  107. export function SetupReplaysCTA({
  108. disabled,
  109. primaryAction = 'setup',
  110. orgSlug,
  111. }: SetupReplaysCTAProps) {
  112. const {activateSidebar} = useReplayOnboardingSidebarPanel();
  113. const [expanded, setExpanded] = useState(-1);
  114. const FAQ = [
  115. {
  116. header: () => (
  117. <QuestionContent>{t('Can I use Session Replay with my app?')}</QuestionContent>
  118. ),
  119. content: () => (
  120. <AnswerContent>
  121. <div>
  122. {t(
  123. 'Session Replay supports all browser-based applications. This includes static websites, single-page aplications, 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.'
  124. )}
  125. </div>
  126. <div>
  127. {t(
  128. "Replays are integrated with Sentry's tracing data model, enabling you to see replays associated with backend errors as well. You need to have Sentry set up for both your frontend and backend, along with distributed tracing."
  129. )}
  130. </div>
  131. <div>
  132. {tct(
  133. 'To learn more about which SDKs we support, please visit [link:our docs].',
  134. {
  135. link: (
  136. <ExternalLink href="https://docs.sentry.io/product/session-replay/getting-started/" />
  137. ),
  138. }
  139. )}
  140. </div>
  141. </AnswerContent>
  142. ),
  143. },
  144. {
  145. header: () => (
  146. <QuestionContent>{t('What’s the performance overhead?')}</QuestionContent>
  147. ),
  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: () => (
  175. <QuestionContent>{t('How do you protect user data?')}</QuestionContent>
  176. ),
  177. content: () => (
  178. <AnswerContent>
  179. <div>
  180. {t(
  181. '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.'
  182. )}
  183. </div>
  184. <div>
  185. {t(
  186. 'Customers can also use server-side scrubbing capabilities to further filter and remove sensitive user data, or our deletion capabilities to delete individual recordings after ingestion.'
  187. )}
  188. </div>
  189. <div>
  190. {tct(
  191. 'To learn more about how we protect user privacy, please visit [link:our docs].',
  192. {
  193. link: (
  194. <ExternalLink href="https://docs.sentry.io/product/session-replay/protecting-user-privacy/" />
  195. ),
  196. }
  197. )}
  198. </div>
  199. </AnswerContent>
  200. ),
  201. },
  202. ];
  203. function renderCTA() {
  204. if (primaryAction === 'setup') {
  205. return (
  206. <Tooltip
  207. title={
  208. <span data-test-id="setup-replays-tooltip">
  209. {t('Select a supported project from the projects dropdown.')}
  210. </span>
  211. }
  212. disabled={!disabled} // we only want to show the tooltip when the button is disabled
  213. >
  214. <Button
  215. data-test-id="setup-replays-btn"
  216. onClick={activateSidebar}
  217. priority="primary"
  218. disabled={disabled}
  219. >
  220. {t('Set Up Replays')}
  221. </Button>
  222. </Tooltip>
  223. );
  224. }
  225. return (
  226. <Tooltip
  227. title={
  228. <span data-test-id="create-project-tooltip">
  229. {t('You do not have permission to create a project.')}
  230. </span>
  231. }
  232. disabled={!disabled}
  233. >
  234. <Button
  235. data-test-id="create-project-btn"
  236. to={`/organizations/${orgSlug}/projects/new/`}
  237. priority="primary"
  238. disabled={disabled}
  239. >
  240. {t('Create Project')}
  241. </Button>
  242. </Tooltip>
  243. );
  244. }
  245. return (
  246. <CenteredContent>
  247. <h3>{t('Get to the root cause faster')}</h3>
  248. <p>
  249. {t(
  250. '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.'
  251. )}
  252. </p>
  253. <ButtonList gap={1}>
  254. {renderCTA()}
  255. <OnboardingCTAButton />
  256. <Button
  257. href="https://docs.sentry.io/platforms/javascript/session-replay/"
  258. external
  259. >
  260. {t('Read Docs')}
  261. </Button>
  262. </ButtonList>
  263. <StyledWidgetContainer>
  264. <StyledHeaderContainer>
  265. {t('FAQ')}
  266. <QuestionTooltip
  267. size="xs"
  268. isHoverable
  269. title={tct('See a [link:full list of FAQs].', {
  270. link: (
  271. <ExternalLink href="https://help.sentry.io/product-features/other/what-is-session-replay/" />
  272. ),
  273. })}
  274. />
  275. </StyledHeaderContainer>
  276. <Accordion
  277. items={FAQ}
  278. expandedIndex={expanded}
  279. setExpandedIndex={setExpanded}
  280. buttonOnLeft
  281. />
  282. </StyledWidgetContainer>
  283. </CenteredContent>
  284. );
  285. }
  286. const HeroImage = styled('img')<{breakpoints: Breakpoints}>`
  287. @media (min-width: ${p => p.breakpoints.small}) {
  288. user-select: none;
  289. position: absolute;
  290. top: 0;
  291. bottom: 0;
  292. width: 220px;
  293. margin-top: auto;
  294. margin-bottom: auto;
  295. transform: translateX(-50%);
  296. left: 50%;
  297. }
  298. @media (min-width: ${p => p.breakpoints.medium}) {
  299. transform: translateX(-55%);
  300. width: 300px;
  301. min-width: 300px;
  302. }
  303. @media (min-width: ${p => p.breakpoints.large}) {
  304. transform: translateX(-60%);
  305. width: 380px;
  306. min-width: 380px;
  307. }
  308. @media (min-width: ${p => p.breakpoints.xlarge}) {
  309. transform: translateX(-65%);
  310. width: 420px;
  311. min-width: 420px;
  312. }
  313. `;
  314. const ButtonList = styled(ButtonBar)`
  315. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  316. `;
  317. const StyledWidgetContainer = styled(WidgetContainer)`
  318. margin: ${space(4)} 0 ${space(1)} 0;
  319. `;
  320. const CenteredContent = styled('div')`
  321. padding: ${space(3)};
  322. `;
  323. const AnswerContent = styled('div')`
  324. display: grid;
  325. gap: ${space(2)};
  326. padding: ${space(2)};
  327. `;
  328. const QuestionContent = styled('div')`
  329. font-weight: bold;
  330. cursor: pointer;
  331. `;
  332. const StyledHeaderContainer = styled(HeaderContainer)`
  333. font-weight: bold;
  334. font-size: ${p => p.theme.fontSizeLarge};
  335. color: ${p => p.theme.gray300};
  336. display: flex;
  337. gap: ${space(0.5)};
  338. align-items: center;
  339. `;