platform.tsx 8.5 KB

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