123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- import {Fragment, useCallback, useContext, useEffect, useMemo, useState} from 'react';
- import {RouteComponentProps} from 'react-router';
- import styled from '@emotion/styled';
- import omit from 'lodash/omit';
- import {loadDocs, removeProject} from 'sentry/actionCreators/projects';
- import Feature from 'sentry/components/acl/feature';
- import {Alert} from 'sentry/components/alert';
- import {Button} from 'sentry/components/button';
- import ButtonBar from 'sentry/components/buttonBar';
- import Confirm from 'sentry/components/confirm';
- import NotFound from 'sentry/components/errors/notFound';
- import HookOrDefault from 'sentry/components/hookOrDefault';
- import ExternalLink from 'sentry/components/links/externalLink';
- import LoadingError from 'sentry/components/loadingError';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import {DocumentationWrapper} from 'sentry/components/onboarding/documentationWrapper';
- import {
- migratedDocs,
- SdkDocumentation,
- } from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
- import {ProductSolution} from 'sentry/components/onboarding/productSelection';
- import {useRecentCreatedProject} from 'sentry/components/onboarding/useRecentCreatedProject';
- import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
- import {
- performance as performancePlatforms,
- Platform,
- PlatformKey,
- } from 'sentry/data/platformCategories';
- import platforms from 'sentry/data/platforms';
- import {IconChevron} from 'sentry/icons';
- import {t, tct} from 'sentry/locale';
- import ConfigStore from 'sentry/stores/configStore';
- import {space} from 'sentry/styles/space';
- import {OnboardingSelectedSDK, Organization, Project} from 'sentry/types';
- import {IssueAlertRule} from 'sentry/types/alerts';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse';
- import {useApiQuery} from 'sentry/utils/queryClient';
- import useApi from 'sentry/utils/useApi';
- import useOrganization from 'sentry/utils/useOrganization';
- import useProjects from 'sentry/utils/useProjects';
- import {normalizeUrl} from 'sentry/utils/withDomainRequired';
- import {SetupDocsLoader} from 'sentry/views/onboarding/setupDocsLoader';
- import {GettingStartedWithProjectContext} from 'sentry/views/projects/gettingStartedWithProjectContext';
- import {OtherPlatformsInfo} from './otherPlatformsInfo';
- const ProductUnavailableCTAHook = HookOrDefault({
- hookName: 'component:product-unavailable-cta',
- });
- type Props = RouteComponentProps<{projectId: string}, {}>;
- export function SetUpGeneralSdkDoc({
- organization,
- projectSlug,
- platform,
- }: {
- organization: Organization;
- platform: Platform;
- projectSlug: Project['slug'];
- }) {
- const api = useApi();
- const [loading, setLoading] = useState(true);
- const [error, setError] = useState(false);
- const [html, setHtml] = useState('');
- const fetchDocs = useCallback(async () => {
- setLoading(true);
- try {
- const {html: reponse} = await loadDocs({
- api,
- orgSlug: organization.slug,
- projectSlug,
- platform: platform.key as PlatformKey,
- });
- setHtml(reponse);
- window.scrollTo(0, 0);
- } catch (err) {
- setError(err);
- }
- setLoading(false);
- }, [api, organization.slug, projectSlug, platform.key]);
- useEffect(() => {
- fetchDocs();
- }, [fetchDocs]);
- return (
- <div>
- <Alert type="info" showIcon>
- {tct(
- `
- This is a quick getting started guide. For in-depth instructions
- on integrating Sentry with [platform], view
- [docLink:our complete documentation].`,
- {
- platform: platform.name,
- docLink: <ExternalLink href={platform.link ?? undefined} />,
- }
- )}
- </Alert>
- {loading ? (
- <LoadingIndicator />
- ) : error ? (
- <LoadingError onRetry={fetchDocs} />
- ) : (
- <Fragment>
- <SentryDocumentTitle
- title={`${t('Configure')} ${platform.name}`}
- projectSlug={projectSlug}
- />
- <DocumentationWrapper dangerouslySetInnerHTML={{__html: html}} />
- </Fragment>
- )}
- </div>
- );
- }
- export function ProjectInstallPlatform({location, params, router}: Props) {
- const organization = useOrganization();
- const api = useApi();
- const gettingStartedWithProjectContext = useContext(GettingStartedWithProjectContext);
- const isSelfHosted = ConfigStore.get('isSelfHosted');
- const {projects, initiallyLoaded} = useProjects({
- slugs: [params.projectId],
- orgId: organization.slug,
- });
- const loadingProjects = !initiallyLoaded;
- const project = !loadingProjects
- ? projects.find(proj => proj.slug === params.projectId)
- : undefined;
- const currentPlatformKey = project?.platform ?? 'other';
- const currentPlatform = platforms.find(p => p.id === currentPlatformKey);
- const [showLoaderOnboarding, setShowLoaderOnboarding] = useState(
- currentPlatform?.id === 'javascript'
- );
- const products = useMemo(
- () => (location.query.product ?? []) as ProductSolution[],
- [location.query.product]
- );
- const {
- data: projectAlertRules,
- isLoading: projectAlertRulesIsLoading,
- isError: projectAlertRulesIsError,
- } = useApiQuery<IssueAlertRule[]>(
- [`/projects/${organization.slug}/${project?.slug}/rules/`],
- {
- enabled: !!project?.slug,
- staleTime: 0,
- }
- );
- useEffect(() => {
- setShowLoaderOnboarding(currentPlatform?.id === 'javascript');
- }, [currentPlatform?.id]);
- useEffect(() => {
- if (!project || projectAlertRulesIsLoading || projectAlertRulesIsError) {
- return;
- }
- if (gettingStartedWithProjectContext.project?.id === project.id) {
- return;
- }
- const platformKey = Object.keys(platforms).find(
- key => platforms[key].id === project.platform
- );
- if (!platformKey) {
- return;
- }
- gettingStartedWithProjectContext.setProject({
- id: project.id,
- name: project.name,
- // sometimes the team slug here can be undefined
- teamSlug: project.team?.slug,
- alertRules: projectAlertRules,
- platform: {
- ...omit(platforms[platformKey], 'id'),
- key: platforms[platformKey].id,
- } as OnboardingSelectedSDK,
- });
- }, [
- gettingStartedWithProjectContext,
- project,
- projectAlertRules,
- projectAlertRulesIsLoading,
- projectAlertRulesIsError,
- ]);
- const projectDeletionOnBackClick = !!organization?.features.includes(
- 'onboarding-project-deletion-on-back-click'
- );
- // This is a feature flag that is currently only enabled for a subset of internal users until the feature is fully implemented,
- // but the purpose of the feature is to make the product selection feature in documents available to all users
- // and guide them to upgrade to a plan if one of the products is not available on their current plan.
- const gettingStartedDocWithProductSelection = !!organization?.features.includes(
- 'getting-started-doc-with-product-selection'
- );
- const recentCreatedProject = useRecentCreatedProject({
- orgSlug: organization.slug,
- projectSlug: project?.slug,
- });
- const shallProjectBeDeleted =
- projectDeletionOnBackClick &&
- recentCreatedProject &&
- // if the project has received a first error, we don't delete it
- recentCreatedProject.firstError === false &&
- // if the project has received a first transaction, we don't delete it
- recentCreatedProject.firstTransaction === false &&
- // if the project has replays, we don't delete it
- recentCreatedProject.hasReplays === false &&
- // if the project has sessions, we don't delete it
- recentCreatedProject.hasSessions === false &&
- // if the project is older than one hour, we don't delete it
- recentCreatedProject.olderThanOneHour === false;
- const platformIntegration = platforms.find(p => p.id === currentPlatformKey);
- const platform: Platform = {
- key: currentPlatformKey as PlatformKey,
- id: platformIntegration?.id,
- name: platformIntegration?.name,
- link: platformIntegration?.link,
- };
- const handleGoBack = useCallback(async () => {
- if (!recentCreatedProject) {
- return;
- }
- trackAnalytics('project_creation.back_button_clicked', {
- organization,
- });
- if (shallProjectBeDeleted) {
- trackAnalytics('project_creation.data_removal_modal_confirm_button_clicked', {
- organization,
- platform: recentCreatedProject.slug,
- project_id: recentCreatedProject.id,
- });
- try {
- await removeProject({
- api,
- orgSlug: organization.slug,
- projectSlug: recentCreatedProject.slug,
- origin: 'getting_started',
- });
- trackAnalytics('project_creation.data_removed', {
- organization,
- date_created: recentCreatedProject.dateCreated,
- platform: recentCreatedProject.slug,
- project_id: recentCreatedProject.id,
- });
- } catch (error) {
- handleXhrErrorResponse('Unable to delete project in project creation', error);
- // we don't give the user any feedback regarding this error as this shall be silent
- }
- }
- router.replace(
- normalizeUrl(
- `/organizations/${organization.slug}/projects/new/?referrer=getting-started&project=${recentCreatedProject.id}`
- )
- );
- }, [api, recentCreatedProject, organization, shallProjectBeDeleted, router]);
- const hideLoaderOnboarding = useCallback(() => {
- setShowLoaderOnboarding(false);
- if (!project?.id || !currentPlatform) {
- return;
- }
- trackAnalytics('onboarding.js_loader_npm_docs_shown', {
- organization,
- platform: currentPlatform.id,
- project_id: project?.id,
- });
- }, [organization, currentPlatform, project?.id]);
- if (!project) {
- return null;
- }
- if (!platform.id && platform.key !== 'other') {
- return <NotFound />;
- }
- const issueStreamLink = `/organizations/${organization.slug}/issues/`;
- const performanceOverviewLink = `/organizations/${organization.slug}/performance/`;
- const showPerformancePrompt = performancePlatforms.includes(platform.id as PlatformKey);
- const isGettingStarted = window.location.href.indexOf('getting-started') > 0;
- const showDocsWithProductSelection =
- gettingStartedDocWithProductSelection &&
- (platform.key === 'javascript' || !!platform.key.match('^javascript-([A-Za-z]+)$'));
- return (
- <Fragment>
- {!isSelfHosted && showDocsWithProductSelection && (
- <ProductUnavailableCTAHook organization={organization} />
- )}
- <StyledPageHeader>
- <h2>{t('Configure %(platform)s SDK', {platform: platform.name ?? 'other'})}</h2>
- <ButtonBar gap={1}>
- <Confirm
- bypass={!shallProjectBeDeleted}
- message={t(
- "Hey, just a heads up - we haven't received any data for this SDK yet and by going back all changes will be discarded. Are you sure you want to head back?"
- )}
- priority="danger"
- confirmText={t("Yes I'm sure")}
- onConfirm={handleGoBack}
- onClose={() => {
- if (!recentCreatedProject) {
- return;
- }
- trackAnalytics('project_creation.data_removal_modal_dismissed', {
- organization,
- platform: recentCreatedProject.slug,
- project_id: recentCreatedProject.id,
- });
- }}
- onRender={() => {
- if (!recentCreatedProject) {
- return;
- }
- trackAnalytics('project_creation.data_removal_modal_rendered', {
- organization,
- platform: recentCreatedProject.slug,
- project_id: recentCreatedProject.id,
- });
- }}
- >
- <Button icon={<IconChevron direction="left" size="sm" />} size="sm">
- {t('Back to Platform Selection')}
- </Button>
- </Confirm>
- {platform.key !== 'other' && (
- <Button size="sm" href={platform.link ?? undefined} external>
- {t('Full Documentation')}
- </Button>
- )}
- </ButtonBar>
- </StyledPageHeader>
- {platform.key === 'other' ? (
- <OtherPlatformsInfo
- projectSlug={project.slug}
- platform={platform.name ?? 'other'}
- />
- ) : (
- <Fragment>
- {currentPlatform && showLoaderOnboarding ? (
- <SetupDocsLoader
- organization={organization}
- project={project}
- location={location}
- platform={currentPlatform.id}
- close={hideLoaderOnboarding}
- />
- ) : currentPlatform && migratedDocs.includes(currentPlatformKey) ? (
- <SdkDocumentation
- platform={currentPlatform}
- organization={organization}
- projectSlug={project.slug}
- projectId={project.id}
- activeProductSelection={products}
- />
- ) : (
- <SetUpGeneralSdkDoc
- organization={organization}
- projectSlug={project.slug}
- platform={platform}
- />
- )}
- </Fragment>
- )}
- <div>
- {isGettingStarted && showPerformancePrompt && (
- <Feature
- features={['performance-view']}
- hookName="feature-disabled:performance-new-project"
- >
- {({hasFeature}) => {
- if (hasFeature) {
- return null;
- }
- return (
- <StyledAlert type="info" showIcon>
- {t(
- `Your selected platform supports performance, but your organization does not have performance enabled.`
- )}
- </StyledAlert>
- );
- }}
- </Feature>
- )}
- <StyledButtonBar gap={1}>
- <Button
- priority="primary"
- busy={loadingProjects}
- to={{
- pathname: issueStreamLink,
- query: project?.id,
- hash: '#welcome',
- }}
- >
- {t('Take me to Issues')}
- </Button>
- <Button
- busy={loadingProjects}
- to={{
- pathname: performanceOverviewLink,
- query: project?.id,
- }}
- >
- {t('Take me to Performance')}
- </Button>
- </StyledButtonBar>
- </div>
- </Fragment>
- );
- }
- const StyledButtonBar = styled(ButtonBar)`
- margin-top: ${space(3)};
- width: max-content;
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- width: auto;
- grid-row-gap: ${space(1)};
- grid-auto-flow: row;
- }
- `;
- const StyledPageHeader = styled('div')`
- display: flex;
- justify-content: space-between;
- margin-bottom: ${space(3)};
- h2 {
- margin: 0;
- }
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- flex-direction: column;
- align-items: flex-start;
- h2 {
- margin-bottom: ${space(2)};
- }
- }
- `;
- const StyledAlert = styled(Alert)`
- margin-top: ${space(2)};
- `;
|