Update Import project flow to configure deployment

This commit is contained in:
IshaVenikar 2024-10-14 12:03:52 +05:30 committed by Nabarun
parent e8f1f34245
commit 9fb72ba0bc
10 changed files with 96 additions and 73 deletions

View File

@ -67,7 +67,7 @@ export class Project {
@Column('varchar') @Column('varchar')
icon!: string; icon!: string;
@Column('varchar', { nullable: true }) @Column({ type: 'simple-array', nullable: true })
baseDomains!: string[] | null; baseDomains!: string[] | null;
@CreateDateColumn() @CreateDateColumn()

View File

@ -299,6 +299,7 @@ export class Service {
auctionId: Not(IsNull()), auctionId: Not(IsNull()),
}, },
relations: ['deployments'], relations: ['deployments'],
withDeleted: true,
}); });
// Should only check on the first deployment // Should only check on the first deployment

View File

@ -26,7 +26,7 @@ const Configure = () => {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const templateId = searchParams.get('templateId'); const templateId = searchParams.get('templateId');
const location = useLocation(); const location = useLocation();
const { templateOwner, templateRepo, owner, name, isPrivate, orgSlug } = location.state || {}; const { templateOwner, templateRepo, owner, name, isPrivate, orgSlug, repository } = location.state || {};
const navigate = useNavigate(); const navigate = useNavigate();
const { toast, dismiss } = useToast(); const { toast, dismiss } = useToast();
@ -47,14 +47,6 @@ const Configure = () => {
setIsLoading(true); setIsLoading(true);
try { try {
const projectData: any = {
templateOwner,
templateRepo,
owner,
name,
isPrivate
};
let lrn: string | undefined; let lrn: string | undefined;
let auctionData: AuctionData | undefined; let auctionData: AuctionData | undefined;
@ -63,26 +55,57 @@ const Configure = () => {
} else if (data.option === 'Auction') { } else if (data.option === 'Auction') {
auctionData = { auctionData = {
numProviders: Number(data.numProviders!), numProviders: Number(data.numProviders!),
maxPrice: (data.maxPrice!).toString() maxPrice: (data.maxPrice!).toString(),
}; };
} }
const { addProjectFromTemplate } = await client.addProjectFromTemplate( if (templateId) {
orgSlug, // Template-based project creation
projectData, const projectData: any = {
lrn, templateOwner,
auctionData templateRepo,
); owner,
name,
isPrivate,
};
data.option === 'Auction' const { addProjectFromTemplate } = await client.addProjectFromTemplate(
? navigate( orgSlug,
`/${orgSlug}/projects/create/success/${addProjectFromTemplate.id}`, projectData,
lrn,
auctionData
);
data.option === 'Auction'
? navigate(
`/${orgSlug}/projects/create/success/${addProjectFromTemplate.id}`,
{ state: { isAuction: true } }
)
: navigate(
`/${orgSlug}/projects/create/template/deploy?projectId=${addProjectFromTemplate.id}&templateId=${templateId}`
);
} else {
const { addProject } = await client.addProject(
orgSlug,
{ {
state: { name: repository.fullName,
isAuction: true prodBranch: repository.defaultBranch,
} repository: repository.fullName,
}) template: 'webapp',
: navigate(`/${orgSlug}/projects/create/template/deploy?projectId=${addProjectFromTemplate.id}&templateId=${templateId}`); },
lrn,
auctionData
);
data.option === 'Auction'
? navigate(
`/${orgSlug}/projects/create/success/${addProject.id}`,
{ state: { isAuction: true } }
)
: navigate(
`/${orgSlug}/projects/create/deploy?projectId=${addProject.id}`
);
}
} catch (error) { } catch (error) {
console.error('Error creating project:', error); console.error('Error creating project:', error);
toast({ toast({
@ -106,7 +129,9 @@ const Configure = () => {
Configure deployment Configure deployment
</Heading> </Heading>
<Heading as="h5" className="text-sm font-sans text-elements-low-em"> <Heading as="h5" className="text-sm font-sans text-elements-low-em">
The app can be deployed by setting the deployer LRN for a single deployment or by creating a deployer auction for multiple deployments The app can be deployed by setting the deployer LRN for a single
deployment or by creating a deployer auction for multiple
deployments
</Heading> </Heading>
</div> </div>
</div> </div>
@ -119,11 +144,14 @@ const Configure = () => {
control={control} control={control}
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<Select <Select
label='Configuration Options' label="Configuration Options"
value={{ value: value || 'LRN', label: value === 'Auction' ? 'Create Auction' : 'Deployer LRN' } as SelectOption} value={
onChange={(value) => {
onChange((value as SelectOption).value) value: value || 'LRN',
label: value === 'Auction' ? 'Create Auction' : 'Deployer LRN',
} as SelectOption
} }
onChange={(value) => onChange((value as SelectOption).value)}
options={[ options={[
{ value: 'LRN', label: 'Deployer LRN' }, { value: 'LRN', label: 'Deployer LRN' },
{ value: 'Auction', label: 'Create Auction' }, { value: 'Auction', label: 'Create Auction' },
@ -138,7 +166,9 @@ const Configure = () => {
<Heading as="h5" className="text-sm font-sans text-elements-low-em"> <Heading as="h5" className="text-sm font-sans text-elements-low-em">
The app will be deployed by the configured deployer The app will be deployed by the configured deployer
</Heading> </Heading>
<span className="text-sm text-elements-high-em">Enter LRN for deployer</span> <span className="text-sm text-elements-high-em">
Enter LRN for deployer
</span>
<Controller <Controller
name="lrn" name="lrn"
control={control} control={control}
@ -152,10 +182,12 @@ const Configure = () => {
{selectedOption === 'Auction' && ( {selectedOption === 'Auction' && (
<> <>
<div className="flex flex-col justify-start gap-3"> <div className="flex flex-col justify-start gap-3">
<Heading as="h5" className="text-sm font-sans text-elements-low-em"> <Heading as="h5" className="text-sm font-sans text-elements-low-em">
Set the number of deployers and maximum price for each deployment Set the number of deployers and maximum price for each deployment
</Heading> </Heading>
<span className="text-sm text-elements-high-em">Number of Deployers</span> <span className="text-sm text-elements-high-em">
Number of Deployers
</span>
<Controller <Controller
name="numProviders" name="numProviders"
control={control} control={control}
@ -165,7 +197,9 @@ const Configure = () => {
/> />
</div> </div>
<div className="flex flex-col justify-start gap-3"> <div className="flex flex-col justify-start gap-3">
<span className="text-sm text-elements-high-em">Maximum Price (alnt)</span> <span className="text-sm text-elements-high-em">
Maximum Price (alnt)
</span>
<Controller <Controller
name="maxPrice" name="maxPrice"
control={control} control={control}

View File

@ -38,36 +38,19 @@ export const ProjectRepoCard: React.FC<ProjectRepoCardProps> = ({
}); });
} }
try { navigate(`configure`,
setIsLoading(true); {
const { addProject } = await client.addProject(orgSlug, { state: {
name: `${repository.owner?.login}-${repository.name}`, repository: {
prodBranch: repository.default_branch as string, owner: repository.owner?.login,
repository: repository.full_name, name: repository.name,
// TODO: Compute template from repo defaultBranch: repository.default_branch,
template: 'webapp', fullName: repository.full_name,
}); },
if (addProject) { orgSlug,
navigate(`import?projectId=${addProject.id}`); },
} else {
toast({
id: 'failed-to-create-project',
title: 'Failed to create project',
variant: 'error',
onDismiss: dismiss,
});
} }
} catch (error) { );
console.error((error as Error).message);
toast({
id: 'failed-to-create-project',
title: 'Failed to create project',
variant: 'error',
onDismiss: dismiss,
});
} finally {
setIsLoading(false);
}
}, [client, repository, orgSlug, setIsLoading, navigate, toast]); }, [client, repository, orgSlug, setIsLoading, navigate, toast]);
return ( return (

View File

@ -2,7 +2,8 @@ import NewProject from './index';
import CreateWithTemplate from './Template'; import CreateWithTemplate from './Template';
import { templateRoutes } from './template/routes'; import { templateRoutes } from './template/routes';
import Id from './success/Id'; import Id from './success/Id';
import Import from './Import'; import Configure from 'components/projects/create/Configure';
import Deploy from 'components/projects/create/Deploy';
export const createProjectRoutes = [ export const createProjectRoutes = [
{ {
@ -19,7 +20,11 @@ export const createProjectRoutes = [
element: <Id />, element: <Id />,
}, },
{ {
path: 'import', path: 'configure',
element: <Import />, element: <Configure />,
},
{
path: 'deploy',
element: <Deploy />,
}, },
]; ];

View File

@ -385,7 +385,7 @@ var addProjectFromTemplate = import_client2.gql`
} }
`; `;
var addProject = import_client2.gql` var addProject = import_client2.gql`
mutation ($organizationSlug: String!, $data: AddProjectInput, $lrn: String, $auctionData: AuctionData) { mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionData: AuctionData) {
addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionData: $auctionData) { addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionData: $auctionData) {
id id
} }

File diff suppressed because one or more lines are too long

View File

@ -357,7 +357,7 @@ var addProjectFromTemplate = gql2`
} }
`; `;
var addProject = gql2` var addProject = gql2`
mutation ($organizationSlug: String!, $data: AddProjectInput, $lrn: String, $auctionData: AuctionData) { mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionData: AuctionData) {
addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionData: $auctionData) { addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionData: $auctionData) {
id id
} }

File diff suppressed because one or more lines are too long

View File

@ -57,7 +57,7 @@ export const addProjectFromTemplate = gql`
`; `;
export const addProject = gql` export const addProject = gql`
mutation ($organizationSlug: String!, $data: AddProjectInput, $lrn: String, $auctionData: AuctionData) { mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionData: AuctionData) {
addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionData: $auctionData) { addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionData: $auctionData) {
id id
} }