platform.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import 'prism-sentry/index.css';
  2. import {Component, Fragment} from 'react';
  3. import {browserHistory, RouteComponentProps} from 'react-router';
  4. import styled from '@emotion/styled';
  5. import {loadDocs} from 'sentry/actionCreators/projects';
  6. import {Client} from 'sentry/api';
  7. import Feature from 'sentry/components/acl/feature';
  8. import Alert from 'sentry/components/alert';
  9. import Button from 'sentry/components/button';
  10. import ButtonBar from 'sentry/components/buttonBar';
  11. import NotFound from 'sentry/components/errors/notFound';
  12. import LoadingError from 'sentry/components/loadingError';
  13. import LoadingIndicator from 'sentry/components/loadingIndicator';
  14. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  15. import {
  16. performance as performancePlatforms,
  17. PlatformKey,
  18. } from 'sentry/data/platformCategories';
  19. import platforms from 'sentry/data/platforms';
  20. import {t, tct} from 'sentry/locale';
  21. import {PageHeader} from 'sentry/styles/organization';
  22. import space from 'sentry/styles/space';
  23. import {Organization, Project} from 'sentry/types';
  24. import Projects from 'sentry/utils/projects';
  25. import withApi from 'sentry/utils/withApi';
  26. import withOrganization from 'sentry/utils/withOrganization';
  27. type Props = {
  28. api: Client;
  29. organization: Organization;
  30. } & RouteComponentProps<{orgId: string; platform: string; projectId: string}, {}>;
  31. type State = {
  32. error: boolean;
  33. html: string;
  34. loading: boolean;
  35. };
  36. class ProjectInstallPlatform extends Component<Props, State> {
  37. state: State = {
  38. loading: true,
  39. error: false,
  40. html: '',
  41. };
  42. componentDidMount() {
  43. this.fetchData();
  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 isGettingStarted() {
  52. return window.location.href.indexOf('getting-started') > 0;
  53. }
  54. fetchData = async () => {
  55. const {api, params} = this.props;
  56. const {orgId, projectId, platform} = params;
  57. this.setState({loading: true});
  58. try {
  59. const {html} = await loadDocs(api, orgId, projectId, platform as PlatformKey);
  60. this.setState({html});
  61. } catch (error) {
  62. this.setState({error});
  63. }
  64. this.setState({loading: false});
  65. };
  66. redirectToNeutralDocs() {
  67. const {orgId, projectId} = this.props.params;
  68. const url = `/organizations/${orgId}/projects/${projectId}/getting-started/`;
  69. browserHistory.push(url);
  70. }
  71. render() {
  72. const {params} = this.props;
  73. const {orgId, projectId} = params;
  74. const platform = platforms.find(p => p.id === params.platform);
  75. if (!platform) {
  76. return <NotFound />;
  77. }
  78. const issueStreamLink = `/organizations/${orgId}/issues/`;
  79. const performanceOverviewLink = `/organizations/${orgId}/performance/`;
  80. const gettingStartedLink = `/organizations/${orgId}/projects/${projectId}/getting-started/`;
  81. const platformLink = platform.link ?? undefined;
  82. return (
  83. <Fragment>
  84. <StyledPageHeader>
  85. <h2>{t('Configure %(platform)s', {platform: platform.name})}</h2>
  86. <ButtonBar gap={1}>
  87. <Button size="sm" to={gettingStartedLink}>
  88. {t('< Back')}
  89. </Button>
  90. <Button size="sm" href={platformLink} external>
  91. {t('Full Documentation')}
  92. </Button>
  93. </ButtonBar>
  94. </StyledPageHeader>
  95. <div>
  96. <Alert type="info" showIcon>
  97. {tct(
  98. `
  99. This is a quick getting started guide. For in-depth instructions
  100. on integrating Sentry with [platform], view
  101. [docLink:our complete documentation].`,
  102. {
  103. platform: platform.name,
  104. docLink: <a href={platformLink} />,
  105. }
  106. )}
  107. </Alert>
  108. {this.state.loading ? (
  109. <LoadingIndicator />
  110. ) : this.state.error ? (
  111. <LoadingError onRetry={this.fetchData} />
  112. ) : (
  113. <Fragment>
  114. <SentryDocumentTitle
  115. title={`${t('Configure')} ${platform.name}`}
  116. projectSlug={projectId}
  117. />
  118. <DocumentationWrapper dangerouslySetInnerHTML={{__html: this.state.html}} />
  119. </Fragment>
  120. )}
  121. {this.isGettingStarted && (
  122. <Projects
  123. key={`${orgId}-${projectId}`}
  124. orgId={orgId}
  125. slugs={[projectId]}
  126. passthroughPlaceholderProject={false}
  127. >
  128. {({projects, initiallyLoaded, fetching, fetchError}) => {
  129. const projectsLoading = !initiallyLoaded && fetching;
  130. const projectFilter =
  131. !projectsLoading && !fetchError && projects.length
  132. ? {
  133. project: (projects[0] as Project).id,
  134. }
  135. : {};
  136. const showPerformancePrompt = performancePlatforms.includes(
  137. platform.id as PlatformKey
  138. );
  139. return (
  140. <Fragment>
  141. {showPerformancePrompt && (
  142. <Feature
  143. features={['performance-view']}
  144. hookName="feature-disabled:performance-new-project"
  145. >
  146. {({hasFeature}) => {
  147. if (hasFeature) {
  148. return null;
  149. }
  150. return (
  151. <StyledAlert type="info" showIcon>
  152. {t(
  153. `Your selected platform supports performance, but your organization does not have performance enabled.`
  154. )}
  155. </StyledAlert>
  156. );
  157. }}
  158. </Feature>
  159. )}
  160. <StyledButtonBar gap={1}>
  161. <Button
  162. priority="primary"
  163. busy={projectsLoading}
  164. to={{
  165. pathname: issueStreamLink,
  166. query: projectFilter,
  167. hash: '#welcome',
  168. }}
  169. >
  170. {t('Take me to Issues')}
  171. </Button>
  172. <Button
  173. busy={projectsLoading}
  174. to={{
  175. pathname: performanceOverviewLink,
  176. query: projectFilter,
  177. }}
  178. >
  179. {t('Take me to Performance')}
  180. </Button>
  181. </StyledButtonBar>
  182. </Fragment>
  183. );
  184. }}
  185. </Projects>
  186. )}
  187. </div>
  188. </Fragment>
  189. );
  190. }
  191. }
  192. const DocumentationWrapper = styled('div')`
  193. line-height: 1.5;
  194. .gatsby-highlight {
  195. margin-bottom: ${space(3)};
  196. &:last-child {
  197. margin-bottom: 0;
  198. }
  199. }
  200. .alert {
  201. margin-bottom: ${space(3)};
  202. border-radius: ${p => p.theme.borderRadius};
  203. }
  204. pre {
  205. word-break: break-all;
  206. white-space: pre-wrap;
  207. }
  208. blockquote {
  209. padding: ${space(1)};
  210. margin-left: 0;
  211. background: ${p => p.theme.alert.info.backgroundLight};
  212. border-left: 2px solid ${p => p.theme.alert.info.border};
  213. }
  214. blockquote > *:last-child {
  215. margin-bottom: 0;
  216. }
  217. `;
  218. const StyledButtonBar = styled(ButtonBar)`
  219. margin-top: ${space(3)};
  220. width: max-content;
  221. @media (max-width: ${p => p.theme.breakpoints.small}) {
  222. width: auto;
  223. grid-row-gap: ${space(1)};
  224. grid-auto-flow: row;
  225. }
  226. `;
  227. const StyledPageHeader = styled(PageHeader)`
  228. margin-bottom: ${space(3)};
  229. h2 {
  230. margin: 0;
  231. }
  232. @media (max-width: ${p => p.theme.breakpoints.small}) {
  233. flex-direction: column;
  234. align-items: flex-start;
  235. h2 {
  236. margin-bottom: ${space(2)};
  237. }
  238. }
  239. `;
  240. const StyledAlert = styled(Alert)`
  241. margin-top: ${space(2)};
  242. `;
  243. export {ProjectInstallPlatform};
  244. export default withApi(withOrganization(ProjectInstallPlatform));