123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- import {Fragment, useCallback, useEffect, useMemo, useState} from 'react';
- import {browserHistory} from 'react-router';
- import styled from '@emotion/styled';
- import {motion} from 'framer-motion';
- import {Location} from 'history';
- import {loadDocs} from 'sentry/actionCreators/projects';
- import {Alert} from 'sentry/components/alert';
- import LoadingError from 'sentry/components/loadingError';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import {DocumentationWrapper} from 'sentry/components/onboarding/documentationWrapper';
- import {Footer} from 'sentry/components/onboarding/footer';
- import {FooterWithViewSampleErrorButton} from 'sentry/components/onboarding/footerWithViewSampleErrorButton';
- import {MissingExampleWarning} from 'sentry/components/onboarding/missingExampleWarning';
- import {PRODUCT, ProductSelection} from 'sentry/components/onboarding/productSelection';
- import {PlatformKey} from 'sentry/data/platformCategories';
- import platforms from 'sentry/data/platforms';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import {Organization, Project} from 'sentry/types';
- import {OnboardingPlatformDoc} from 'sentry/types/onboarding';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import getDynamicText from 'sentry/utils/getDynamicText';
- import {platformToIntegrationMap} from 'sentry/utils/integrationUtil';
- import {useApiQuery} from 'sentry/utils/queryClient';
- import useApi from 'sentry/utils/useApi';
- import {useExperiment} from 'sentry/utils/useExperiment';
- import useOrganization from 'sentry/utils/useOrganization';
- import SetupIntroduction from 'sentry/views/onboarding/components/setupIntroduction';
- import {SetupDocsLoader} from 'sentry/views/onboarding/setupDocsLoader';
- import FirstEventFooter from './components/firstEventFooter';
- import IntegrationSetup from './integrationSetup';
- import {StepProps} from './types';
- export function DocWithProductSelection({
- organization,
- location,
- projectSlug,
- newOrg,
- currentPlatform,
- }: {
- currentPlatform: PlatformKey;
- location: Location;
- organization: Organization;
- projectSlug: Project['slug'];
- newOrg?: boolean;
- }) {
- const loadPlatform = useMemo(() => {
- const products = location.query.product ?? [];
- return products.includes(PRODUCT.PERFORMANCE_MONITORING) &&
- products.includes(PRODUCT.SESSION_REPLAY)
- ? `${currentPlatform}-with-error-monitoring-performance-and-replay`
- : products.includes(PRODUCT.PERFORMANCE_MONITORING)
- ? `${currentPlatform}-with-error-monitoring-and-performance`
- : products.includes(PRODUCT.SESSION_REPLAY)
- ? `${currentPlatform}-with-error-monitoring-and-replay`
- : `${currentPlatform}-with-error-monitoring`;
- }, [location.query.product, currentPlatform]);
- const {data, isLoading, isError, refetch} = useApiQuery<OnboardingPlatformDoc>(
- [`/projects/${organization.slug}/${projectSlug}/docs/${loadPlatform}/`],
- {
- staleTime: Infinity,
- enabled: !!projectSlug && !!organization.slug && !!loadPlatform,
- }
- );
- const platformName = platforms.find(p => p.id === currentPlatform)?.name ?? '';
- return (
- <Fragment>
- {newOrg && (
- <SetupIntroduction
- stepHeaderText={t('Configure %s SDK', platformName)}
- platform={currentPlatform}
- />
- )}
- <ProductSelection
- defaultSelectedProducts={[PRODUCT.PERFORMANCE_MONITORING, PRODUCT.SESSION_REPLAY]}
- />
- {isLoading ? (
- <LoadingIndicator />
- ) : isError ? (
- <LoadingError
- message={t('Failed to load documentation for the %s platform.', platformName)}
- onRetry={refetch}
- />
- ) : (
- getDynamicText({
- value: (
- <DocsWrapper>
- <DocumentationWrapper
- dangerouslySetInnerHTML={{__html: data?.html ?? ''}}
- />
- <MissingExampleWarning
- platform={currentPlatform}
- platformDocs={{
- html: data?.html ?? '',
- link: data?.link ?? '',
- }}
- />
- </DocsWrapper>
- ),
- fixed: (
- <Alert type="warning">
- Platform documentation is not rendered in for tests in CI
- </Alert>
- ),
- })
- )}
- </Fragment>
- );
- }
- function ProjectDocs(props: {
- hasError: boolean;
- onRetry: () => void;
- organization: Organization;
- platform: PlatformKey | null;
- platformDocs: OnboardingPlatformDoc | null;
- project: Project;
- }) {
- const currentPlatform = props.platform ?? props.project?.platform ?? 'other';
- return (
- <Fragment>
- <SetupIntroduction
- stepHeaderText={t(
- 'Configure %s SDK',
- platforms.find(p => p.id === currentPlatform)?.name ?? ''
- )}
- platform={currentPlatform}
- />
- {getDynamicText({
- value: !props.hasError ? (
- props.platformDocs !== null && (
- <DocsWrapper key={props.platformDocs.html}>
- <DocumentationWrapper
- dangerouslySetInnerHTML={{__html: props.platformDocs.html}}
- />
- <MissingExampleWarning
- platform={props.platform}
- platformDocs={props.platformDocs}
- />
- </DocsWrapper>
- )
- ) : (
- <LoadingError
- message={t(
- 'Failed to load documentation for the %s platform.',
- props.project?.platform
- )}
- onRetry={props.onRetry}
- />
- ),
- fixed: (
- <Alert type="warning">
- Platform documentation is not rendered in for tests in CI
- </Alert>
- ),
- })}
- </Fragment>
- );
- }
- function SetupDocs({route, router, location, recentCreatedProject: project}: StepProps) {
- const api = useApi();
- const organization = useOrganization();
- const {
- logExperiment: newFooterLogExperiment,
- experimentAssignment: newFooterAssignment,
- } = useExperiment('OnboardingNewFooterExperiment', {
- logExperimentOnMount: false,
- });
- const heartbeatFooter = !!organization?.features.includes(
- 'onboarding-heartbeat-footer'
- );
- // SDK instrumentation
- const [hasError, setHasError] = useState(false);
- const [platformDocs, setPlatformDocs] = useState<OnboardingPlatformDoc | null>(null);
- const [loadedPlatform, setLoadedPlatform] = useState<PlatformKey | null>(null);
- const currentPlatform = loadedPlatform ?? project?.platform ?? 'other';
- const [showLoaderOnboarding, setShowLoaderOnboarding] = useState(
- currentPlatform === 'javascript'
- );
- const integrationSlug = project?.platform && platformToIntegrationMap[project.platform];
- const [integrationUseManualSetup, setIntegrationUseManualSetup] = useState(false);
- const showIntegrationOnboarding = integrationSlug && !integrationUseManualSetup;
- const showDocsWithProductSelection =
- currentPlatform.match('^javascript-([A-Za-z]+)$') ??
- (showLoaderOnboarding === false && currentPlatform === 'javascript');
- const hideLoaderOnboarding = useCallback(() => {
- setShowLoaderOnboarding(false);
- if (!project?.id) {
- return;
- }
- trackAnalytics('onboarding.js_loader_npm_docs_shown', {
- organization,
- platform: currentPlatform,
- project_id: project?.id,
- });
- }, [organization, currentPlatform, project?.id]);
- const fetchData = useCallback(async () => {
- // TODO: add better error handling logic
- if (!project?.platform) {
- return;
- }
- // this will be fetched in the DocWithProductSelection component
- if (showDocsWithProductSelection) {
- return;
- }
- // Show loader setup for base javascript platform
- if (showLoaderOnboarding) {
- return;
- }
- if (showIntegrationOnboarding) {
- setLoadedPlatform(project.platform);
- setPlatformDocs(null);
- setHasError(false);
- return;
- }
- try {
- const loadedDocs = await loadDocs({
- api,
- orgSlug: organization.slug,
- projectSlug: project.slug,
- platform: project.platform as PlatformKey,
- });
- setPlatformDocs(loadedDocs);
- setLoadedPlatform(project.platform);
- setHasError(false);
- } catch (error) {
- setHasError(error);
- throw error;
- }
- }, [
- project?.slug,
- project?.platform,
- api,
- organization.slug,
- showDocsWithProductSelection,
- showIntegrationOnboarding,
- showLoaderOnboarding,
- ]);
- useEffect(() => {
- fetchData();
- }, [fetchData, location.query.product, project?.platform]);
- // log experiment on mount if feature enabled
- useEffect(() => {
- if (heartbeatFooter) {
- newFooterLogExperiment();
- }
- }, [newFooterLogExperiment, heartbeatFooter]);
- if (!project) {
- return null;
- }
- return (
- <Fragment>
- <Wrapper>
- <MainContent>
- {showIntegrationOnboarding ? (
- <IntegrationSetup
- integrationSlug={integrationSlug}
- project={project}
- onClickManualSetup={() => {
- setIntegrationUseManualSetup(true);
- }}
- />
- ) : showDocsWithProductSelection ? (
- <DocWithProductSelection
- organization={organization}
- projectSlug={project.slug}
- location={location}
- currentPlatform={currentPlatform}
- newOrg
- />
- ) : showLoaderOnboarding ? (
- <Fragment>
- <SetupIntroduction
- stepHeaderText={t(
- 'Configure %s SDK',
- platforms.find(p => p.id === currentPlatform)?.name ?? ''
- )}
- platform={currentPlatform}
- />
- <SetupDocsLoader
- organization={organization}
- project={project}
- location={location}
- platform={loadedPlatform}
- close={hideLoaderOnboarding}
- />
- </Fragment>
- ) : (
- <ProjectDocs
- platform={loadedPlatform}
- project={project}
- hasError={hasError}
- platformDocs={platformDocs}
- onRetry={fetchData}
- organization={organization}
- />
- )}
- </MainContent>
- </Wrapper>
- {heartbeatFooter ? (
- newFooterAssignment === 'variant2' ? (
- <FooterWithViewSampleErrorButton
- projectSlug={project.slug}
- projectId={project.id}
- route={route}
- router={router}
- location={location}
- newOrg
- />
- ) : newFooterAssignment === 'variant1' ? (
- <Footer
- projectSlug={project.slug}
- projectId={project.id}
- route={route}
- router={router}
- location={location}
- newOrg
- />
- ) : (
- <FirstEventFooter
- project={project}
- organization={organization}
- isLast
- onClickSetupLater={() => {
- const orgIssuesURL = `/organizations/${organization.slug}/issues/?project=${project.id}&referrer=onboarding-setup-docs`;
- trackAnalytics('growth.onboarding_clicked_setup_platform_later', {
- organization,
- platform: currentPlatform,
- project_id: project.id,
- });
- browserHistory.push(orgIssuesURL);
- }}
- />
- )
- ) : (
- <FirstEventFooter
- project={project}
- organization={organization}
- isLast
- onClickSetupLater={() => {
- const orgIssuesURL = `/organizations/${organization.slug}/issues/?project=${project.id}&referrer=onboarding-setup-docs`;
- trackAnalytics('growth.onboarding_clicked_setup_platform_later', {
- organization,
- platform: currentPlatform,
- project_id: project.id,
- });
- browserHistory.push(orgIssuesURL);
- }}
- />
- )}
- </Fragment>
- );
- }
- export default SetupDocs;
- const AnimatedContentWrapper = styled(motion.div)`
- overflow: hidden;
- `;
- AnimatedContentWrapper.defaultProps = {
- initial: {
- height: 0,
- },
- animate: {
- height: 'auto',
- },
- exit: {
- height: 0,
- },
- };
- const DocsWrapper = styled(motion.div)``;
- DocsWrapper.defaultProps = {
- initial: {opacity: 0, y: 40},
- animate: {opacity: 1, y: 0},
- exit: {opacity: 0},
- };
- const Wrapper = styled('div')`
- display: flex;
- flex-direction: row;
- margin: ${space(2)};
- justify-content: center;
- `;
- const MainContent = styled('div')`
- max-width: 850px;
- min-width: 0;
- flex-grow: 1;
- `;
|