forked from cerc-io/snowballtools-base
Add GQL mutation for rollback deployment (#46)
* Show project owner in member tab panel * Implement mutation for rollback deployment * Fix project members count --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
1ae1564878
commit
8c38d4788e
@ -303,4 +303,18 @@ export class Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async rollbackDeploymentById (projectId: string, deploymentId: string): Promise<boolean> {
|
||||||
|
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||||
|
|
||||||
|
// TODO: Implement transactions
|
||||||
|
const oldCurrentDeploymentUpdate = await deploymentRepository.update({ project: { id: projectId }, isCurrent: true }, { isCurrent: false });
|
||||||
|
const newCurrentDeploymentUpdate = await deploymentRepository.update({ id: Number(deploymentId) }, { isCurrent: true });
|
||||||
|
|
||||||
|
if (oldCurrentDeploymentUpdate.affected && newCurrentDeploymentUpdate.affected) {
|
||||||
|
return oldCurrentDeploymentUpdate.affected > 0 && newCurrentDeploymentUpdate.affected > 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,15 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
|||||||
log(err);
|
log(err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
rollbackDeployment: async (_: any, { projectId, deploymentId }: {deploymentId: string, projectId: string }) => {
|
||||||
|
try {
|
||||||
|
return db.rollbackDeploymentById(projectId, deploymentId);
|
||||||
|
} catch (err) {
|
||||||
|
log(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -131,6 +131,7 @@ type Mutation {
|
|||||||
updateProject(projectId: String!, updateProject: UpdateProjectInput): Boolean!
|
updateProject(projectId: String!, updateProject: UpdateProjectInput): Boolean!
|
||||||
redeployToProd(deploymentId: String!): Boolean!
|
redeployToProd(deploymentId: String!): Boolean!
|
||||||
deleteProject(projectId: String!): Boolean!
|
deleteProject(projectId: String!): Boolean!
|
||||||
|
rollbackDeployment(projectId: String!, deploymentId: String!): Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
input AddEnvironmentVariableInput {
|
input AddEnvironmentVariableInput {
|
||||||
|
10
packages/backend/test/fixtures/deployments.json
vendored
10
packages/backend/test/fixtures/deployments.json
vendored
@ -29,6 +29,16 @@
|
|||||||
"branch": "prod",
|
"branch": "prod",
|
||||||
"commitHash": "testXyz"
|
"commitHash": "testXyz"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"projectIndex": 0,
|
||||||
|
"domainIndex": null,
|
||||||
|
"title": "nextjs-boilerplate-4",
|
||||||
|
"status": "Ready",
|
||||||
|
"environment": "Production",
|
||||||
|
"isCurrent": false,
|
||||||
|
"branch": "prod",
|
||||||
|
"commitHash": "testXyz"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 1,
|
"projectIndex": 1,
|
||||||
"domainIndex":3,
|
"domainIndex":3,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useOutletContext, useParams } from 'react-router-dom';
|
import { useOutletContext, useParams } from 'react-router-dom';
|
||||||
import toast, { Toaster } from 'react-hot-toast';
|
import toast, { Toaster } from 'react-hot-toast';
|
||||||
|
import { Project } from 'gql-client';
|
||||||
|
|
||||||
import { Chip, Button, Typography } from '@material-tailwind/react';
|
import { Chip, Button, Typography } from '@material-tailwind/react';
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ import { useGQLClient } from '../../../../context/GQLClientContext';
|
|||||||
|
|
||||||
const FIRST_MEMBER_CARD = 0;
|
const FIRST_MEMBER_CARD = 0;
|
||||||
|
|
||||||
const MembersTabPanel = () => {
|
const MembersTabPanel = ({ project }: { project: Project }) => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const client = useGQLClient();
|
const client = useGQLClient();
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ const MembersTabPanel = () => {
|
|||||||
<Chip
|
<Chip
|
||||||
className="normal-case ml-3 font-normal"
|
className="normal-case ml-3 font-normal"
|
||||||
size="sm"
|
size="sm"
|
||||||
value={projectMembers.length}
|
value={projectMembers.length + 1}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -82,6 +83,15 @@ const MembersTabPanel = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<MemberCard
|
||||||
|
member={project.owner}
|
||||||
|
isFirstCard={true}
|
||||||
|
isOwner={true}
|
||||||
|
isPending={false}
|
||||||
|
permissions={[]}
|
||||||
|
handleDeletePendingMember={() => {}}
|
||||||
|
removeMemberHandler={async () => {}}
|
||||||
|
/>
|
||||||
{projectMembers.map((projectMember, index) => {
|
{projectMembers.map((projectMember, index) => {
|
||||||
return (
|
return (
|
||||||
<MemberCard
|
<MemberCard
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
||||||
|
|
||||||
import { getUser, getOrganizations, getDeployments, getProjectMembers, searchProjects, getEnvironmentVariables, getProject, getProjectsInOrganization } from './queries';
|
import { getUser, getOrganizations, getDeployments, getProjectMembers, searchProjects, getEnvironmentVariables, getProject, getProjectsInOrganization } from './queries';
|
||||||
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, RemoveMemberResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse } from './types';
|
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, RemoveMemberResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse } from './types';
|
||||||
import { removeMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject } from './mutations';
|
import { removeMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, rollbackDeployment } from './mutations';
|
||||||
|
|
||||||
export interface GraphQLConfig {
|
export interface GraphQLConfig {
|
||||||
gqlEndpoint: string;
|
gqlEndpoint: string;
|
||||||
@ -180,4 +180,16 @@ export class GQLClient {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async rollbackDeployment (projectId: string, deploymentId: string): Promise<RollbackDeploymentResponse> {
|
||||||
|
const { data } = await this.client.mutate({
|
||||||
|
mutation: rollbackDeployment,
|
||||||
|
variables: {
|
||||||
|
projectId,
|
||||||
|
deploymentId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,3 +34,9 @@ mutation ($projectId: String!) {
|
|||||||
deleteProject(projectId: $projectId)
|
deleteProject(projectId: $projectId)
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const rollbackDeployment = gql`
|
||||||
|
mutation ($projectId: String! ,$deploymentId: String!) {
|
||||||
|
rollbackDeployment(proejctId: $projectId, deploymentId: $deploymentId)
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
@ -195,3 +195,7 @@ export type UpdateProjectInput = {
|
|||||||
export type RedeployToProdResponse = {
|
export type RedeployToProdResponse = {
|
||||||
redeployToProd: boolean
|
redeployToProd: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type RollbackDeploymentResponse = {
|
||||||
|
rollbackDeployment: boolean
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user