forked from cerc-io/snowballtools-base
		
	Fix deployments visit URL and date filter (#78)
* Add method to update multiple deployments in single query * Fix deployments URL visit and date filter * Clean fixtures data * Update fixtures data --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
		
							parent
							
								
									c3d1b4f3eb
								
							
						
					
					
						commit
						a45fb4c617
					
				| @ -316,6 +316,19 @@ export class Database { | ||||
|     return Boolean(updateResult.affected); | ||||
|   } | ||||
| 
 | ||||
|   async updateDeploymentsByProjectIds (projectIds: string[], data: DeepPartial<Deployment>): Promise<boolean> { | ||||
|     const deploymentRepository = this.dataSource.getRepository(Deployment); | ||||
| 
 | ||||
|     const updateResult = await deploymentRepository | ||||
|       .createQueryBuilder() | ||||
|       .update(Deployment) | ||||
|       .set(data) | ||||
|       .where('projectId IN (:...projectIds)', { projectIds }) | ||||
|       .execute(); | ||||
| 
 | ||||
|     return Boolean(updateResult.affected); | ||||
|   } | ||||
| 
 | ||||
|   async addProject (userId: string, organizationId: string, data: DeepPartial<Project>): Promise<Project> { | ||||
|     const projectRepository = this.dataSource.getRepository(Project); | ||||
| 
 | ||||
|  | ||||
| @ -78,7 +78,9 @@ export class Service { | ||||
|       log(`Found ${records.length} ApplicationDeploymentRecords`); | ||||
| 
 | ||||
|       // Update deployments for which ApplicationDeploymentRecords were returned
 | ||||
|       await this.updateDeploymentsWithRecordData(records); | ||||
|       if (records.length) { | ||||
|         await this.updateDeploymentsWithRecordData(records); | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     this.deployRecordCheckTimeout = setTimeout(() => { | ||||
| @ -110,10 +112,7 @@ export class Service { | ||||
|     }, new Set<string>()); | ||||
| 
 | ||||
|     // Set old deployments isCurrent to false
 | ||||
|     await Promise.all(Array.from(productionDeploymentProjectIds).map( | ||||
|       // TODO: Add DB method to update multiple deployments in single query
 | ||||
|       async (projectId) => this.db.updateDeployment({ projectId }, { isCurrent: false }) | ||||
|     )); | ||||
|     await this.db.updateDeploymentsByProjectIds(Array.from(productionDeploymentProjectIds), { isCurrent: false }); | ||||
| 
 | ||||
|     const recordToDeploymentsMap = deployments.reduce((acc: {[key: string]: Deployment}, deployment) => { | ||||
|       acc[deployment.applicationRecordId] = deployment; | ||||
| @ -135,7 +134,7 @@ export class Service { | ||||
|         } | ||||
|       ); | ||||
| 
 | ||||
|       log(`Updated deployment deployment ${deployment.id} with URL ${record.attributes.url}`); | ||||
|       log(`Updated deployment ${deployment.id} with URL ${record.attributes.url}`); | ||||
|     }); | ||||
| 
 | ||||
|     await Promise.all(deploymentUpdatePromises); | ||||
| @ -295,7 +294,6 @@ export class Service { | ||||
|       octokit, | ||||
|       { | ||||
|         project: oldDeployment.project, | ||||
|         isCurrent: true, | ||||
|         branch: oldDeployment.branch, | ||||
|         environment: Environment.Production, | ||||
|         domain: prodBranchDomains[0], | ||||
| @ -357,7 +355,6 @@ export class Service { | ||||
|       commitHash: data.commitHash, | ||||
|       commitMessage: data.commitMessage, | ||||
|       environment: data.environment, | ||||
|       isCurrent: data.isCurrent, | ||||
|       status: DeploymentStatus.Building, | ||||
|       applicationRecordId, | ||||
|       applicationRecordData, | ||||
| @ -400,7 +397,6 @@ export class Service { | ||||
|       octokit, | ||||
|       { | ||||
|         project, | ||||
|         isCurrent: true, | ||||
|         branch: project.prodBranch, | ||||
|         environment: Environment.Production, | ||||
|         domain: null, | ||||
| @ -486,7 +482,6 @@ export class Service { | ||||
|         octokit, | ||||
|         { | ||||
|           project, | ||||
|           isCurrent: project.prodBranch === branch, | ||||
|           branch, | ||||
|           environment: project.prodBranch === branch ? Environment.Production : Environment.Preview, | ||||
|           domain, | ||||
| @ -543,7 +538,6 @@ export class Service { | ||||
|         project: oldDeployment.project, | ||||
|         // TODO: Put isCurrent field in project
 | ||||
|         branch: oldDeployment.branch, | ||||
|         isCurrent: true, | ||||
|         environment: Environment.Production, | ||||
|         domain: oldDeployment.domain, | ||||
|         commitHash: oldDeployment.commitHash, | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
|   }, | ||||
|   { | ||||
|     "id": "7eb9b3eb-eb74-4b53-b59a-69884c82a7fb", | ||||
|     "name": "AirFoil", | ||||
|     "slug": "airfoil-2" | ||||
|     "name": "Laconic", | ||||
|     "slug": "laconic-2" | ||||
|   } | ||||
| ] | ||||
|  | ||||
| @ -1,37 +1,37 @@ | ||||
| [ | ||||
|   { | ||||
|     "projectIndex": 0, | ||||
|     "name": "randomurl.snowballtools.xyz", | ||||
|     "name": "example.snowballtools.xyz", | ||||
|     "status": "Live", | ||||
|     "branch": "main" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 0, | ||||
|     "name": "saugatt.com", | ||||
|     "name": "example.org", | ||||
|     "status": "Pending", | ||||
|     "branch": "test" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 1, | ||||
|     "name": "randomurl.snowballtools.xyz", | ||||
|     "name": "example.snowballtools.xyz", | ||||
|     "status": "Live", | ||||
|     "branch": "main" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 1, | ||||
|     "name": "saugatt.com", | ||||
|     "name": "example.org", | ||||
|     "status": "Pending", | ||||
|     "branch": "test" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 2, | ||||
|     "name": "randomurl.snowballtools.xyz", | ||||
|     "name": "example.snowballtools.xyz", | ||||
|     "status": "Live", | ||||
|     "branch": "main" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 2, | ||||
|     "name": "saugatt.com", | ||||
|     "name": "example.org", | ||||
|     "status": "Pending", | ||||
|     "branch": "test" | ||||
|   }, | ||||
|  | ||||
| @ -1,21 +1,21 @@ | ||||
| [ | ||||
|   { | ||||
|     "projectIndex": 0, | ||||
|     "name": "www.saugatt.com", | ||||
|     "name": "www.example.org", | ||||
|     "status": "Pending", | ||||
|     "redirectToIndex": 1, | ||||
|     "branch": "test" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 1, | ||||
|     "name": "www.saugatt.com", | ||||
|     "name": "www.example.org", | ||||
|     "status": "Pending", | ||||
|     "redirectToIndex": 3, | ||||
|     "branch": "test" | ||||
|   }, | ||||
|   { | ||||
|     "projectIndex": 2, | ||||
|     "name": "www.saugatt.com", | ||||
|     "name": "www.example.org", | ||||
|     "status": "Pending", | ||||
|     "redirectToIndex": 5, | ||||
|     "branch": "test" | ||||
|  | ||||
							
								
								
									
										12
									
								
								packages/backend/test/fixtures/users.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								packages/backend/test/fixtures/users.json
									
									
									
									
										vendored
									
									
								
							| @ -1,20 +1,20 @@ | ||||
| [ | ||||
|   { | ||||
|     "id": "59f4355d-9549-4aac-9b54-eeefceeabef0", | ||||
|     "name": "Saugat Yadav", | ||||
|     "email": "saugaty@airfoil.studio", | ||||
|     "name": "Snowball", | ||||
|     "email": "snowball@snowballtools.xyz", | ||||
|     "isVerified": true | ||||
|   }, | ||||
|   { | ||||
|     "id": "e505b212-8da6-48b2-9614-098225dab34b", | ||||
|     "name": "Gideon Low", | ||||
|     "email": "gideonl@airfoil.studio", | ||||
|     "name": "Alice Anderson", | ||||
|     "email": "alice@snowballtools.xyz", | ||||
|     "isVerified": true | ||||
|   }, | ||||
|   { | ||||
|     "id": "cd892fad-9138-4aa2-a62c-414a32776ea7", | ||||
|     "name": "Sushan Yadav", | ||||
|     "email": "sushany@airfoil.studio", | ||||
|     "name": "Bob Banner", | ||||
|     "email": "bob@snowballtools.xyz", | ||||
|     "isVerified": true | ||||
|   } | ||||
| ] | ||||
|  | ||||
| @ -20,7 +20,7 @@ const log = debug('snowball:initialize-database'); | ||||
| const USER_DATA_PATH = './fixtures/users.json'; | ||||
| const PROJECT_DATA_PATH = './fixtures/projects.json'; | ||||
| const ORGANIZATION_DATA_PATH = './fixtures/organizations.json'; | ||||
| const USER_ORGANIZATION_DATA_PATH = './fixtures/user-orgnizations.json'; | ||||
| const USER_ORGANIZATION_DATA_PATH = './fixtures/user-organizations.json'; | ||||
| const PROJECT_MEMBER_DATA_PATH = './fixtures/project-members.json'; | ||||
| const PRIMARY_DOMAIN_DATA_PATH = './fixtures/primary-domains.json'; | ||||
| const DEPLOYMENT_DATA_PATH = './fixtures/deployments.json'; | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
|   { | ||||
|     "id": 1, | ||||
|     "projectid": 1, | ||||
|     "name": "randomurl.snowballtools.xyz", | ||||
|     "name": "example.snowballtools.xyz", | ||||
|     "status": "live", | ||||
|     "record": null, | ||||
|     "isRedirectedto": false | ||||
| @ -10,7 +10,7 @@ | ||||
|   { | ||||
|     "id": 2, | ||||
|     "projectid": 1, | ||||
|     "name": "saugatt.com", | ||||
|     "name": "example.org", | ||||
|     "status": "pending", | ||||
|     "record": { | ||||
|       "type": "A", | ||||
| @ -22,7 +22,7 @@ | ||||
|   { | ||||
|     "id": 3, | ||||
|     "projectid": 1, | ||||
|     "name": "www.saugatt.com", | ||||
|     "name": "www.example.org", | ||||
|     "status": "pending", | ||||
|     "record": { | ||||
|       "type": "CNAME", | ||||
|  | ||||
| @ -1,17 +0,0 @@ | ||||
| [ | ||||
|   { | ||||
|     "name": "Saugat Yadav", | ||||
|     "email": "saugaty@airfoil.studio", | ||||
|     "id": 1 | ||||
|   }, | ||||
|   { | ||||
|     "name": "Gideon Low", | ||||
|     "email": "gideonl@airfoil.studio", | ||||
|     "id": 2 | ||||
|   }, | ||||
|   { | ||||
|     "name": "Sushan Yadav", | ||||
|     "email": "sushany@airfoil.studio", | ||||
|     "id": 3 | ||||
|   } | ||||
| ] | ||||
| @ -1,6 +1,6 @@ | ||||
| [ | ||||
|   "[20:50:03.502] Running build in Washington, D.C., USA (East) – iad1", | ||||
|   "[20:50:03.641] Cloning github.com/saugatyadav11/nextjs2 (Branch: main, Commit: 4a5f47f)", | ||||
|   "[20:50:03.641] Cloning github.com/cerc-io/nextjs2 (Branch: main, Commit: 4a5f47f)", | ||||
|   "[20:50:04.004] Previous build cache not available", | ||||
|   "[20:50:04.118] Cloning completed: 480.574ms", | ||||
|   "[20:50:04.382] Running 'vercel build'", | ||||
|  | ||||
| @ -1,190 +0,0 @@ | ||||
| [ | ||||
|   { | ||||
|     "id": 1, | ||||
|     "icon": "^", | ||||
|     "name": "iglootools", | ||||
|     "title": "Iglootools", | ||||
|     "domain": null, | ||||
|     "organization": "Airfoil", | ||||
|     "url": "iglootools.co", | ||||
|     "createdAt": "2023-12-07T04:20:00", | ||||
|     "createdBy": "Alice", | ||||
|     "deployment": "iglootools.snowballtools.co", | ||||
|     "source": "feature/add-remote-control", | ||||
|     "latestCommit": { | ||||
|       "message": "subscription added", | ||||
|       "createdAt": "2023-12-11T04:20:00", | ||||
|       "branch": "main" | ||||
|     }, | ||||
|     "repositoryId": 1, | ||||
|     "members": [ | ||||
|       { | ||||
|         "id": 1, | ||||
|         "permissions": [] | ||||
|       }, | ||||
|       { | ||||
|         "id": 2, | ||||
|         "permissions": ["view", "edit"] | ||||
|       }, | ||||
|       { | ||||
|         "id": 3, | ||||
|         "permissions": ["view"] | ||||
|       } | ||||
|     ], | ||||
|     "ownerId": 1 | ||||
|   }, | ||||
|   { | ||||
|     "id": 2, | ||||
|     "icon": "^", | ||||
|     "name": "snowball-starter-kit", | ||||
|     "title": "Snowball Starter Kit", | ||||
|     "domain": null, | ||||
|     "organization": "Snowball", | ||||
|     "url": "starterkit.snowballtools.com", | ||||
|     "createdAt": "2023-12-04T04:20:00", | ||||
|     "createdBy": "Bob", | ||||
|     "deployment": "deploy.snowballtools.com", | ||||
|     "source": "prod/add-docker-compose", | ||||
|     "latestCommit": { | ||||
|       "message": "component updates", | ||||
|       "createdAt": "2023-12-11T04:20:00", | ||||
|       "branch": "staging" | ||||
|     }, | ||||
|     "repositoryId": 1, | ||||
|     "members": [ | ||||
|       { | ||||
|         "id": 2, | ||||
|         "permissions": [] | ||||
|       }, | ||||
|       { | ||||
|         "id": 3, | ||||
|         "permissions": ["view"] | ||||
|       } | ||||
|     ], | ||||
|     "ownerId": 2 | ||||
|   }, | ||||
|   { | ||||
|     "id": 3, | ||||
|     "icon": "^", | ||||
|     "name": "web3-android", | ||||
|     "title": "Web3 Android", | ||||
|     "domain": null, | ||||
|     "organization": "Personal", | ||||
|     "url": "web3fordroids.com", | ||||
|     "createdAt": "2023-12-01T04:20:00", | ||||
|     "createdBy": "Charlie", | ||||
|     "deployment": "deploy.web3fordroids.com", | ||||
|     "source": "dev/style-page", | ||||
|     "latestCommit": { | ||||
|       "message": "No repo connected", | ||||
|       "createdAt": "2023-12-01T04:20:00", | ||||
|       "branch": "main" | ||||
|     }, | ||||
|     "repositoryId": 1, | ||||
|     "members": [ | ||||
|       { | ||||
|         "id": 1, | ||||
|         "permissions": [] | ||||
|       }, | ||||
|       { | ||||
|         "id": 2, | ||||
|         "permissions": ["view", "edit"] | ||||
|       }, | ||||
|       { | ||||
|         "id": 3, | ||||
|         "permissions": ["view"] | ||||
|       } | ||||
|     ], | ||||
|     "ownerId": 1 | ||||
|   }, | ||||
|   { | ||||
|     "id": 4, | ||||
|     "icon": "^", | ||||
|     "name": "passkeys-demo", | ||||
|     "title": "Passkeys Demo", | ||||
|     "domain": null, | ||||
|     "organization": "Airfoil", | ||||
|     "url": "passkeys.iglootools.xyz", | ||||
|     "createdAt": "2023-12-01T04:20:00", | ||||
|     "createdBy": "David", | ||||
|     "deployment": "demo.passkeys.xyz", | ||||
|     "source": "dev/style-page", | ||||
|     "latestCommit": { | ||||
|       "message": "hello world", | ||||
|       "createdAt": "2023-12-01T04:20:00", | ||||
|       "branch": "main" | ||||
|     }, | ||||
|     "repositoryId": 1, | ||||
|     "members": [ | ||||
|       { | ||||
|         "id": 1, | ||||
|         "permissions": [] | ||||
|       }, | ||||
|       { | ||||
|         "id": 2, | ||||
|         "permissions": ["view", "edit"] | ||||
|       }, | ||||
|       { | ||||
|         "id": 3, | ||||
|         "permissions": ["view"] | ||||
|       } | ||||
|     ], | ||||
|     "ownerId": 1 | ||||
|   }, | ||||
|   { | ||||
|     "id": 5, | ||||
|     "icon": "^", | ||||
|     "name": "iglootools", | ||||
|     "title": "Iglootools", | ||||
|     "domain": null, | ||||
|     "organization": "Airfoil", | ||||
|     "url": "iglootools.xyz", | ||||
|     "createdAt": "2023-12-11T04:20:00", | ||||
|     "createdBy": "Erin", | ||||
|     "deployment": "staging.snowballtools.com", | ||||
|     "source": "prod/fix-error", | ||||
|     "latestCommit": { | ||||
|       "message": "404 added", | ||||
|       "createdAt": "2023-12-09T04:20:00", | ||||
|       "branch": "main" | ||||
|     }, | ||||
|     "repositoryId": 1, | ||||
|     "members": [ | ||||
|       { | ||||
|         "id": 3, | ||||
|         "permissions": [] | ||||
|       } | ||||
|     ], | ||||
|     "ownerId": 3 | ||||
|   }, | ||||
|   { | ||||
|     "id": 6, | ||||
|     "icon": "^", | ||||
|     "name": "iglootools", | ||||
|     "title": "Iglootools", | ||||
|     "domain": null, | ||||
|     "organization": "Airfoil", | ||||
|     "url": "iglootools.xyz", | ||||
|     "createdAt": "2023-12-11T04:20:00", | ||||
|     "createdBy": "Frank", | ||||
|     "deployment": "iglootools.snowballtools.com", | ||||
|     "source": "prod/fix-error", | ||||
|     "latestCommit": { | ||||
|       "message": "design system integrated", | ||||
|       "createdAt": "2023-12-09T04:20:00", | ||||
|       "branch": "prod" | ||||
|     }, | ||||
|     "repositoryId": 1, | ||||
|     "members": [ | ||||
|       { | ||||
|         "id": 2, | ||||
|         "permissions": [] | ||||
|       }, | ||||
|       { | ||||
|         "id": 3, | ||||
|         "permissions": ["view"] | ||||
|       } | ||||
|     ], | ||||
|     "ownerId": 2 | ||||
|   } | ||||
| ] | ||||
| @ -122,11 +122,7 @@ const DeploymentDetailsCard = ({ | ||||
|             <button className="self-start">...</button> | ||||
|           </MenuHandler> | ||||
|           <MenuList> | ||||
|             <a | ||||
|               href={'https://' + deployment.url} | ||||
|               target="_blank" | ||||
|               rel="noreferrer" | ||||
|             > | ||||
|             <a href={deployment.url} target="_blank" rel="noreferrer"> | ||||
|               <MenuItem disabled={!Boolean(deployment.url)}>^ Visit</MenuItem> | ||||
|             </a> | ||||
|             <MenuItem | ||||
|  | ||||
| @ -66,8 +66,10 @@ const DeploymentsTabPanel = () => { | ||||
| 
 | ||||
|       const dateMatch = | ||||
|         !filterValue.updateAtRange || | ||||
|         (new Date(deployment.updatedAt) >= filterValue.updateAtRange!.from! && | ||||
|           new Date(deployment.updatedAt) <= filterValue.updateAtRange!.to!); | ||||
|         (new Date(Number(deployment.createdAt)) >= | ||||
|           filterValue.updateAtRange!.from! && | ||||
|           new Date(Number(deployment.createdAt)) <= | ||||
|             filterValue.updateAtRange!.to!); | ||||
| 
 | ||||
|       return branchMatch && statusMatch && dateMatch; | ||||
|     }); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user