overview.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import AsyncComponent from 'sentry/components/asyncComponent';
  4. import AutoSelectText from 'sentry/components/autoSelectText';
  5. import Button from 'sentry/components/button';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import PlatformPicker from 'sentry/components/platformPicker';
  8. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  9. import {PlatformKey} from 'sentry/data/platformCategories';
  10. import {t, tct} from 'sentry/locale';
  11. import space from 'sentry/styles/space';
  12. import {Organization} from 'sentry/types';
  13. import recreateRoute from 'sentry/utils/recreateRoute';
  14. import withOrganization from 'sentry/utils/withOrganization';
  15. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  16. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  17. import {ProjectKey} from 'sentry/views/settings/project/projectKeys/types';
  18. type Props = RouteComponentProps<{orgId: string; projectId: string}, {}> & {
  19. organization: Organization;
  20. } & AsyncComponent['props'];
  21. type State = {
  22. keyList: Array<ProjectKey> | null;
  23. } & AsyncComponent['state'];
  24. class ProjectInstallOverview extends AsyncComponent<Props, State> {
  25. get isGettingStarted() {
  26. return window.location.href.indexOf('getting-started') > 0;
  27. }
  28. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  29. const {orgId, projectId} = this.props.params;
  30. return [['keyList', `/projects/${orgId}/${projectId}/keys/`]];
  31. }
  32. redirectToDocs = (platform: PlatformKey | null) => {
  33. const {orgId, projectId} = this.props.params;
  34. const installUrl = this.isGettingStarted
  35. ? `/organizations/${orgId}/projects/${projectId}/getting-started/${platform}/`
  36. : recreateRoute(`${platform}/`, {
  37. ...this.props,
  38. stepBack: -1,
  39. });
  40. browserHistory.push(installUrl);
  41. };
  42. toggleDsn = () => {
  43. this.setState(state => ({showDsn: !state.showDsn}));
  44. };
  45. render() {
  46. const {orgId, projectId} = this.props.params;
  47. const {keyList, showDsn} = this.state;
  48. const issueStreamLink = `/organizations/${orgId}/issues/#welcome`;
  49. return (
  50. <div>
  51. <SentryDocumentTitle title={t('Instrumentation')} projectSlug={projectId} />
  52. <SettingsPageHeader title={t('Configure your application')} />
  53. <TextBlock>
  54. {t(
  55. 'Get started by selecting the platform or language that powers your application.'
  56. )}
  57. </TextBlock>
  58. {showDsn ? (
  59. <DsnInfo>
  60. <DsnContainer>
  61. <strong>{t('DSN')}</strong>
  62. <DsnValue>{keyList?.[0].dsn.public}</DsnValue>
  63. </DsnContainer>
  64. <Button priority="primary" to={issueStreamLink}>
  65. {t('Got it! Take me to the Issue Stream.')}
  66. </Button>
  67. </DsnInfo>
  68. ) : (
  69. <p>
  70. <small>
  71. {tct('Already have things setup? [link:Get your DSN]', {
  72. link: (
  73. <Button
  74. priority="link"
  75. onClick={this.toggleDsn}
  76. aria-label={t('Get your DSN')}
  77. />
  78. ),
  79. })}
  80. .
  81. </small>
  82. </p>
  83. )}
  84. <PlatformPicker
  85. setPlatform={this.redirectToDocs}
  86. showOther={false}
  87. organization={this.props.organization}
  88. />
  89. <p>
  90. {tct(
  91. `For a complete list of client integrations, please see
  92. [docLink:our in-depth documentation].`,
  93. {docLink: <ExternalLink href="https://docs.sentry.io" />}
  94. )}
  95. </p>
  96. </div>
  97. );
  98. }
  99. }
  100. const DsnValue = styled(p => (
  101. <code {...p}>
  102. <AutoSelectText>{p.children}</AutoSelectText>
  103. </code>
  104. ))`
  105. overflow: hidden;
  106. `;
  107. const DsnInfo = styled('div')`
  108. margin-bottom: ${space(3)};
  109. `;
  110. const DsnContainer = styled('div')`
  111. display: grid;
  112. grid-template-columns: max-content 1fr;
  113. gap: ${space(1.5)} ${space(2)};
  114. align-items: center;
  115. margin-bottom: ${space(2)};
  116. `;
  117. export default withOrganization(ProjectInstallOverview);