Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion static/app/views/onboarding/onboarding.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ describe('Onboarding', () => {

describe('SCM onboarding flow', () => {
const scmOrganization = OrganizationFixture({
features: ['onboarding-scm-experiment'],
features: ['onboarding-scm-experiment', 'onboarding-scm-project-details'],
});

const githubProvider = GitHubIntegrationProviderFixture({
Expand Down
10 changes: 9 additions & 1 deletion static/app/views/onboarding/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,15 @@ export function OnboardingWithoutContext() {
feature: 'onboarding-scm-experiment',
});

const onboardingSteps = hasScmOnboarding ? scmOnboardingSteps : legacyOnboardingSteps;
const hasProjectDetailsStep = organization.features.includes(
'onboarding-scm-project-details'
);

const scmSteps = hasProjectDetailsStep
? scmOnboardingSteps
: scmOnboardingSteps.filter(s => s.id !== OnboardingStepId.SCM_PROJECT_DETAILS);

const onboardingSteps = hasScmOnboarding ? scmSteps : legacyOnboardingSteps;

const stepObj = onboardingSteps.find(({id}) => stepId === id);
const stepIndex = onboardingSteps.findIndex(({id}) => stepId === id);
Expand Down
4 changes: 4 additions & 0 deletions static/app/views/onboarding/scmPlatformFeatures.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
OnboardingContextProvider,
type OnboardingSessionState,
} from 'sentry/components/onboarding/onboardingContext';
import {ProjectsStore} from 'sentry/stores/projectsStore';
import {TeamStore} from 'sentry/stores/teamStore';
import * as analytics from 'sentry/utils/analytics';
import {sessionStorageWrapper} from 'sentry/utils/sessionStorage';

Expand Down Expand Up @@ -72,6 +74,8 @@ describe('ScmPlatformFeatures', () => {
beforeEach(() => {
jest.clearAllMocks();
sessionStorageWrapper.clear();
ProjectsStore.loadInitialData([]);
TeamStore.loadInitialData([]);
});

afterEach(() => {
Expand Down
69 changes: 67 additions & 2 deletions static/app/views/onboarding/scmPlatformFeatures.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useCallback, useEffect, useMemo, useState} from 'react';
import * as Sentry from '@sentry/react';
import {LayoutGroup, motion} from 'framer-motion';
import {PlatformIcon} from 'platformicons';

Expand All @@ -7,6 +8,7 @@ import {Container, Flex, Grid, Stack} from '@sentry/scraps/layout';
import {Select} from '@sentry/scraps/select';
import {Heading} from '@sentry/scraps/text';

import {addErrorMessage} from 'sentry/actionCreators/indicator';
import {closeModal, openConsoleModal, openModal} from 'sentry/actionCreators/modal';
import {LoadingIndicator} from 'sentry/components/loadingIndicator';
import {SupportedLanguages} from 'sentry/components/onboarding/frameworkSuggestionModal';
Expand All @@ -16,13 +18,17 @@ import {
getDisabledProducts,
platformProductAvailability,
} from 'sentry/components/onboarding/productSelection';
import {useCreateProject} from 'sentry/components/onboarding/useCreateProject';
import {platforms} from 'sentry/data/platforms';
import {t} from 'sentry/locale';
import type {OnboardingSelectedSDK} from 'sentry/types/onboarding';
import type {Team} from 'sentry/types/organization';
import type {PlatformIntegration, PlatformKey} from 'sentry/types/project';
import {trackAnalytics} from 'sentry/utils/analytics';
import {isDisabledGamingPlatform} from 'sentry/utils/platform';
import {useOrganization} from 'sentry/utils/useOrganization';
import {useProjects} from 'sentry/utils/useProjects';
import {useTeams} from 'sentry/utils/useTeams';
import {ScmFeatureSelectionCards} from 'sentry/views/onboarding/components/scmFeatureSelectionCards';
import {ScmPlatformCard} from 'sentry/views/onboarding/components/scmPlatformCard';

Expand Down Expand Up @@ -84,8 +90,17 @@ export function ScmPlatformFeatures({onComplete}: StepProps) {
setSelectedPlatform,
selectedFeatures,
setSelectedFeatures,
createdProjectSlug,
setCreatedProjectSlug,
} = useOnboardingContext();

const {teams, fetching: isLoadingTeams} = useTeams();
const {projects, initiallyLoaded: projectsLoaded} = useProjects();
const createProject = useCreateProject();
const hasProjectDetailsStep = organization.features.includes(
'onboarding-scm-project-details'
);

const [showManualPicker, setShowManualPicker] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -306,14 +321,59 @@ export function ScmPlatformFeatures({onComplete}: StepProps) {
}
}

function handleContinue() {
const existingProject = createdProjectSlug
? projects.find(p => p.slug === createdProjectSlug)
: undefined;

async function handleContinue() {
// Persist derived defaults to context if user accepted them
if (currentPlatformKey && !selectedPlatform?.key) {
setPlatform(currentPlatformKey);
}
if (!selectedFeatures) {
setSelectedFeatures(currentFeatures);
}

if (!hasProjectDetailsStep) {
// Auto-create project with defaults when SCM_PROJECT_DETAILS step is skipped
const platform =
selectedPlatform ??
(currentPlatformKey
? toSelectedSdk(getPlatformInfo(currentPlatformKey)!)
: undefined);
if (!platform) {
return;
}

// If a project was already created for this platform (e.g. the user
// went back after the project received its first event), reuse it.
// If the platform changed, abandon the old project and create a new
// one — matching legacy onboarding behavior.
if (existingProject?.platform === platform.key) {
onComplete(undefined, {product: currentFeatures});
return;
}

const firstAdminTeam = teams.find((team: Team) =>
team.access.includes('team:admin')
);

try {
const project = await createProject.mutateAsync({
name: platform.key,
platform,
default_rules: true,
firstTeamSlug: firstAdminTeam?.slug,
});
setCreatedProjectSlug(project.slug);
onComplete(undefined, {product: currentFeatures});
} catch (error) {
addErrorMessage(t('Failed to create project'));
Sentry.captureException(error);
}
return;
}

onComplete();
}

Expand Down Expand Up @@ -459,7 +519,12 @@ export function ScmPlatformFeatures({onComplete}: StepProps) {
features: currentFeatures,
}}
onClick={handleContinue}
disabled={!currentPlatformKey}
disabled={
!currentPlatformKey ||
createProject.isPending ||
(!hasProjectDetailsStep && (isLoadingTeams || !projectsLoaded))
}
busy={createProject.isPending}
>
{t('Continue')}
</Button>
Expand Down
13 changes: 9 additions & 4 deletions static/app/views/onboarding/useBackActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse';
import type {RequestError} from 'sentry/utils/requestError/requestError';
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
import {useApi} from 'sentry/utils/useApi';
import {useExperiment} from 'sentry/utils/useExperiment';
import {useOrganization} from 'sentry/utils/useOrganization';
import type {StepDescriptor} from 'sentry/views/onboarding/types';

Expand All @@ -33,6 +34,9 @@ export function useBackActions({
const api = useApi();
const organization = useOrganization();
const onboardingContext = useOnboardingContext();
const {inExperiment: hasScmOnboarding} = useExperiment({
feature: 'onboarding-scm-experiment',
});
const currentStep = onboardingSteps[stepIndex];

const deleteRecentCreatedProject = useCallback(
Expand Down Expand Up @@ -118,21 +122,22 @@ export function useBackActions({
// store data and skip project creation.
// In the SCM flow, preserve context so the user keeps their SCM
// connection, repo selection, and feature choices.
await deleteRecentCreatedProject(prevStep.id === 'scm-project-details');
await deleteRecentCreatedProject(hasScmOnboarding);
}

if (!browserBackButton) {
goToStep(prevStep);
}
},
[
goToStep,
currentStep,
organization,
onboardingContext,
isRecentCreatedProjectActive,
recentCreatedProject,
currentStep,
onboardingContext,
goToStep,
deleteRecentCreatedProject,
hasScmOnboarding,
]
);

Expand Down
Loading