Set project name for repository organization and name (#57)

* Remove unused methods from backend utils

* Set project name from repo organization and name when creating project

* Rename success and project components according to routes
This commit is contained in:
Nabarun Gogoi 2024-02-06 16:18:29 +05:30 committed by GitHub
parent afd522654c
commit c0cee2c57f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 22 additions and 92 deletions

View File

@ -132,10 +132,9 @@ export const createResolvers = async (db: Database, app: OAuthApp, service: Serv
addProject: async (_: any, { data }: { data: DeepPartial<Project> }, context: any) => { addProject: async (_: any, { data }: { data: DeepPartial<Project> }, context: any) => {
try { try {
return Boolean(await service.addProject(context.userId, data)); return service.addProject(context.userId, data);
} catch (err) { } catch (err) {
log(err); log(err);
return false;
} }
}, },

View File

@ -192,7 +192,7 @@ type Mutation {
updateEnvironmentVariable(environmentVariableId: String!, data: UpdateEnvironmentVariableInput!): Boolean! updateEnvironmentVariable(environmentVariableId: String!, data: UpdateEnvironmentVariableInput!): Boolean!
removeEnvironmentVariable(environmentVariableId: String!): Boolean! removeEnvironmentVariable(environmentVariableId: String!): Boolean!
updateDeploymentToProd(deploymentId: String!): Boolean! updateDeploymentToProd(deploymentId: String!): Boolean!
addProject(data: AddProjectInput): Boolean! addProject(data: AddProjectInput): Project!
updateProject(projectId: String!, projectDetails: UpdateProjectInput): Boolean! updateProject(projectId: String!, projectDetails: UpdateProjectInput): Boolean!
redeployToProd(deploymentId: String!): Boolean! redeployToProd(deploymentId: String!): Boolean!
deleteProject(projectId: String!): Boolean! deleteProject(projectId: String!): Boolean!

View File

@ -11,7 +11,6 @@ import { Organization } from './entity/Organization';
import { Project } from './entity/Project'; import { Project } from './entity/Project';
import { Permission, ProjectMember } from './entity/ProjectMember'; import { Permission, ProjectMember } from './entity/ProjectMember';
import { User } from './entity/User'; import { User } from './entity/User';
import { isUserOwner } from './utils';
const nanoid = customAlphabet(lowercase + numbers, 8); const nanoid = customAlphabet(lowercase + numbers, 8);
@ -116,7 +115,7 @@ export class Service {
const memberProject = member.project; const memberProject = member.project;
assert(memberProject); assert(memberProject);
if (isUserOwner(String(userId), String(memberProject.owner.id))) { if (String(userId) === String(memberProject.owner.id)) {
return this.db.removeProjectMemberById(projectMemberId); return this.db.removeProjectMemberById(projectMemberId);
} else { } else {
throw new Error('Invalid operation: not authorized'); throw new Error('Invalid operation: not authorized');
@ -182,7 +181,7 @@ export class Service {
return updateResult; return updateResult;
} }
async addProject (userId: string, data: DeepPartial<Project>): Promise<Project> { async addProject (userId: string, data: DeepPartial<Project>): Promise<Project | undefined> {
return this.db.addProject(userId, data); return this.db.addProject(userId, data);
} }

View File

@ -3,11 +3,6 @@ import path from 'path';
import toml from 'toml'; import toml from 'toml';
import debug from 'debug'; import debug from 'debug';
import { Project } from './entity/Project';
import { ProjectMember } from './entity/ProjectMember';
import { Deployment } from './entity/Deployment';
import { EnvironmentVariable } from './entity/EnvironmentVariable';
const log = debug('snowball:utils'); const log = debug('snowball:utils');
export const getConfig = async <ConfigType>( export const getConfig = async <ConfigType>(
@ -24,66 +19,3 @@ export const getConfig = async <ConfigType>(
return config; return config;
}; };
export const projectToGqlType = (dbProject: Project, projectMembers: ProjectMember[], environmentVariables: EnvironmentVariable[]): any => {
return {
id: dbProject.id,
owner: dbProject.owner,
name: dbProject.name,
repository: dbProject.repository,
prodBranch: dbProject.prodBranch,
description: dbProject.description,
template: dbProject.template,
framework: dbProject.framework,
webhooks: dbProject.webhooks,
members: projectMembers,
environmentVariables: environmentVariables,
createdAt: dbProject.createdAt,
updatedAt: dbProject.updatedAt,
organization: dbProject.organization
};
};
// TODO: Add domain field to deployment
export const deploymentToGqlType = (dbDeployment: Deployment): any => {
return {
id: dbDeployment.id,
domain: dbDeployment.domain,
branch: dbDeployment.branch,
commitHash: dbDeployment.commitHash,
title: dbDeployment.title,
url: dbDeployment.url,
environment: dbDeployment.environment,
isCurrent: dbDeployment.isCurrent,
status: dbDeployment.status,
createdBy: dbDeployment.createdBy,
createdAt: dbDeployment.createdAt,
updatedAt: dbDeployment.updatedAt
};
};
export const projectMemberToGqlType = (dbProjectMember: ProjectMember): any => {
return {
id: dbProjectMember.id,
member: dbProjectMember.member,
isPending: dbProjectMember.isPending,
permissions: dbProjectMember.permissions,
createdAt: dbProjectMember.createdAt,
updatedAt: dbProjectMember.updatedAt
};
};
export const environmentVariableToGqlType = (dbEnvironmentVariable: EnvironmentVariable): any => {
return {
id: dbEnvironmentVariable.id,
environments: dbEnvironmentVariable.environment,
key: dbEnvironmentVariable.key,
value: dbEnvironmentVariable.value,
createdAt: dbEnvironmentVariable.createdAt,
updatedAt: dbEnvironmentVariable.updatedAt
};
};
export const isUserOwner = (userId: string, projectOwnerId: string): boolean => {
return userId === projectOwnerId;
};

View File

@ -8,7 +8,7 @@ import HorizontalLine from '../../components/HorizontalLine';
import ProjectTabs from '../../components/projects/project/ProjectTabs'; import ProjectTabs from '../../components/projects/project/ProjectTabs';
import { useGQLClient } from '../../context/GQLClientContext'; import { useGQLClient } from '../../context/GQLClientContext';
const Project = () => { const Id = () => {
const { id } = useParams(); const { id } = useParams();
const navigate = useNavigate(); const navigate = useNavigate();
const client = useGQLClient(); const client = useGQLClient();
@ -64,4 +64,4 @@ const Project = () => {
); );
}; };
export default Project; export default Id;

View File

@ -39,16 +39,14 @@ const Import = () => {
const { addProject } = await client.addProject({ const { addProject } = await client.addProject({
// TODO: Implement form for setting project name // TODO: Implement form for setting project name
name: gitRepo.name, name: `${gitRepo.owner!.login}-${gitRepo.name}`,
// TODO: Get organization id from context or URL // TODO: Get organization id from context or URL
organizationId: String(1), organizationId: String(1),
prodBranch: gitRepo.default_branch ?? 'main', prodBranch: gitRepo.default_branch ?? 'main',
repository: gitRepo.full_name, repository: gitRepo.full_name,
}); });
if (addProject) { navigate(`/projects/create/success/${addProject.id}`);
navigate('/projects/create/success');
}
}, [client, gitRepo]); }, [client, gitRepo]);
return ( return (

View File

@ -3,7 +3,7 @@ import React from 'react';
import NewProject from './index'; import NewProject from './index';
import CreateWithTemplate from './Template'; import CreateWithTemplate from './Template';
import { templateRoutes } from './template/routes'; import { templateRoutes } from './template/routes';
import Success from './Success'; import Id from './success/Id';
import Import from './Import'; import Import from './Import';
export const createProjectRoutes = [ export const createProjectRoutes = [
@ -17,8 +17,8 @@ export const createProjectRoutes = [
children: templateRoutes, children: templateRoutes,
}, },
{ {
path: 'success', path: 'success/:id',
element: <Success />, element: <Id />,
}, },
{ {
path: 'import', path: 'import',

View File

@ -1,10 +1,10 @@
import React from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { Link, useParams } from 'react-router-dom';
import { Button } from '@material-tailwind/react'; import { Button } from '@material-tailwind/react';
// TODO: Use dynamic route params for fetching project created details const Id = () => {
const Success = () => { const { id } = useParams();
return ( return (
<div className="flex justify-center"> <div className="flex justify-center">
<div className="w-1/2"> <div className="w-1/2">
@ -57,7 +57,7 @@ const Success = () => {
</Link> </Link>
</div> </div>
<div> <div>
<Link to="/projects/1"> <Link to={`/projects/${id}`}>
<Button className="rounded-full" variant="gradient" color="blue"> <Button className="rounded-full" variant="gradient" color="blue">
View project View project
</Button> </Button>
@ -69,4 +69,4 @@ const Success = () => {
); );
}; };
export default Success; export default Id;

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import CreateProject from './Create'; import CreateProject from './Create';
import Project from './Project'; import Id from './Id';
import AddDomain from './id/domain/add'; import AddDomain from './id/domain/add';
import { createProjectRoutes } from './create/routes'; import { createProjectRoutes } from './create/routes';
import { addDomainRoutes } from './id/domain/add/routes'; import { addDomainRoutes } from './id/domain/add/routes';
@ -22,6 +22,6 @@ export const projectsRoutesWithoutSearch = [
export const projectsRoutesWithSearch = [ export const projectsRoutesWithSearch = [
{ {
path: ':id', path: ':id',
element: <Project />, element: <Id />,
}, },
]; ];

View File

@ -44,7 +44,9 @@ mutation ($deploymentId: String!) {
export const addProject = gql` export const addProject = gql`
mutation ($data: AddProjectInput) { mutation ($data: AddProjectInput) {
addProject(data: $data) addProject(data: $data) {
id
}
}`; }`;
export const updateProjectMutation = gql` export const updateProjectMutation = gql`

View File

@ -220,7 +220,7 @@ export type UpdateDeploymentToProdResponse = {
} }
export type AddProjectResponse = { export type AddProjectResponse = {
addProject: boolean addProject: Project
} }
export type UpdateProjectResponse = { export type UpdateProjectResponse = {