platformIntegrationSetup.tsx 6.3 KB

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