From 25283da940647efc6ebe7ca4b941d49bd90de54d Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Tue, 22 Oct 2024 19:20:06 +0530 Subject: [PATCH 1/9] Remove useCallback for fetching logs --- packages/backend/src/service.ts | 6 +++--- .../project/deployments/DeploymentDetailsCard.tsx | 12 ++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 318e0c9b..cfc4fc49 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -334,9 +334,9 @@ export class Service { await this.updateProjectWithDeployer(project.id, deployer); } - for (const deployer of deployerIds) { - log(`Creating deployment for deployer LRN ${deployer}`); - await this.createDeploymentFromAuction(project, deployer); + for (const deployerId of deployerIds) { + log(`Creating deployment for deployer ${deployerId}`); + await this.createDeploymentFromAuction(project, deployerId); } } } diff --git a/packages/frontend/src/components/projects/project/deployments/DeploymentDetailsCard.tsx b/packages/frontend/src/components/projects/project/deployments/DeploymentDetailsCard.tsx index b8abe55b..fa6142e9 100644 --- a/packages/frontend/src/components/projects/project/deployments/DeploymentDetailsCard.tsx +++ b/packages/frontend/src/components/projects/project/deployments/DeploymentDetailsCard.tsx @@ -91,7 +91,7 @@ const DeploymentDetailsCard = ({ } }; - const fetchDeploymentLogs = useCallback(async () => { + const fetchDeploymentLogs = async () => { let url = `${deployment.deployer.deployerApiUrl}/log/${deployment.applicationDeploymentRequestId}`; const res = await fetch(url, { cache: 'no-store' }); handleOpenDialog(); @@ -99,11 +99,7 @@ const DeploymentDetailsCard = ({ const logs = await res.text(); setDeploymentLogs(logs); } - }, [ - deployment.deployer.deployerApiUrl, - deployment.applicationDeploymentRequestId, - handleOpenDialog, - ]); + }; const renderDeploymentStatus = useCallback( (className?: string) => { @@ -189,8 +185,8 @@ const DeploymentDetailsCard = ({ type="orange" initials={getInitials(deployment.createdBy.name ?? '')} className="lg:size-5 2xl:size-6" - // TODO: Add avatarUrl - // imageSrc={deployment.createdBy.avatarUrl} + // TODO: Add avatarUrl + // imageSrc={deployment.createdBy.avatarUrl} > Date: Tue, 22 Oct 2024 19:28:06 +0530 Subject: [PATCH 2/9] Add method to fetch deployers while creating project --- packages/backend/src/database.ts | 6 ++++++ packages/backend/src/resolvers.ts | 4 ++++ packages/backend/src/schema.gql | 1 + packages/backend/src/service.ts | 5 +++++ .../src/components/projects/create/Configure.tsx | 15 +++++++++++++-- packages/gql-client/src/client.ts | 8 ++++++++ packages/gql-client/src/queries.ts | 10 ++++++++++ packages/gql-client/src/types.ts | 4 ++++ 8 files changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 7bcd77bc..518bab6c 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -597,4 +597,10 @@ export class Database { return deployer; } + + async getDeployers(): Promise { + const deployerRepository = this.dataSource.getRepository(Deployer); + const deployers = await deployerRepository.find(); + return deployers; + } } diff --git a/packages/backend/src/resolvers.ts b/packages/backend/src/resolvers.ts index 067a9f72..b4c2c01c 100644 --- a/packages/backend/src/resolvers.ts +++ b/packages/backend/src/resolvers.ts @@ -76,6 +76,10 @@ export const createResolvers = async (service: Service): Promise => { ) => { return service.getAuctionData(auctionId); }, + + deployers: async (_: any, __: any, context: any) => { + return service.getDeployers(); + }, }, // TODO: Return error in GQL response diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 4a63e584..5accd5a3 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -257,6 +257,7 @@ type Query { searchProjects(searchText: String!): [Project!] getAuctionData(auctionId: String!): Auction! domains(projectId: String!, filter: FilterDomainsInput): [Domain] + deployers: [Deployer] } type Mutation { diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index cfc4fc49..635c522f 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -443,6 +443,11 @@ export class Service { return dbDeployments; } + async getDeployers(): Promise { + const dbDeployers = await this.db.getDeployers(); + return dbDeployers; + } + async getEnvironmentVariablesByProjectId( projectId: string, ): Promise { diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index d1380f64..95d4712b 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -1,9 +1,9 @@ -import { useCallback, useState } from 'react'; +import { useCallback, useState, useEffect } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { FormProvider, FieldValues } from 'react-hook-form'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { useMediaQuery } from 'usehooks-ts'; -import { AddEnvironmentVariableInput, AuctionParams } from 'gql-client'; +import { AddEnvironmentVariableInput, AuctionParams, Deployer } from 'gql-client'; import { ArrowRightCircleFilledIcon, @@ -30,6 +30,8 @@ type ConfigureFormValues = ConfigureDeploymentFormValues & const Configure = () => { const [isLoading, setIsLoading] = useState(false); + const [deployers, setDeployers] = useState([]); + const [searchParams] = useSearchParams(); const templateId = searchParams.get('templateId'); const queryParams = new URLSearchParams(location.search); @@ -171,6 +173,15 @@ const Configure = () => { [client, createProject, dismiss, toast], ); + const fetchDeployers = useCallback(async () => { + const res = await client.getDeployers() + setDeployers(res.deployers) + }, [client]) + + useEffect(()=>{ + fetchDeployers() + }, []) + return (
diff --git a/packages/gql-client/src/client.ts b/packages/gql-client/src/client.ts index 0e0eff9f..87e4bc80 100644 --- a/packages/gql-client/src/client.ts +++ b/packages/gql-client/src/client.ts @@ -424,4 +424,12 @@ export class GQLClient { return data.getAuctionData; } + + async getDeployers(): Promise { + const { data } = await this.client.query({ + query: queries.getDeployers, + }); + + return data; + } } diff --git a/packages/gql-client/src/queries.ts b/packages/gql-client/src/queries.ts index 0d2ad0f9..da8c9b62 100644 --- a/packages/gql-client/src/queries.ts +++ b/packages/gql-client/src/queries.ts @@ -307,3 +307,13 @@ query ($auctionId: String!) { } } `; + +export const getDeployers = gql` +query { + deployers { + deployerApiUrl + deployerId + deployerLrn + } +} +`; \ No newline at end of file diff --git a/packages/gql-client/src/types.ts b/packages/gql-client/src/types.ts index 74cf17b1..258aeff1 100644 --- a/packages/gql-client/src/types.ts +++ b/packages/gql-client/src/types.ts @@ -233,6 +233,10 @@ export type GetDomainsResponse = { domains: Domain[]; }; +export type GetDeployersResponse = { + deployers: Deployer[]; +}; + export type SearchProjectsResponse = { searchProjects: Project[]; }; -- 2.45.2 From 967eded8b1424fc7ee1333c4a69ff4ebd14a74ed Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 23 Oct 2024 10:45:15 +0530 Subject: [PATCH 3/9] Display deployer LRNs in dropdown --- packages/backend/src/registry.ts | 1 + packages/backend/src/service.ts | 39 ++++++++++++++++--- .../components/projects/create/Configure.tsx | 38 +++++++++++------- .../project/overview/Activity/AuctionCard.tsx | 8 +++- packages/gql-client/src/queries.ts | 2 +- 5 files changed, 67 insertions(+), 21 deletions(-) diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index f4df1353..9371baaa 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -283,6 +283,7 @@ export class Registry { this.registryConfig.privateKey, fee ); + log(`Application deployment request record published: ${result.id}`); log('Application deployment request data:', applicationDeploymentRequest); diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 635c522f..258a99e6 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -443,11 +443,6 @@ export class Service { return dbDeployments; } - async getDeployers(): Promise { - const dbDeployers = await this.db.getDeployers(); - return dbDeployers; - } - async getEnvironmentVariablesByProjectId( projectId: string, ): Promise { @@ -1374,4 +1369,38 @@ export class Service { return false; } + + async getDeployers(): Promise { + const dbDeployers = await this.db.getDeployers(); + + if (dbDeployers.length > 0) { + this.updateDeployersFromRegistry(); + return dbDeployers; + } else { + return await this.updateDeployersFromRegistry(); + } + } + + async updateDeployersFromRegistry(): Promise { + const deployerRecords = await this.laconicRegistry.getDeployerRecordsByFilter({}); + + for (const record of deployerRecords) { + const deployerId = record.id; + const deployerLrn = record.names[0]; + + const deployerApiUrl = record.attributes.apiUrl; + const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); + + const deployerData = { + deployerId, + deployerLrn, + deployerApiUrl, + baseDomain + }; + + await this.db.addDeployer(deployerData); + } + + return await this.db.getDeployers(); + } } diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index 95d4712b..0eaf4721 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -155,19 +155,19 @@ const Configure = () => { if (templateId) { createFormData.option === 'Auction' ? navigate( - `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, - ) + `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, + ) : navigate( - `/${orgSlug}/projects/create/template/deploy?projectId=${projectId}&templateId=${templateId}`, - ); + `/${orgSlug}/projects/create/template/deploy?projectId=${projectId}&templateId=${templateId}`, + ); } else { createFormData.option === 'Auction' ? navigate( - `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, - ) + `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, + ) : navigate( - `/${orgSlug}/projects/create/deploy?projectId=${projectId}`, - ); + `/${orgSlug}/projects/create/deploy?projectId=${projectId}`, + ); } }, [client, createProject, dismiss, toast], @@ -176,9 +176,9 @@ const Configure = () => { const fetchDeployers = useCallback(async () => { const res = await client.getDeployers() setDeployers(res.deployers) - }, [client]) + }, [client]) - useEffect(()=>{ + useEffect(() => { fetchDeployers() }, []) @@ -236,15 +236,25 @@ const Configure = () => { > The app will be deployed by the configured deployer - - Enter LRN for deployer - ( - + - onChange((value as SelectOption).value) - } - options={[ - { value: 'LRN', label: 'Deployer LRN' }, - { value: 'Auction', label: 'Create Auction' }, - ]} - /> + value={value} + onChange={(event) => onChange(event.target.value)} + size='small' + displayEmpty + > + Deployer LRN + Create Auction + )} />
@@ -240,21 +231,26 @@ const Configure = () => { name="lrn" control={methods.control} rules={{ required: true }} - render={({ field: { value, onChange } }) => ( - onChange(event.target.value)} + displayEmpty + size='small' + + > + {deployers.map((deployer) => ( + + {deployer.deployerLrn} + + ))} + + {fieldState.error && {fieldState.error.message}} + )} />
diff --git a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx index aea84caa..291bc7ff 100644 --- a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx +++ b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx @@ -17,6 +17,16 @@ import { Button, Heading, Tag } from 'components/shared'; const WAIT_DURATION = 5000; +const DIALOG_STYLE = { + backgroundColor: 'rgba(0,0,0, .9)', + padding: '2em', + borderRadius: '0.5em', + marginLeft: '0.5em', + marginRight: '0.5em', + color: 'gray', + fontSize: 'small', +}; + export const AuctionCard = ({ project }: { project: Project }) => { const [auctionStatus, setAuctionStatus] = useState(''); const [deployers, setDeployers] = useState([]); @@ -140,7 +150,7 @@ export const AuctionCard = ({ project }: { project: Project }) => { maxWidth="md" > Auction Details - + {auctionDetails && (
{JSON.stringify(auctionDetails, null, 2)}
)} -- 2.45.2 From 3aee4ac6f813c97bacf27f2b0a02458710c13043 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 23 Oct 2024 14:22:05 +0530 Subject: [PATCH 5/9] Set deployer LRN as the primary key for Deployer table --- packages/backend/src/database.ts | 8 -- packages/backend/src/entity/Deployer.ts | 4 +- packages/backend/src/entity/Deployment.ts | 2 +- packages/backend/src/schema.gql | 2 +- packages/backend/src/service.ts | 105 +++++++----------- .../components/projects/create/Configure.tsx | 4 +- packages/gql-client/src/queries.ts | 20 ++-- packages/gql-client/src/types.ts | 4 +- 8 files changed, 60 insertions(+), 89 deletions(-) diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 518bab6c..41a73b9d 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -590,14 +590,6 @@ export class Database { return newDomain; } - async getDeployerById (deployerId: string): Promise { - const deployerRepository = this.dataSource.getRepository(Deployer); - - const deployer = await deployerRepository.findOne({ where: { deployerId } }); - - return deployer; - } - async getDeployers(): Promise { const deployerRepository = this.dataSource.getRepository(Deployer); const deployers = await deployerRepository.find(); diff --git a/packages/backend/src/entity/Deployer.ts b/packages/backend/src/entity/Deployer.ts index bdb920e3..854ab1dd 100644 --- a/packages/backend/src/entity/Deployer.ts +++ b/packages/backend/src/entity/Deployer.ts @@ -4,10 +4,10 @@ import { Project } from './Project'; @Entity() export class Deployer { @PrimaryColumn('varchar') - deployerId!: string; + deployerLrn!: string; @Column('varchar') - deployerLrn!: string; + deployerId!: string; @Column('varchar') deployerApiUrl!: string; diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index 21bfb4e4..5efb28b4 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -129,7 +129,7 @@ export class Deployment { applicationDeploymentRemovalRecordData!: AppDeploymentRemovalRecordAttributes | null; @ManyToOne(() => Deployer) - @JoinColumn({ name: 'deployerId' }) + @JoinColumn({ name: 'deployerLrn' }) deployer!: Deployer; @Column({ diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 5accd5a3..5cead09e 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -134,8 +134,8 @@ type EnvironmentVariable { } type Deployer { - deployerId: String! deployerLrn: String! + deployerId: String! deployerApiUrl: String! createdAt: String! updatedAt: String! diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 258a99e6..2ee14e0a 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -21,6 +21,7 @@ import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, + DeployerRecord, EnvironmentVariables, GitPushEventPayload, } from './types'; @@ -309,35 +310,13 @@ export class Service { if (!deployerRecords) { log(`No winning deployer for auction ${project!.auctionId}`); } else { - const deployerIds = []; - - for (const record of deployerRecords) { - const deployerId = record.id; - const deployerLrn = record.names[0]; - - deployerIds.push(deployerId); - - const deployerApiUrl = record.attributes.apiUrl; - const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); - - const deployerData = { - deployerId, - deployerLrn, - deployerApiUrl, - baseDomain - }; - - // Store the deployer in the DB - const deployer = await this.db.addDeployer(deployerData); - + const deployers = await this.saveDeployersByDeployerRecords(deployerRecords); + for (const deployer of deployers) { + log(`Creating deployment for deployer ${deployer.deployerLrn}`); + await this.createDeploymentFromAuction(project, deployer); // Update project with deployer await this.updateProjectWithDeployer(project.id, deployer); } - - for (const deployerId of deployerIds) { - log(`Creating deployment for deployer ${deployerId}`); - await this.createDeploymentFromAuction(project, deployerId); - } } } @@ -649,7 +628,7 @@ export class Service { deployer = data.deployer; } - const newDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerId!, applicationRecordId, applicationRecordData); + const newDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData); const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash); const environmentVariablesObj = await this.getEnvVariables(data.project!.id!); @@ -687,7 +666,7 @@ export class Service { async createDeploymentFromAuction( project: DeepPartial, - deployerId: string + deployer: Deployer ): Promise { const octokit = await this.getOctokit(project.ownerId!); const [owner, repo] = project.repository!.split('/'); @@ -713,7 +692,6 @@ export class Service { const applicationRecordId = record.id; const applicationRecordData = record.attributes; - const deployer = await this.db.getDeployerById(deployerId); const deployerLrn = deployer!.deployerLrn // Create deployment with prod branch and latest commit @@ -726,7 +704,7 @@ export class Service { commitMessage: latestCommit.commit.message, }; - const newDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerId, applicationRecordId, applicationRecordData); + const newDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData); const environmentVariablesObj = await this.getEnvVariables(project!.id!); // To set project DNS @@ -767,7 +745,7 @@ export class Service { async createDeploymentFromData( userId: string, data: DeepPartial, - deployerId: string, + deployerLrn: string, applicationRecordId: string, applicationRecordData: ApplicationRecord, ): Promise { @@ -785,7 +763,7 @@ export class Service { id: userId, }), deployer: Object.assign(new Deployer(), { - deployerId, + deployerLrn, }), }); @@ -802,20 +780,9 @@ export class Service { return null; } - const deployerId = records[0].id; - const deployerApiUrl = records[0].attributes.apiUrl; - const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); + const deployer = await this.saveDeployersByDeployerRecords(records); - const deployerData = { - deployerId, - deployerLrn, - deployerApiUrl, - baseDomain - }; - - const deployer = await this.db.addDeployer(deployerData); - - return deployer; + return deployer[0]; } async updateProjectWithDeployer( @@ -1089,7 +1056,7 @@ export class Service { let newDeployment: Deployment; if (oldDeployment.project.auctionId) { - newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer.deployerId); + newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployer); } else { newDeployment = await this.createDeployment(user.id, octokit, { @@ -1374,33 +1341,45 @@ export class Service { const dbDeployers = await this.db.getDeployers(); if (dbDeployers.length > 0) { + // Call asynchronously to fetch the records from the registry and update the DB this.updateDeployersFromRegistry(); return dbDeployers; } else { + // Fetch from the registry and populate empty DB return await this.updateDeployersFromRegistry(); } } async updateDeployersFromRegistry(): Promise { const deployerRecords = await this.laconicRegistry.getDeployerRecordsByFilter({}); - - for (const record of deployerRecords) { - const deployerId = record.id; - const deployerLrn = record.names[0]; - - const deployerApiUrl = record.attributes.apiUrl; - const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); - - const deployerData = { - deployerId, - deployerLrn, - deployerApiUrl, - baseDomain - }; - - await this.db.addDeployer(deployerData); - } + await this.saveDeployersByDeployerRecords(deployerRecords); return await this.db.getDeployers(); } + + async saveDeployersByDeployerRecords(deployerRecords: DeployerRecord[]): Promise { + const deployers: Deployer[] = []; + + for (const record of deployerRecords) { + if (record.names.length > 0) { + const deployerId = record.id; + const deployerLrn = record.names[0]; + const deployerApiUrl = record.attributes.apiUrl; + const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); + + const deployerData = { + deployerLrn, + deployerId, + deployerApiUrl, + baseDomain + }; + + // TODO: Update deployers table in a separate job + const deployer = await this.db.addDeployer(deployerData); + deployers.push(deployer); + } + } + + return deployers; + } } diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index cd4edb05..b57abc02 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -51,7 +51,7 @@ const Configure = () => { const client = useGQLClient(); const methods = useForm({ - defaultValues: { option: 'LRN' }, + defaultValues: { option: 'Auction' }, }); const selectedOption = methods.watch('option'); @@ -244,7 +244,7 @@ const Configure = () => { > {deployers.map((deployer) => ( - + {deployer.deployerLrn} ))} diff --git a/packages/gql-client/src/queries.ts b/packages/gql-client/src/queries.ts index 5f0f85ae..a1ac2af2 100644 --- a/packages/gql-client/src/queries.ts +++ b/packages/gql-client/src/queries.ts @@ -25,9 +25,9 @@ query ($projectId: String!) { prodBranch auctionId deployers { - deployerApiUrl - deployerId deployerLrn + deployerId + deployerApiUrl } fundsReleased framework @@ -81,9 +81,9 @@ query ($organizationSlug: String!) { framework auctionId deployers { - deployerApiUrl - deployerId deployerLrn + deployerId + deployerApiUrl } fundsReleased prodBranch @@ -145,9 +145,9 @@ query ($projectId: String!) { commitMessage url deployer { + deployerLrn deployerId - deployerLrn, - deployerApiUrl, + deployerApiUrl } environment isCurrent @@ -208,9 +208,9 @@ query ($searchText: String!) { framework auctionId deployers { - deployerApiUrl - deployerId deployerLrn + deployerId + deployerApiUrl } fundsReleased prodBranch @@ -311,9 +311,9 @@ query ($auctionId: String!) { export const getDeployers = gql` query { deployers { - deployerApiUrl - deployerId deployerLrn + deployerId + deployerApiUrl } } `; diff --git a/packages/gql-client/src/types.ts b/packages/gql-client/src/types.ts index 258aeff1..c06d9d4e 100644 --- a/packages/gql-client/src/types.ts +++ b/packages/gql-client/src/types.ts @@ -117,9 +117,9 @@ export type Deployment = { }; export type Deployer = { - deployerApiUrl: string; - deployerId: string; deployerLrn: string; + deployerId: string; + deployerApiUrl: string; } export type OrganizationMember = { -- 2.45.2 From 1ae2c5b1e1b10c763654671e1ad1ddc4afd39247 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 23 Oct 2024 15:05:30 +0530 Subject: [PATCH 6/9] Display confirm dialog on deleting deployment --- .../Dialog/DeleteDeploymentDialog.tsx | 26 +++++++ .../project/deployments/DeploymentMenu.tsx | 11 ++- .../project/overview/Activity/AuctionCard.tsx | 68 ++++++++++--------- 3 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx diff --git a/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx b/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx new file mode 100644 index 00000000..f83efd76 --- /dev/null +++ b/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx @@ -0,0 +1,26 @@ +import ConfirmDialog, { + ConfirmDialogProps, +} from 'components/shared/ConfirmDialog'; + +export const DeleteDeploymentDialog = ({ + open, + handleCancel, + handleConfirm, + ...props +}: ConfirmDialogProps) => { + return ( + +

+ Once deleted, the deployment will not be accessible. +

+
+ ); +}; diff --git a/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx b/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx index fec28246..9301dd3b 100644 --- a/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx +++ b/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx @@ -23,6 +23,7 @@ import { useGQLClient } from 'context/GQLClientContext'; import { cn } from 'utils/classnames'; import { ChangeStateToProductionDialog } from 'components/projects/Dialog/ChangeStateToProductionDialog'; import { useToast } from 'components/shared/Toast'; +import { DeleteDeploymentDialog } from 'components/projects/Dialog/DeleteDeploymentDialog'; interface DeploymentMenuProps extends ComponentPropsWithRef<'div'> { deployment: Deployment; @@ -46,6 +47,7 @@ export const DeploymentMenu = ({ const [changeToProduction, setChangeToProduction] = useState(false); const [redeployToProduction, setRedeployToProduction] = useState(false); + const [deleteDeploymentDialog, setDeleteDeploymentDialog] = useState(false); const [rollbackDeployment, setRollbackDeployment] = useState(false); const [assignDomainDialog, setAssignDomainDialog] = useState(false); const [isConfirmButtonLoading, setConfirmButtonLoadingLoading] = @@ -123,6 +125,8 @@ export const DeploymentMenu = ({ onDismiss: dismiss, }); + setDeleteDeploymentDialog((preVal) => !preVal); + const isDeleted = await client.deleteDeployment(deployment.id); if (isDeleted) { await onUpdate(); @@ -212,7 +216,7 @@ export const DeploymentMenu = ({
deleteDeployment()} + onClick={() => setDeleteDeploymentDialog((preVal) => !preVal)} > Delete deployment @@ -265,6 +269,11 @@ export const DeploymentMenu = ({ open={assignDomainDialog} handleOpen={() => setAssignDomainDialog(!assignDomainDialog)} /> + setDeleteDeploymentDialog((preVal) => !preVal)} + /> ); }; diff --git a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx index 291bc7ff..5e83d91c 100644 --- a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx +++ b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx @@ -96,13 +96,6 @@ export const AuctionCard = ({ project }: { project: Project }) => { -
- - Auction Status - -
{renderAuctionStatus()}
-
-
Auction Id @@ -112,35 +105,48 @@ export const AuctionCard = ({ project }: { project: Project }) => {
- {deployers?.length > 0 ? ( -
- - Deployer LRNs - - {deployers.map((deployer, index) => ( -

- {'\u2022'} {deployer.deployerLrn} -

- ))} -
- ) : ( -
- - No winning deployers - -
- )}
- Deployer Funds Status + Auction Status -
- - {fundsStatus ? 'RELEASED' : 'LOCKED'} - -
+
{renderAuctionStatus()}
+ + {auctionStatus === 'completed' && ( + <> + {deployers?.length > 0 ? ( +
+ + Deployer LRNs + + {deployers.map((deployer, index) => ( +

+ {'\u2022'} {deployer.deployerLrn} +

+ ))} +
+ ) : ( +
+ + No winning deployers + +
+ )} + +
+ + Deployer Funds Status + +
+ + {fundsStatus ? 'RELEASED' : 'LOCKED'} + +
+
+ + )} + Date: Wed, 23 Oct 2024 15:52:15 +0530 Subject: [PATCH 7/9] Display loader on deleting deployment --- .../Dialog/DeleteDeploymentDialog.tsx | 20 ++++++++++++++++--- .../project/deployments/DeploymentMenu.tsx | 16 +++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx b/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx index f83efd76..cc10f77a 100644 --- a/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx +++ b/packages/frontend/src/components/projects/Dialog/DeleteDeploymentDialog.tsx @@ -1,22 +1,36 @@ import ConfirmDialog, { ConfirmDialogProps, } from 'components/shared/ConfirmDialog'; +import { ArrowRightCircleFilledIcon, LoadingIcon } from 'components/shared/CustomIcon'; + +interface DeleteDeploymentDialogProps extends ConfirmDialogProps { + isConfirmButtonLoading?: boolean; +} export const DeleteDeploymentDialog = ({ open, handleCancel, handleConfirm, + isConfirmButtonLoading, ...props -}: ConfirmDialogProps) => { +}: DeleteDeploymentDialogProps) => { return ( + ) : ( + + ), + }} >

Once deleted, the deployment will not be accessible. diff --git a/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx b/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx index 9301dd3b..421c2bba 100644 --- a/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx +++ b/packages/frontend/src/components/projects/project/deployments/DeploymentMenu.tsx @@ -48,6 +48,7 @@ export const DeploymentMenu = ({ const [changeToProduction, setChangeToProduction] = useState(false); const [redeployToProduction, setRedeployToProduction] = useState(false); const [deleteDeploymentDialog, setDeleteDeploymentDialog] = useState(false); + const [isConfirmDeleteLoading, setIsConfirmDeleteLoading] = useState(false); const [rollbackDeployment, setRollbackDeployment] = useState(false); const [assignDomainDialog, setAssignDomainDialog] = useState(false); const [isConfirmButtonLoading, setConfirmButtonLoadingLoading] = @@ -118,16 +119,11 @@ export const DeploymentMenu = ({ }; const deleteDeployment = async () => { - toast({ - id: 'deleting_deployment', - title: 'Deleting deployment....', - variant: 'success', - onDismiss: dismiss, - }); + const isDeleted = await client.deleteDeployment(deployment.id); + setIsConfirmDeleteLoading(false); setDeleteDeploymentDialog((preVal) => !preVal); - const isDeleted = await client.deleteDeployment(deployment.id); if (isDeleted) { await onUpdate(); toast({ @@ -271,8 +267,12 @@ export const DeploymentMenu = ({ /> { + setIsConfirmDeleteLoading(true); + await deleteDeployment(); + }} handleCancel={() => setDeleteDeploymentDialog((preVal) => !preVal)} + isConfirmButtonLoading={isConfirmDeleteLoading} /> ); -- 2.45.2 From 9595f088008d9090623d1b3d894e4c54940dbe57 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 23 Oct 2024 16:52:36 +0530 Subject: [PATCH 8/9] Remove baseDomains usage from database --- packages/backend/src/database.ts | 11 ++++------- packages/backend/src/index.ts | 2 +- packages/backend/test/publish-deploy-records.ts | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 41a73b9d..7cefbaa2 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -34,9 +34,8 @@ const nanoid = customAlphabet(lowercase + numbers, 8); // TODO: Fix order of methods export class Database { private dataSource: DataSource; - private projectDomain: string; - constructor({ dbPath }: DatabaseConfig, { projectDomain }: MiscConfig) { + constructor({ dbPath }: DatabaseConfig) { this.dataSource = new DataSource({ type: 'better-sqlite3', database: dbPath, @@ -44,8 +43,6 @@ export class Database { synchronize: true, logging: false }); - - this.projectDomain = projectDomain; } async init(): Promise { @@ -491,13 +488,13 @@ export class Database { return projectRepository.save(newProject); } - async saveProject (project: Project): Promise { + async saveProject(project: Project): Promise { const projectRepository = this.dataSource.getRepository(Project); return projectRepository.save(project); } - async updateProjectById ( + async updateProjectById( projectId: string, data: DeepPartial ): Promise { @@ -583,7 +580,7 @@ export class Database { return domains; } - async addDeployer (data: DeepPartial): Promise { + async addDeployer(data: DeepPartial): Promise { const deployerRepository = this.dataSource.getRepository(Deployer); const newDomain = await deployerRepository.save(data); diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index c6f0b3c6..629bd6e7 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -25,7 +25,7 @@ export const main = async (): Promise => { clientSecret: gitHub.oAuth.clientSecret, }); - const db = new Database(database, misc); + const db = new Database(database); await db.init(); const registry = new Registry(registryConfig); diff --git a/packages/backend/test/publish-deploy-records.ts b/packages/backend/test/publish-deploy-records.ts index cb40e032..26e0823a 100644 --- a/packages/backend/test/publish-deploy-records.ts +++ b/packages/backend/test/publish-deploy-records.ts @@ -38,7 +38,7 @@ async function main() { }); for await (const deployment of deployments) { - const url = `https://${deployment.project.name}-${deployment.id}.${misc.projectDomain}`; + const url = `https://${(deployment.project.name).toLowerCase()}-${deployment.id}.${deployment.deployer.baseDomain}`; const applicationDeploymentRecord = { type: 'ApplicationDeploymentRecord', @@ -73,7 +73,7 @@ async function main() { // Remove deployment for project subdomain if deployment is for production environment if (deployment.environment === Environment.Production) { - applicationDeploymentRecord.url = `https://${deployment.project.name}.${deployment.baseDomain}`; + applicationDeploymentRecord.url = `https://${deployment.project.name}.${deployment.deployer.baseDomain}`; await registry.setRecord( { -- 2.45.2 From 043bcac3beb77ebcc8e6b8645a1d9372cc462b3b Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 23 Oct 2024 18:26:02 +0530 Subject: [PATCH 9/9] Add method to query deployer by LRN --- packages/backend/src/database.ts | 7 ++++++ packages/backend/src/service.ts | 15 +----------- .../components/projects/create/Configure.tsx | 1 - .../project/overview/Activity/AuctionCard.tsx | 23 +++++++++---------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 7cefbaa2..8bf75d32 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -592,4 +592,11 @@ export class Database { const deployers = await deployerRepository.find(); return deployers; } + + async getDeployerByLRN(deployerLrn: string): Promise { + const deployerRepository = this.dataSource.getRepository(Deployer); + const deployer = await deployerRepository.findOne({ where: { deployerLrn } }); + + return deployer; + } } diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 2ee14e0a..bcd7e4b8 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -623,7 +623,7 @@ export class Service { let deployer; if (deployerLrn) { - deployer = await this.createDeployerFromLRN(deployerLrn); + deployer = await this.db.getDeployerByLRN(deployerLrn); } else { deployer = data.deployer; } @@ -772,19 +772,6 @@ export class Service { return newDeployment; } - async createDeployerFromLRN(deployerLrn: string): Promise { - const records = await this.laconicRegistry.getRecordsByName(deployerLrn); - - if (records.length === 0) { - log('No records found for deployer LRN:', deployerLrn); - return null; - } - - const deployer = await this.saveDeployersByDeployerRecords(records); - - return deployer[0]; - } - async updateProjectWithDeployer( projectId: string, deployer: Deployer diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index b57abc02..9e6a45a7 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -241,7 +241,6 @@ const Configure = () => { onChange={(event) => onChange(event.target.value)} displayEmpty size='small' - > {deployers.map((deployer) => ( diff --git a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx index 5e83d91c..cbf725f8 100644 --- a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx +++ b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx @@ -125,6 +125,17 @@ export const AuctionCard = ({ project }: { project: Project }) => { {'\u2022'} {deployer.deployerLrn}

))} + +
+ + Deployer Funds Status + +
+ + {fundsStatus ? 'RELEASED' : 'LOCKED'} + +
+
) : (
@@ -133,20 +144,8 @@ export const AuctionCard = ({ project }: { project: Project }) => {
)} - -
- - Deployer Funds Status - -
- - {fundsStatus ? 'RELEASED' : 'LOCKED'} - -
-
)} -