overview.tsx 4.7 KB

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