Skip to content
Open
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
7 changes: 5 additions & 2 deletions static/app/components/onboarding/useCreateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import useApi from 'sentry/utils/useApi';
import useOrganization from 'sentry/utils/useOrganization';

interface Variables {
platform: OnboardingSelectedSDK;
default_rules?: boolean;
firstTeamSlug?: string;
name?: string;
/**
* If no platform is provided, the project will be created with the 'other' platform
*/
platform?: OnboardingSelectedSDK;
}

export function useCreateProject() {
Expand All @@ -26,7 +29,7 @@ export function useCreateProject() {
{
method: 'POST',
data: {
platform: platform.key,
platform: platform?.key,
name,
default_rules: default_rules ?? true,
origin: 'ui',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Variables = {
createNotificationAction: ReturnType<
typeof useCreateNotificationAction
>['createNotificationAction'];
platform: OnboardingSelectedSDK;
projectName: string;
platform?: OnboardingSelectedSDK;
team?: string;
};

Expand Down
2 changes: 1 addition & 1 deletion static/app/types/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export interface UpdatedTask extends Partial<Pick<OnboardingTask, 'status' | 'da

export interface OnboardingSelectedSDK
extends Pick<PlatformIntegration, 'language' | 'link' | 'name' | 'type'> {
category: Category;
key: PlatformKey;
category?: Category;
}

export type OnboardingRecentCreatedProject = {
Expand Down
5 changes: 2 additions & 3 deletions static/app/utils/platform.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {Platform} from 'sentry/components/platformPicker';
import {
backend,
desktop,
Expand All @@ -8,7 +7,7 @@ import {
PlatformCategory,
serverless,
} from 'sentry/data/platformCategories';
import type {PlatformKey} from 'sentry/types/project';
import type {PlatformIntegration, PlatformKey} from 'sentry/types/project';

/**
*
Expand Down Expand Up @@ -72,7 +71,7 @@ export function isDisabledGamingPlatform({
platform,
enabledConsolePlatforms,
}: {
platform: Platform;
platform: PlatformIntegration;
enabledConsolePlatforms?: string[];
}) {
return platform.type === 'console' && !enabledConsolePlatforms?.includes(platform.id);
Expand Down
22 changes: 22 additions & 0 deletions static/app/views/projectInstall/createProject.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,27 @@ describe('CreateProject', () => {
})
);
});

it("should create 'other' platform if no platform is selected", async () => {
const {projectCreationMockRequest} = renderFrameworkModalMockRequests({
organization,
teamSlug: teamWithAccess.slug,
});
render(<CreateProject />, {organization});
expect(screen.getByRole('button', {name: 'Create Project'})).toBeDisabled();
await userEvent.type(screen.getByPlaceholderText('project-name'), 'my-project');
expect(screen.getByRole('button', {name: 'Create Project'})).toBeEnabled();
await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
expect(projectCreationMockRequest).toHaveBeenCalledWith(
`/teams/${organization.slug}/${teamWithAccess.slug}/projects/`,
expect.objectContaining({
data: {
default_rules: true,
name: 'my-project',
origin: 'ui',
},
})
);
});
});
});
48 changes: 18 additions & 30 deletions static/app/views/projectInstall/createProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {useCreateProjectAndRules} from 'sentry/components/onboarding/useCreatePr
import PlatformPicker, {type Platform} from 'sentry/components/platformPicker';
import TeamSelector from 'sentry/components/teamSelector';
import {categoryList} from 'sentry/data/platformPickerCategories';
import {otherPlatform} from 'sentry/data/platforms';
import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {IssueAlertRule} from 'sentry/types/alerts';
Expand Down Expand Up @@ -58,7 +59,7 @@ import {makeProjectsPathname} from 'sentry/views/projects/pathname';
type FormData = {
projectName: string;
alertRule?: Partial<AlertRuleOptions>;
platform?: Partial<OnboardingSelectedSDK>;
platform?: OnboardingSelectedSDK;
team?: string;
};

Expand All @@ -69,12 +70,6 @@ type CreatedProject = Pick<Project, 'name' | 'id'> & {
team?: string;
};

function isNotPartialPlatform(
platform: Partial<OnboardingSelectedSDK> | undefined
): platform is OnboardingSelectedSDK {
return !!platform?.key;
}

function getMissingValues({
team,
projectName,
Expand Down Expand Up @@ -250,15 +245,10 @@ export function CreateProject() {
team,
alertRule,
}: {selectedFramework?: OnboardingSelectedSDK} & Omit<FormData, 'platform'> & {
platform: OnboardingSelectedSDK;
platform?: OnboardingSelectedSDK;
}) => {
const selectedPlatform = selectedFramework ?? platform;

if (!selectedPlatform) {
addErrorMessage(t('Please select a platform in Step 1'));
return;
}

let projectToRollback: Project | undefined;

try {
Expand All @@ -272,6 +262,11 @@ export function CreateProject() {
});
projectToRollback = project;

const projectPlatform = selectedPlatform ?? {
...otherPlatform,
key: otherPlatform.id,
};

trackAnalytics('project_creation_page.created', {
organization,
issue_alert: alertRuleConfig.shouldCreateCustomRule
Expand All @@ -280,7 +275,7 @@ export function CreateProject() {
? 'No Rule'
: 'Default',
project_id: project.id,
platform: selectedPlatform.key,
platform: projectPlatform.key,
rule_ids: ruleIds,
});

Expand All @@ -298,7 +293,7 @@ export function CreateProject() {
id: project.id,
name: project.name,
team: project.team?.slug,
platform: selectedPlatform,
platform: projectPlatform,
alertRule,
notificationRule,
});
Expand Down Expand Up @@ -372,21 +367,14 @@ export function CreateProject() {
);

const handleProjectCreation = useCallback(
async (data: FormData) => {
const selectedPlatform = data.platform;

if (!isNotPartialPlatform(selectedPlatform)) {
addErrorMessage(t('Please select a platform in Step 1'));
return;
}

async ({platform, ...data}: FormData) => {
if (
selectedPlatform.type !== 'language' ||
platform?.type !== 'language' ||
!Object.values(SupportedLanguages).includes(
selectedPlatform.language as SupportedLanguages
platform?.language as SupportedLanguages
)
) {
configurePlatform({...data, platform: selectedPlatform});
configurePlatform({...data, platform});
return;
}

Expand All @@ -399,11 +387,11 @@ export function CreateProject() {
<FrameworkSuggestionModal
{...deps}
organization={organization}
selectedPlatform={selectedPlatform}
selectedPlatform={platform}
onConfigure={selectedFramework => {
configurePlatform({...data, platform: selectedPlatform, selectedFramework});
configurePlatform({...data, platform, selectedFramework});
}}
onSkip={() => configurePlatform({...data, platform: selectedPlatform})}
onSkip={() => configurePlatform({...data, platform})}
/>
),
{
Expand All @@ -412,7 +400,7 @@ export function CreateProject() {
trackAnalytics(
'project_creation.select_framework_modal_close_button_clicked',
{
platform: selectedPlatform.key,
platform: platform.key,
organization,
}
);
Expand Down