platformIntegrationSetup.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import {Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Button} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  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 {trackAnalytics} from 'sentry/utils/analytics';
  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. DeprecatedAsyncComponent['props'];
  25. type State = {
  26. installed: boolean;
  27. integrations: {providers: IntegrationProvider[]};
  28. project: Project | null;
  29. } & DeprecatedAsyncComponent['state'];
  30. class PlatformIntegrationSetup extends DeprecatedAsyncComponent<Props, State> {
  31. getDefaultState() {
  32. return {
  33. ...super.getDefaultState(),
  34. installed: false,
  35. integrations: {providers: []},
  36. project: null,
  37. };
  38. }
  39. componentDidMount() {
  40. super.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<DeprecatedAsyncComponent['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. trackAnalytics('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);