platformIntegrationSetup.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import 'prism-sentry/index.css';
  2. import {Fragment} from 'react';
  3. import {browserHistory, WithRouterProps} from 'react-router';
  4. import styled from '@emotion/styled';
  5. import AsyncComponent from 'app/components/asyncComponent';
  6. import Button from 'app/components/button';
  7. import ButtonBar from 'app/components/buttonBar';
  8. import platforms from 'app/data/platforms';
  9. import {t} from 'app/locale';
  10. import {PageHeader} from 'app/styles/organization';
  11. import space from 'app/styles/space';
  12. import {IntegrationProvider, Organization, Project} from 'app/types';
  13. import {trackIntegrationEvent} from 'app/utils/integrationUtil';
  14. import withOrganization from 'app/utils/withOrganization';
  15. import FirstEventFooter from 'app/views/onboarding/components/firstEventFooter';
  16. import AddInstallationInstructions from 'app/views/onboarding/components/integrations/addInstallationInstructions';
  17. import PostInstallCodeSnippet from 'app/views/onboarding/components/integrations/postInstallCodeSnippet';
  18. import AddIntegrationButton from 'app/views/organizationIntegrations/addIntegrationButton';
  19. import PlatformHeaderButtonBar from './components/platformHeaderButtonBar';
  20. type Props = {
  21. organization: Organization;
  22. integrationSlug: string;
  23. } & WithRouterProps<{orgId: string; projectId: string; platform: 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. redirectToNeutralDocs() {
  65. const {orgId, projectId} = this.props.params;
  66. const url = `/organizations/${orgId}/projects/${projectId}/getting-started/`;
  67. browserHistory.push(url);
  68. }
  69. handleAddIntegration = () => {
  70. this.setState({installed: true});
  71. };
  72. trackSwitchToManual = () => {
  73. const {organization, integrationSlug} = this.props;
  74. trackIntegrationEvent(
  75. 'integrations.switch_manual_sdk_setup',
  76. {
  77. integration_type: 'first_party',
  78. integration: integrationSlug,
  79. view: 'project_creation',
  80. },
  81. organization
  82. );
  83. };
  84. render() {
  85. const {organization, params} = this.props;
  86. const {installed, project} = this.state;
  87. const {projectId, orgId, platform} = params;
  88. const provider = this.provider;
  89. const platformIntegration = platforms.find(p => p.id === platform);
  90. if (!provider || !platformIntegration || !project) {
  91. return null;
  92. }
  93. const gettingStartedLink = `/organizations/${orgId}/projects/${projectId}/getting-started/`;
  94. //TODO: make dynamic when adding more integrations
  95. const docsLink = 'https://docs.sentry.io/product/integrations/aws-lambda/';
  96. return (
  97. <OuterWrapper>
  98. <StyledPageHeader>
  99. <StyledTitle>
  100. {t('Automatically instrument %s', platformIntegration.name)}
  101. </StyledTitle>
  102. <PlatformHeaderButtonBar
  103. gettingStartedLink={gettingStartedLink}
  104. docsLink={docsLink}
  105. />
  106. </StyledPageHeader>
  107. <InnerWrapper>
  108. {!installed ? (
  109. <Fragment>
  110. <AddInstallationInstructions />
  111. <StyledButtonBar gap={1}>
  112. <AddIntegrationButton
  113. provider={provider}
  114. onAddIntegration={this.handleAddIntegration}
  115. organization={organization}
  116. priority="primary"
  117. size="small"
  118. analyticsParams={{view: 'project_creation', already_installed: false}}
  119. modalParams={{projectId: project.id}}
  120. />
  121. <Button
  122. size="small"
  123. to={{
  124. pathname: window.location.pathname,
  125. query: {manual: '1'},
  126. }}
  127. onClick={this.trackSwitchToManual}
  128. >
  129. {t('Manual Setup')}
  130. </Button>
  131. </StyledButtonBar>
  132. </Fragment>
  133. ) : (
  134. <Fragment>
  135. <PostInstallCodeSnippet provider={provider} />
  136. <FirstEventFooter
  137. project={project}
  138. organization={organization}
  139. docsLink={docsLink}
  140. />
  141. </Fragment>
  142. )}
  143. </InnerWrapper>
  144. </OuterWrapper>
  145. );
  146. }
  147. }
  148. const StyledButtonBar = styled(ButtonBar)`
  149. margin-top: ${space(3)};
  150. width: max-content;
  151. @media (max-width: ${p => p.theme.breakpoints[0]}) {
  152. width: auto;
  153. grid-row-gap: ${space(1)};
  154. grid-auto-flow: row;
  155. }
  156. `;
  157. const InnerWrapper = styled('div')`
  158. width: 850px;
  159. `;
  160. const OuterWrapper = styled('div')`
  161. display: flex;
  162. flex-direction: column;
  163. align-items: center;
  164. margin-top: 50px;
  165. `;
  166. const StyledPageHeader = styled(PageHeader)`
  167. margin-bottom: ${space(3)};
  168. `;
  169. const StyledTitle = styled('h2')`
  170. margin: 0 ${space(3)} 0 0;
  171. `;
  172. export default withOrganization(PlatformIntegrationSetup);