platformIntegrationSetup.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'prism-sentry/index.css';
  2. import {Fragment} from 'react';
  3. import {browserHistory, RouteComponentProps} from 'react-router';
  4. import styled from '@emotion/styled';
  5. import AsyncComponent from 'sentry/components/asyncComponent';
  6. import {Button} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import platforms from 'sentry/data/platforms';
  9. import {t} from 'sentry/locale';
  10. import space from 'sentry/styles/space';
  11. import {IntegrationProvider, Organization, Project} from 'sentry/types';
  12. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  13. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  14. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  15. import withOrganization from 'sentry/utils/withOrganization';
  16. import AddInstallationInstructions from 'sentry/views/onboarding/components/integrations/addInstallationInstructions';
  17. import PostInstallCodeSnippet from 'sentry/views/onboarding/components/integrations/postInstallCodeSnippet';
  18. import {AddIntegrationButton} from 'sentry/views/organizationIntegrations/addIntegrationButton';
  19. import FirstEventFooter from './components/firstEventFooter';
  20. import PlatformHeaderButtonBar from './components/platformHeaderButtonBar';
  21. type Props = {
  22. integrationSlug: string;
  23. organization: Organization;
  24. } & RouteComponentProps<{platform: string; projectId: string}, {}> &
  25. AsyncComponent['props'];
  26. type State = {
  27. installed: boolean;
  28. integrations: {providers: IntegrationProvider[]};
  29. project: Project | null;
  30. } & AsyncComponent['state'];
  31. class PlatformIntegrationSetup extends AsyncComponent<Props, State> {
  32. getDefaultState() {
  33. return {
  34. ...super.getDefaultState(),
  35. installed: false,
  36. integrations: {providers: []},
  37. project: null,
  38. };
  39. }
  40. componentDidMount() {
  41. window.scrollTo(0, 0);
  42. const {platform} = this.props.params;
  43. // redirect if platform is not known.
  44. if (!platform || platform === 'other') {
  45. this.redirectToNeutralDocs();
  46. }
  47. }
  48. get provider() {
  49. const {providers} = this.state.integrations;
  50. return providers.length ? providers[0] : null;
  51. }
  52. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  53. const {organization, integrationSlug, params} = this.props;
  54. if (!integrationSlug) {
  55. return [];
  56. }
  57. return [
  58. [
  59. 'integrations',
  60. `/organizations/${organization.slug}/config/integrations/?provider_key=${integrationSlug}`,
  61. ],
  62. ['project', `/projects/${organization.slug}/${params.projectId}/`],
  63. ];
  64. }
  65. handleFullDocsClick = () => {
  66. const {organization} = this.props;
  67. trackAdvancedAnalyticsEvent('growth.onboarding_view_full_docs', {organization});
  68. };
  69. redirectToNeutralDocs() {
  70. const {organization} = this.props;
  71. const {projectId} = this.props.params;
  72. const url = `/organizations/${organization.slug}/projects/${projectId}/getting-started/`;
  73. browserHistory.push(normalizeUrl(url));
  74. }
  75. handleAddIntegration = () => {
  76. this.setState({installed: true});
  77. };
  78. trackSwitchToManual = () => {
  79. const {organization, integrationSlug} = this.props;
  80. trackIntegrationAnalytics('integrations.switch_manual_sdk_setup', {
  81. integration_type: 'first_party',
  82. integration: integrationSlug,
  83. view: 'project_creation',
  84. organization,
  85. });
  86. };
  87. render() {
  88. const {organization, params} = this.props;
  89. const {installed, project} = this.state;
  90. const {projectId, platform} = params;
  91. const provider = this.provider;
  92. const platformIntegration = platforms.find(p => p.id === platform);
  93. if (!provider || !platformIntegration || !project) {
  94. return null;
  95. }
  96. const gettingStartedLink = `/organizations/${organization.slug}/projects/${projectId}/getting-started/`;
  97. // TODO: make dynamic when adding more integrations
  98. const docsLink =
  99. 'https://docs.sentry.io/product/integrations/cloud-monitoring/aws-lambda/';
  100. return (
  101. <OuterWrapper>
  102. <InnerWrapper>
  103. <StyledTitle>
  104. {t('Automatically instrument %s', platformIntegration.name)}
  105. </StyledTitle>
  106. <HeaderButtons>
  107. <PlatformHeaderButtonBar
  108. gettingStartedLink={gettingStartedLink}
  109. docsLink={docsLink}
  110. />
  111. </HeaderButtons>
  112. {!installed ? (
  113. <Fragment>
  114. <AddInstallationInstructions />
  115. <StyledButtonBar gap={1}>
  116. <AddIntegrationButton
  117. provider={provider}
  118. onAddIntegration={this.handleAddIntegration}
  119. organization={organization}
  120. priority="primary"
  121. size="sm"
  122. analyticsParams={{view: 'project_creation', already_installed: false}}
  123. modalParams={{projectId: project.id}}
  124. aria-label={t('Add integration')}
  125. />
  126. <Button
  127. size="sm"
  128. to={{
  129. pathname: window.location.pathname,
  130. query: {manual: '1'},
  131. }}
  132. onClick={this.trackSwitchToManual}
  133. >
  134. {t('Manual Setup')}
  135. </Button>
  136. </StyledButtonBar>
  137. </Fragment>
  138. ) : (
  139. <Fragment>
  140. <PostInstallCodeSnippet provider={provider} />
  141. <FirstEventFooter
  142. project={project}
  143. organization={organization}
  144. docsLink={docsLink}
  145. docsOnClick={this.handleFullDocsClick}
  146. />
  147. </Fragment>
  148. )}
  149. </InnerWrapper>
  150. </OuterWrapper>
  151. );
  152. }
  153. }
  154. const StyledButtonBar = styled(ButtonBar)`
  155. margin-top: ${space(3)};
  156. width: max-content;
  157. @media (max-width: ${p => p.theme.breakpoints.small}) {
  158. width: auto;
  159. grid-row-gap: ${space(1)};
  160. grid-auto-flow: row;
  161. }
  162. `;
  163. const InnerWrapper = styled('div')`
  164. max-width: 850px;
  165. `;
  166. const OuterWrapper = styled('div')`
  167. display: flex;
  168. flex-direction: column;
  169. align-items: center;
  170. margin-top: 50px;
  171. `;
  172. const HeaderButtons = styled('div')`
  173. width: min-content;
  174. margin-bottom: ${space(3)};
  175. `;
  176. const StyledTitle = styled('h2')`
  177. margin: 0;
  178. margin-bottom: ${space(2)};
  179. `;
  180. export default withOrganization(PlatformIntegrationSetup);