platformIntegrationSetup.tsx 6.4 KB

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