diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 7f39b67..c24067b 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -201,6 +201,28 @@ export class Database { return savedEnvironmentVariables.length > 0; } + async updateEnvironmentVariable (environmentVariableId: string, update: DeepPartial): Promise { + const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable); + const updateResult = await environmentVariableRepository.update({ id: Number(environmentVariableId) }, update); + + if (updateResult.affected) { + return updateResult.affected > 0; + } else { + return false; + } + } + + async deleteEnvironmentVariable (environmentVariableId: string): Promise { + const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable); + const deleteResult = await environmentVariableRepository.delete({ id: Number(environmentVariableId) }); + + if (deleteResult.affected) { + return deleteResult.affected > 0; + } else { + return false; + } + } + async getProjectMemberByMemberId (memberId: string): Promise { const projectMemberRepository = this.dataSource.getRepository(ProjectMember); diff --git a/packages/backend/src/resolvers.ts b/packages/backend/src/resolvers.ts index e84ce91..2c1a252 100644 --- a/packages/backend/src/resolvers.ts +++ b/packages/backend/src/resolvers.ts @@ -139,6 +139,27 @@ export const createResolvers = async (db: Database, app: OAuthApp): Promise } }, + updateEnvironmentVariable: async (_: any, { environmentVariableId, environmentVariable }: { environmentVariableId: string, environmentVariable : { + key: string + value: string + }}) => { + try { + return db.updateEnvironmentVariable(environmentVariableId, environmentVariable); + } catch (err) { + log(err); + return false; + } + }, + + removeEnvironmentVariable: async (_: any, { environmentVariableId }: { environmentVariableId: string}) => { + try { + return db.deleteEnvironmentVariable(environmentVariableId); + } catch (err) { + log(err); + return false; + } + }, + updateDeploymentToProd: async (_: any, { deploymentId }: { deploymentId: string }) => { try { return db.updateDeploymentById(deploymentId, { diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index b98cd38..25381ca 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -133,6 +133,8 @@ type AuthResult { type Mutation { removeMember(memberId: String!): Boolean! addEnvironmentVariables(projectId: String!, environmentVariables: [AddEnvironmentVariableInput!]): Boolean! + removeEnvironmentVariable(environmentVariableId: String!): Boolean! + updateEnvironmentVariable(environmentVariableId: String!, environmentVariable: UpdateEnvironmentVariableInput!): Boolean! updateDeploymentToProd(deploymentId: String!): Boolean! updateProject(projectId: String!, projectDetails: UpdateProjectInput): Boolean! redeployToProd(deploymentId: String!): Boolean! @@ -163,3 +165,8 @@ input UpdateDomainInput { isRedirected: Boolean branch: String } + +input UpdateEnvironmentVariableInput { + key: String + value: String +} diff --git a/packages/frontend/src/components/projects/project/OverviewTabPanel.tsx b/packages/frontend/src/components/projects/project/OverviewTabPanel.tsx index 8410e17..5473f4c 100644 --- a/packages/frontend/src/components/projects/project/OverviewTabPanel.tsx +++ b/packages/frontend/src/components/projects/project/OverviewTabPanel.tsx @@ -12,7 +12,7 @@ interface OverviewProps { } // TODO: Check if any live domain is set for production branch -const IS_DOMAIN_SETUP = true; +const IS_DOMAIN_SETUP = false; const OverviewTabPanel = ({ project }: OverviewProps) => { return ( diff --git a/packages/frontend/src/components/projects/project/settings/EnvironmentVariablesTabPanel.tsx b/packages/frontend/src/components/projects/project/settings/EnvironmentVariablesTabPanel.tsx index 542daa5..3c5c4fb 100644 --- a/packages/frontend/src/components/projects/project/settings/EnvironmentVariablesTabPanel.tsx +++ b/packages/frontend/src/components/projects/project/settings/EnvironmentVariablesTabPanel.tsx @@ -70,7 +70,7 @@ export const EnvironmentVariablesTabPanel = () => { } }, [isSubmitSuccessful, reset, id]); - const getEnvironmentVariable = useCallback( + const getEnvironmentVariables = useCallback( (environment: Environment) => { return environmentVariables.filter( (item) => item.environment === environment, @@ -226,17 +226,17 @@ export const EnvironmentVariablesTabPanel = () => {
diff --git a/packages/frontend/src/layouts/ProjectSearch.tsx b/packages/frontend/src/layouts/ProjectSearch.tsx index cc35d47..68ae1e7 100644 --- a/packages/frontend/src/layouts/ProjectSearch.tsx +++ b/packages/frontend/src/layouts/ProjectSearch.tsx @@ -51,7 +51,6 @@ const ProjectSearch = () => { ...project, // TODO: populate empty fields icon: '', - title: project.name, organization: orgName, deployments: updatedDeployments, url: '', diff --git a/packages/gql-client/src/client.ts b/packages/gql-client/src/client.ts index 1b1483a..b66c105 100644 --- a/packages/gql-client/src/client.ts +++ b/packages/gql-client/src/client.ts @@ -1,8 +1,8 @@ import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client'; import { getUser, getOrganizations, getDeployments, getProjectMembers, searchProjects, getEnvironmentVariables, getProject, getDomains, getProjectsInOrganization } from './queries'; -import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, RemoveMemberResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse, AddDomainInput, AddDomainResponse, GetDomainsResponse, UpdateDomainInput, UpdateDomainResponse, AuthenticateGithubResponse } from './types'; -import { removeMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, addDomain, rollbackDeployment, updateDomainMutation, authenticateGithub } from './mutations'; +import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, RemoveMemberResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse, AddDomainInput, AddDomainResponse, GetDomainsResponse, UpdateDomainInput, UpdateDomainResponse, AuthenticateGithubResponse, UpdateEnvironmentVariableResponse, UpdateEnvironmentVariableInput, RemoveEnvironmentVariableResponse } from './types'; +import { removeMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, addDomain, rollbackDeployment, updateDomainMutation, authenticateGithub, updateEnvironmentVariable, removeEnvironmentVariable } from './mutations'; export interface GraphQLConfig { gqlEndpoint: string; @@ -136,6 +136,29 @@ export class GQLClient { return data; } + async updateEnvironmentVariable (environmentVariableId: string, environmentVariable: UpdateEnvironmentVariableInput): Promise { + const { data } = await this.client.mutate({ + mutation: updateEnvironmentVariable, + variables: { + environmentVariableId, + environmentVariable + } + }); + + return data; + } + + async removeEnvironmentVariable (environmentVariableId: string): Promise { + const { data } = await this.client.mutate({ + mutation: removeEnvironmentVariable, + variables: { + environmentVariableId + } + }); + + return data; + } + async updateDeploymentToProd (deploymentId: string): Promise { const { data } = await this.client.mutate({ mutation: updateDeploymentToProd, diff --git a/packages/gql-client/src/mutations.ts b/packages/gql-client/src/mutations.ts index 006b488..5551e52 100644 --- a/packages/gql-client/src/mutations.ts +++ b/packages/gql-client/src/mutations.ts @@ -12,6 +12,18 @@ mutation ($projectId: String!, $environmentVariables: [AddEnvironmentVariableInp } `; +export const updateEnvironmentVariable = gql` +mutation ($environmentVariableId: String!, $environmentVariable: UpdateEnvironmentVariableInput!) { + updateEnvironmentVariable(environmentVariableId: $environmentVariableId, environmentVariable: $environmentVariable) +} +`; + +export const removeEnvironmentVariable = gql` +mutation ($environmentVariableId: String!) { + removeEnvironmentVariable(environmentVariableId: $environmentVariableId) +} +`; + export const updateDeploymentToProd = gql` mutation ($deploymentId: String!) { updateDeploymentToProd(deploymentId: $deploymentId) diff --git a/packages/gql-client/src/types.ts b/packages/gql-client/src/types.ts index e47a1a3..e8cb30d 100644 --- a/packages/gql-client/src/types.ts +++ b/packages/gql-client/src/types.ts @@ -180,6 +180,19 @@ export type AddEnvironmentVariableInput = { value: string; } +export type UpdateEnvironmentVariableInput = { + key: string; + value: string; +} + +export type UpdateEnvironmentVariableResponse = { + updateEnvironmentVariable: boolean; +} + +export type RemoveEnvironmentVariableResponse = { + removeEnvironmentVariable: boolean; +} + export type UpdateDeploymentToProdResponse = { updateDeploymentToProd: boolean; }