performanceSetupWarning.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import {useEffect, useMemo} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import qs from 'qs';
  5. import connectDotsImg from 'sentry-images/spot/performance-connect-dots.svg';
  6. import {Alert} from 'sentry/components/alert';
  7. import {Button} from 'sentry/components/button';
  8. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  9. import ExternalLink from 'sentry/components/links/externalLink';
  10. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  11. import {withPerformanceOnboarding} from 'sentry/data/platformCategories';
  12. import {IconClose} from 'sentry/icons';
  13. import {t, tct} from 'sentry/locale';
  14. import SidebarPanelStore from 'sentry/stores/sidebarPanelStore';
  15. import {space} from 'sentry/styles/space';
  16. import type {Organization} from 'sentry/types/organization';
  17. import type {Project} from 'sentry/types/project';
  18. import useDismissAlert from 'sentry/utils/useDismissAlert';
  19. import useProjects from 'sentry/utils/useProjects';
  20. import {traceAnalytics} from '../traceAnalytics';
  21. import type {TraceTree} from '../traceModels/traceTree';
  22. import {TraceType} from '../traceType';
  23. type OnlyOrphanErrorWarningsProps = {
  24. organization: Organization;
  25. traceSlug: string | undefined;
  26. tree: TraceTree;
  27. };
  28. function filterProjects(projects: Project[], tree: TraceTree) {
  29. const projectsWithNoPerformance: Project[] = [];
  30. const projectsWithOnboardingChecklist: Project[] = [];
  31. for (const project of projects) {
  32. if (tree.project_ids.has(Number(project.id))) {
  33. if (!project.firstTransactionEvent) {
  34. projectsWithNoPerformance.push(project);
  35. if (project.platform && withPerformanceOnboarding.has(project.platform)) {
  36. projectsWithOnboardingChecklist.push(project);
  37. }
  38. }
  39. }
  40. }
  41. return {projectsWithNoPerformance, projectsWithOnboardingChecklist};
  42. }
  43. export function PerformanceSetupWarning({
  44. traceSlug,
  45. tree,
  46. organization,
  47. }: OnlyOrphanErrorWarningsProps) {
  48. const {projects} = useProjects();
  49. const {projectsWithNoPerformance, projectsWithOnboardingChecklist} = useMemo(() => {
  50. return filterProjects(projects, tree);
  51. }, [projects, tree]);
  52. const LOCAL_STORAGE_KEY = `${traceSlug}:performance-orphan-error-onboarding-banner-hide`;
  53. useEffect(() => {
  54. if (
  55. projectsWithOnboardingChecklist.length > 0 &&
  56. location.hash === '#performance-sidequest'
  57. ) {
  58. SidebarPanelStore.activatePanel(SidebarPanelKey.PERFORMANCE_ONBOARDING);
  59. }
  60. }, [projectsWithOnboardingChecklist]);
  61. const {dismiss: snooze, isDismissed: isSnoozed} = useDismissAlert({
  62. key: LOCAL_STORAGE_KEY,
  63. expirationDays: 7,
  64. });
  65. const {dismiss, isDismissed} = useDismissAlert({
  66. key: LOCAL_STORAGE_KEY,
  67. expirationDays: 365,
  68. });
  69. if (
  70. tree.type !== 'trace' ||
  71. tree.shape !== TraceType.ONLY_ERRORS ||
  72. projectsWithNoPerformance.length === 0
  73. ) {
  74. return null;
  75. }
  76. if (projectsWithOnboardingChecklist.length === 0) {
  77. return (
  78. <Alert type="info" showIcon>
  79. {tct(
  80. "Some of the projects associated with this trace don't support performance monitoring. To learn more about how to setup performance monitoring, visit our [documentation].",
  81. {
  82. documentationLink: (
  83. <ExternalLink href="https://docs.sentry.io/product/performance/getting-started/">
  84. {t('documentation')}
  85. </ExternalLink>
  86. ),
  87. }
  88. )}
  89. </Alert>
  90. );
  91. }
  92. if (isDismissed || isSnoozed) {
  93. return null;
  94. }
  95. return (
  96. <BannerWrapper>
  97. <ActionsWrapper>
  98. <BannerTitle>{t('Your setup is incomplete')}</BannerTitle>
  99. <BannerDescription>
  100. {t(
  101. "Want to know why this string of errors happened? Configure performance monitoring to get a full picture of what's going on."
  102. )}
  103. </BannerDescription>
  104. <ButtonsWrapper>
  105. <ActionButton>
  106. <Button
  107. priority="primary"
  108. onClick={event => {
  109. event.preventDefault();
  110. traceAnalytics.trackPerformanceSetupChecklistTriggered(organization);
  111. browserHistory.replace({
  112. pathname: location.pathname,
  113. query: {
  114. ...qs.parse(location.search),
  115. project: projectsWithOnboardingChecklist.map(project => project.id),
  116. },
  117. hash: '#performance-sidequest',
  118. });
  119. SidebarPanelStore.activatePanel(SidebarPanelKey.PERFORMANCE_ONBOARDING);
  120. }}
  121. >
  122. {t('Start Checklist')}
  123. </Button>
  124. </ActionButton>
  125. <ActionButton>
  126. <Button
  127. onClick={() =>
  128. traceAnalytics.trackPerformanceSetupLearnMoreClicked(organization)
  129. }
  130. href="https://docs.sentry.io/product/performance/"
  131. external
  132. >
  133. {t('Learn More')}
  134. </Button>
  135. </ActionButton>
  136. </ButtonsWrapper>
  137. </ActionsWrapper>
  138. {<Background image={connectDotsImg} />}
  139. <CloseDropdownMenu
  140. position="bottom-end"
  141. triggerProps={{
  142. showChevron: false,
  143. borderless: true,
  144. icon: <IconClose color="subText" />,
  145. }}
  146. size="xs"
  147. items={[
  148. {
  149. key: 'dismiss',
  150. label: t('Dismiss'),
  151. onAction: () => {
  152. dismiss();
  153. },
  154. },
  155. {
  156. key: 'snooze',
  157. label: t('Snooze'),
  158. onAction: () => {
  159. snooze();
  160. },
  161. },
  162. ]}
  163. />
  164. </BannerWrapper>
  165. );
  166. }
  167. const BannerWrapper = styled('div')`
  168. position: relative;
  169. border: 1px solid ${p => p.theme.border};
  170. border-radius: ${p => p.theme.borderRadius};
  171. padding: ${space(2)} ${space(3)};
  172. margin-bottom: ${space(2)};
  173. background: linear-gradient(
  174. 90deg,
  175. ${p => p.theme.backgroundSecondary}00 0%,
  176. ${p => p.theme.backgroundSecondary}FF 70%,
  177. ${p => p.theme.backgroundSecondary}FF 100%
  178. );
  179. container-type: inline-size;
  180. `;
  181. const ActionsWrapper = styled('div')`
  182. max-width: 50%;
  183. `;
  184. const ButtonsWrapper = styled('div')`
  185. display: flex;
  186. align-items: center;
  187. gap: ${space(0.5)};
  188. `;
  189. const BannerTitle = styled('div')`
  190. font-size: ${p => p.theme.fontSizeExtraLarge};
  191. margin-bottom: ${space(1)};
  192. font-weight: ${p => p.theme.fontWeightBold};
  193. `;
  194. const BannerDescription = styled('div')`
  195. margin-bottom: ${space(1.5)};
  196. `;
  197. const CloseDropdownMenu = styled(DropdownMenu)`
  198. position: absolute;
  199. display: block;
  200. top: ${space(1)};
  201. right: ${space(1)};
  202. color: ${p => p.theme.white};
  203. cursor: pointer;
  204. z-index: 1;
  205. `;
  206. const Background = styled('div')<{image: any}>`
  207. display: flex;
  208. justify-self: flex-end;
  209. position: absolute;
  210. top: 14px;
  211. right: 15px;
  212. height: 81%;
  213. width: 100%;
  214. max-width: 413px;
  215. background-image: url(${p => p.image});
  216. background-repeat: no-repeat;
  217. background-size: contain;
  218. @container (max-width: 840px) {
  219. display: none;
  220. }
  221. `;
  222. const ActionButton = styled('div')`
  223. display: flex;
  224. gap: ${space(1)};
  225. `;