From a5e995eaf2cd95100c282645ae3193a9c8147be6 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 1 Oct 2021 09:41:52 +0900 Subject: [PATCH 1/3] Replace params into namespace, and name --- ui/src/apis/approval.ts | 26 +++++++++++++------------- ui/src/apis/branch.ts | 12 ++++++------ ui/src/apis/commit.ts | 12 ++++++------ ui/src/apis/config.ts | 4 ++-- ui/src/apis/deployment.ts | 24 ++++++++++++------------ ui/src/apis/lock.ts | 12 ++++++------ ui/src/apis/perm.ts | 4 ++-- ui/src/apis/repo.ts | 32 ++++++++++++++------------------ ui/src/apis/tag.ts | 12 ++++++------ 9 files changed, 67 insertions(+), 71 deletions(-) diff --git a/ui/src/apis/approval.ts b/ui/src/apis/approval.ts index b2896d24..a51b3d3d 100644 --- a/ui/src/apis/approval.ts +++ b/ui/src/apis/approval.ts @@ -93,8 +93,8 @@ export const searchApprovals = async (statuses: ApprovalStatus[], from?: Date, t return approvals } -export const listApprovals = async (id: string, number: number): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approvals`, { +export const listApprovals = async (namespace: string, name: string, number: number): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approvals`, { credentials: "same-origin", headers, }) @@ -109,11 +109,11 @@ export const listApprovals = async (id: string, number: number): Promise => { +export const createApproval = async (namespace: string, name: string, number: number, userId: number): Promise => { const body = { - user_id: approver.id + user_id: userId } - const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/deployments/${deployment.number}/approvals`, { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approvals`, { credentials: "same-origin", headers, method: "POST", @@ -131,8 +131,8 @@ export const createApproval = async (repo: Repo, deployment: Deployment, approve return approval } -export const deleteApproval = async (repo: Repo, approval: Approval): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/approvals/${approval.id}`, { +export const deleteApproval = async (namespace: string, name: string, id: number): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/approvals/${id}`, { credentials: "same-origin", headers, method: "DELETE", @@ -144,8 +144,8 @@ export const deleteApproval = async (repo: Repo, approval: Approval): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approval`, { +export const getMyApproval = async (namespace: string, name: string, number: number): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, { credentials: "same-origin", headers, }) @@ -159,11 +159,11 @@ export const getMyApproval = async (id: string, number: number): Promise => { +export const setApprovalApproved = async (namespace: string, name: string, number: number): Promise => { const body = { status: ApprovalStatus.Approved.toString(), } - const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approval`, { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, { credentials: "same-origin", headers, method: "PATCH", @@ -179,11 +179,11 @@ export const setApprovalApproved = async (id: string, number: number): Promise => { +export const setApprovalDeclined = async (namespace: string, name: string, number: number): Promise => { const body = { status: ApprovalStatus.Declined.toString(), } - const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approval`, { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, { credentials: "same-origin", headers, method: "PATCH", diff --git a/ui/src/apis/branch.ts b/ui/src/apis/branch.ts index d17868fa..816c2229 100644 --- a/ui/src/apis/branch.ts +++ b/ui/src/apis/branch.ts @@ -16,8 +16,8 @@ const mapDataToBranch = (data: BranchData): Branch => { } } -export const listBranches = async (repoId: string, page = 1, perPage = 30): Promise => { - const branches: Branch[] = await _fetch(`${instance}/api/v1/repos/${repoId}/branches?page=${page}&per_page=${perPage}`, { +export const listBranches = async (namespace: string, name: string, page = 1, perPage = 30): Promise => { + const branches: Branch[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/branches?page=${page}&per_page=${perPage}`, { headers, credentials: "same-origin", }) @@ -27,8 +27,8 @@ export const listBranches = async (repoId: string, page = 1, perPage = 30): Prom return branches } -export const getBranch = async (repoId: string, name: string): Promise => { - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/branches/${name}`, { +export const getBranch = async (namespace: string, name: string, branch: string): Promise => { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/branches/${branch}`, { headers, credentials: "same-origin", }) @@ -37,9 +37,9 @@ export const getBranch = async (repoId: string, name: string): Promise = throw new HttpNotFoundError(message) } - const branch:Branch = await response + const ret:Branch = await response .json() .then((b: BranchData) => mapDataToBranch(b)) - return branch + return ret } \ No newline at end of file diff --git a/ui/src/apis/commit.ts b/ui/src/apis/commit.ts index 7a1c700c..9607e256 100644 --- a/ui/src/apis/commit.ts +++ b/ui/src/apis/commit.ts @@ -63,8 +63,8 @@ const mapStatusState = (state: string) => { return StatusState.Pending } -export const listCommits = async (repoId: string, branch: string, page = 1, perPage = 30): Promise => { - const commits: Commit[] = await _fetch(`${instance}/api/v1/repos/${repoId}/commits?branch=${branch}&page=${page}&per_page=${perPage}`, { +export const listCommits = async (namespace: string, name: string, branch: string, page = 1, perPage = 30): Promise => { + const commits: Commit[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/commits?branch=${branch}&page=${page}&per_page=${perPage}`, { headers, credentials: "same-origin", }) @@ -74,8 +74,8 @@ export const listCommits = async (repoId: string, branch: string, page = 1, perP return commits } -export const getCommit = async (repoId: string, sha: string): Promise => { - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/commits/${sha}`, { +export const getCommit = async (namespace: string, name: string, sha: string): Promise => { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/commits/${sha}`, { headers, credentials: "same-origin", }) @@ -91,8 +91,8 @@ export const getCommit = async (repoId: string, sha: string): Promise => return commit } -export const listStatuses = async (repoId: string, sha: string): Promise<{state: StatusState, statuses: Status[]}> => { - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/commits/${sha}/statuses`, { +export const listStatuses = async (namespace: string, name: string, sha: string): Promise<{state: StatusState, statuses: Status[]}> => { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/commits/${sha}/statuses`, { headers, credentials: "same-origin", }) diff --git a/ui/src/apis/config.ts b/ui/src/apis/config.ts index 180e3705..2eb431f7 100644 --- a/ui/src/apis/config.ts +++ b/ui/src/apis/config.ts @@ -40,8 +40,8 @@ const mapDataToConfig = (data: ConfigData): Config => { } } -export const getConfig = async (repoId: string): Promise => { - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/config`, { +export const getConfig = async (namespace: string, name: string): Promise => { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/config`, { headers, credentials: "same-origin", }) diff --git a/ui/src/apis/deployment.ts b/ui/src/apis/deployment.ts index 492ae64f..c95e1f41 100644 --- a/ui/src/apis/deployment.ts +++ b/ui/src/apis/deployment.ts @@ -169,8 +169,8 @@ export const searchDeployments = async (statuses: DeploymentStatusEnum[], owned: return deployments } -export const listDeployments = async (repoId: string, env: string, status: string, page: number, perPage: number): Promise => { - const deployments: Deployment[] = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments?env=${env}&status=${status}&page=${page}&per_page=${perPage}`, { +export const listDeployments = async (namespace: string, name: string, env: string, status: string, page: number, perPage: number): Promise => { + const deployments: Deployment[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments?env=${env}&status=${status}&page=${page}&per_page=${perPage}`, { headers, credentials: 'same-origin', }) @@ -180,8 +180,8 @@ export const listDeployments = async (repoId: string, env: string, status: strin return deployments } -export const getDeployment = async (id: string, number: number): Promise => { - const deployment = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}`, { +export const getDeployment = async (namespace: string, name: string, number: number): Promise => { + const deployment = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}`, { headers, credentials: 'same-origin', }) @@ -191,13 +191,13 @@ export const getDeployment = async (id: string, number: number): Promise => { +export const createDeployment = async (namespace: string, name: string, type: DeploymentType = DeploymentType.Commit, ref: string, env: string): Promise => { const body = JSON.stringify({ type, ref, env }) - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments`, { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments`, { headers, credentials: 'same-origin', method: "POST", @@ -220,11 +220,11 @@ export const createDeployment = async (repoId: string, type: DeploymentType = De return deployment } -export const updateDeploymentStatusCreated = async (id: string, number: number): Promise => { +export const updateDeploymentStatusCreated = async (namespace: string, name: string, number: number): Promise => { const body = JSON.stringify({ status: "created" }) - const response = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}`, { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}`, { headers, credentials: 'same-origin', method: "PATCH", @@ -244,8 +244,8 @@ export const updateDeploymentStatusCreated = async (id: string, number: number): return deployment } -export const rollbackDeployment = async (repoId: string, number: number): Promise => { - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments/${number}/rollback`, { +export const rollbackDeployment = async (namespace: string, name: string, number: number): Promise => { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/rollback`, { headers, credentials: 'same-origin', method: "POST", @@ -267,8 +267,8 @@ export const rollbackDeployment = async (repoId: string, number: number): Promis return deployment } -export const listDeploymentChanges = async (repoId: string, number: number, page = 1, perPage = 30): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments/${number}/changes?page=${page}&per_page=${perPage}`, { +export const listDeploymentChanges = async (namespace: string, name: string, number: number, page = 1, perPage = 30): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/changes?page=${page}&per_page=${perPage}`, { headers, credentials: 'same-origin', }) diff --git a/ui/src/apis/lock.ts b/ui/src/apis/lock.ts index 34c62b4f..d47a19bd 100644 --- a/ui/src/apis/lock.ts +++ b/ui/src/apis/lock.ts @@ -29,8 +29,8 @@ const mapDataToLock = (data: LockData): Lock => { } } -export const listLocks = async (repo: Repo): Promise => { - const locks = await _fetch(`${instance}/api/v1/repos/${repo.id}/locks`, { +export const listLocks = async (namespace: string, name: string): Promise => { + const locks = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/locks`, { headers, credentials: 'same-origin', }) @@ -40,8 +40,8 @@ export const listLocks = async (repo: Repo): Promise => { return locks } -export const lock = async (repo: Repo, env: string): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/locks`, { +export const lock = async (namespace: string, name: string, env: string): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/locks`, { headers, credentials: 'same-origin', method: "POST", @@ -62,8 +62,8 @@ export const lock = async (repo: Repo, env: string): Promise => { return lock } -export const unlock = async (repo: Repo, lock: Lock): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/locks/${lock.id}`, { +export const unlock = async (namespace: string, name: string, id: number): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/locks/${id}`, { headers, credentials: 'same-origin', method: "DELETE", diff --git a/ui/src/apis/perm.ts b/ui/src/apis/perm.ts index e8a889f3..755d17a0 100644 --- a/ui/src/apis/perm.ts +++ b/ui/src/apis/perm.ts @@ -26,8 +26,8 @@ const mapDataToPerm = (data: PermData): Perm => { } } -export const listPerms = async (repo: Repo, q: string, page = 1, perPage = 30): Promise => { - const perms: Perm[] = await _fetch(`${instance}/api/v1/repos/${repo.id}/perms?q=${q}&page=${page}&per_page=${perPage}`, { +export const listPerms = async (namespace: string, name: string, q: string, page = 1, perPage = 30): Promise => { + const perms: Perm[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/perms?q=${q}&page=${page}&per_page=${perPage}`, { headers, credentials: "same-origin" }) diff --git a/ui/src/apis/repo.ts b/ui/src/apis/repo.ts index 80a5bede..a1000654 100644 --- a/ui/src/apis/repo.ts +++ b/ui/src/apis/repo.ts @@ -70,12 +70,8 @@ export const searchRepo = async (namespace: string, name: string): Promise return repos[0] } -export const updateRepo = async (repo: Repo): Promise => { - const payload = { - "config_path": repo.configPath, - } - - const res = await _fetch(`${instance}/api/v1/repos/${repo.id}`, { +export const updateRepo = async (namespace: string, name: string, payload: {config_path: string}): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}`, { headers, credentials: 'same-origin', method: "PATCH", @@ -93,11 +89,11 @@ export const updateRepo = async (repo: Repo): Promise => { return ret } -export const activateRepo = async (repo: Repo): Promise => { +export const activateRepo = async (namespace: string, name: string): Promise => { const body = { "active": true, } - const response = await _fetch(`${instance}/api/v1/repos/${repo.id}`, { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}`, { headers, credentials: 'same-origin', method: "PATCH", @@ -108,17 +104,17 @@ export const activateRepo = async (repo: Repo): Promise => { throw new HttpForbiddenError(message) } - repo = await response + const repo = await response .json() .then((r:any) => mapDataToRepo(r)) return repo } -export const deactivateRepo = async (repo: Repo): Promise => { +export const deactivateRepo = async (namespace: string, name: string): Promise => { const body = { "active": false, } - const response = await _fetch(`${instance}/api/v1/repos/${repo.id}`, { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}`, { headers, credentials: 'same-origin', method: "PATCH", @@ -129,17 +125,17 @@ export const deactivateRepo = async (repo: Repo): Promise => { throw new HttpForbiddenError(message) } - repo = await response + const repo = await response .json() .then((r:any) => mapDataToRepo(r)) return repo } -export const lockRepo = async (repo: Repo): Promise => { +export const lockRepo = async (namespace: string, name: string): Promise => { const body = { "locked": true, } - const response = await _fetch(`${instance}/api/v1/repos/${repo.id}`, { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}`, { headers, credentials: 'same-origin', method: "PATCH", @@ -150,17 +146,17 @@ export const lockRepo = async (repo: Repo): Promise => { throw new HttpForbiddenError(message) } - repo = await response + const repo = await response .json() .then((r:any) => mapDataToRepo(r)) return repo } -export const unlockRepo = async (repo: Repo): Promise => { +export const unlockRepo = async (namespace: string, name: string): Promise => { const body = { "locked": false, } - const response = await _fetch(`${instance}/api/v1/repos/${repo.id}`, { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}`, { headers, credentials: 'same-origin', method: "PATCH", @@ -171,7 +167,7 @@ export const unlockRepo = async (repo: Repo): Promise => { throw new HttpForbiddenError(message) } - repo = await response + const repo = await response .json() .then((r:any) => mapDataToRepo(r)) return repo diff --git a/ui/src/apis/tag.ts b/ui/src/apis/tag.ts index 03b27290..716273cc 100644 --- a/ui/src/apis/tag.ts +++ b/ui/src/apis/tag.ts @@ -4,8 +4,8 @@ import { instance, headers } from './setting' import { _fetch } from "./_base" import { Tag, HttpNotFoundError } from '../models' -export const listTags = async (repoId: string, page = 1, perPage = 30): Promise => { - const tags: Tag[] = await _fetch(`${instance}/api/v1/repos/${repoId}/tags?page=${page}&per_page=${perPage}`, { +export const listTags = async (namespace: string, name: string, page = 1, perPage = 30): Promise => { + const tags: Tag[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/tags?page=${page}&per_page=${perPage}`, { headers, credentials: "same-origin", }) @@ -20,8 +20,8 @@ export const listTags = async (repoId: string, page = 1, perPage = 30): Promise< return tags } -export const getTag = async (repoId: string, name: string): Promise => { - const response = await _fetch(`${instance}/api/v1/repos/${repoId}/tags/${name}`, { +export const getTag = async (namespace: string, name: string, tag: string): Promise => { + const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/tags/${tag}`, { headers, credentials: "same-origin", }) @@ -30,11 +30,11 @@ export const getTag = async (repoId: string, name: string): Promise => { throw new HttpNotFoundError(message) } - const tag:Tag = await response + const ret: Tag = await response .json() .then(t => ({ name: t.name, commitSha: t.commit_sha, })) - return tag + return ret } \ No newline at end of file From 34af0094f404c0d66f9cf5191bd56824e97d1741 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 1 Oct 2021 10:47:45 +0900 Subject: [PATCH 2/3] Update state of redux --- ui/src/apis/approval.ts | 3 +- ui/src/apis/index.ts | 4 +- ui/src/apis/lock.ts | 2 +- ui/src/apis/perm.ts | 2 +- ui/src/apis/repo.ts | 12 ++-- ui/src/redux/deployment.tsx | 108 ++++++++++-------------------- ui/src/redux/repo.ts | 13 ++-- ui/src/redux/repoDeploy.tsx | 121 +++++++++++++++------------------- ui/src/redux/repoHome.ts | 50 +++++--------- ui/src/redux/repoLock.ts | 54 +++++---------- ui/src/redux/repoRollback.tsx | 59 +++++++---------- ui/src/redux/repoSettings.ts | 8 +-- ui/src/views/Deployment.tsx | 29 ++++++-- ui/src/views/RepoDeploy.tsx | 8 +-- ui/src/views/RepoHome.tsx | 4 +- ui/src/views/RepoLock.tsx | 10 +-- ui/src/views/RepoRollback.tsx | 11 ++-- 17 files changed, 203 insertions(+), 295 deletions(-) diff --git a/ui/src/apis/approval.ts b/ui/src/apis/approval.ts index a51b3d3d..de434a38 100644 --- a/ui/src/apis/approval.ts +++ b/ui/src/apis/approval.ts @@ -5,7 +5,6 @@ import { _fetch } from "./_base" import { UserData, mapDataToUser } from "./user" import { DeploymentData, mapDataToDeployment } from "./deployment" import { - Repo, User, Deployment, Approval, @@ -109,7 +108,7 @@ export const listApprovals = async (namespace: string, name: string, number: num return approvals } -export const createApproval = async (namespace: string, name: string, number: number, userId: number): Promise => { +export const createApproval = async (namespace: string, name: string, number: number, userId: string): Promise => { const body = { user_id: userId } diff --git a/ui/src/apis/index.ts b/ui/src/apis/index.ts index e96e6ec7..85efbc5f 100644 --- a/ui/src/apis/index.ts +++ b/ui/src/apis/index.ts @@ -1,7 +1,7 @@ import { sync } from "./sync" import { listRepos, - searchRepo, + getRepo, updateRepo, activateRepo, deactivateRepo, @@ -44,7 +44,7 @@ import { subscribeEvents } from "./events" export { sync, listRepos, - searchRepo, + getRepo, updateRepo, activateRepo, deactivateRepo, diff --git a/ui/src/apis/lock.ts b/ui/src/apis/lock.ts index d47a19bd..993a0d89 100644 --- a/ui/src/apis/lock.ts +++ b/ui/src/apis/lock.ts @@ -3,7 +3,7 @@ import { StatusCodes } from "http-status-codes" import { instance, headers } from "./setting" import { _fetch } from "./_base" import { UserData, mapDataToUser } from "./user" -import { Repo, Lock, User, HttpForbiddenError, HttpUnprocessableEntityError } from "../models" +import { Lock, User, HttpForbiddenError, HttpUnprocessableEntityError } from "../models" interface LockData { id: number diff --git a/ui/src/apis/perm.ts b/ui/src/apis/perm.ts index 755d17a0..db152a71 100644 --- a/ui/src/apis/perm.ts +++ b/ui/src/apis/perm.ts @@ -2,7 +2,7 @@ import { instance, headers } from './setting' import { _fetch } from "./_base" import { mapDataToUser, UserData } from "./user" import { mapDataToRepo, RepoData } from "./repo" -import { Repo, Perm } from '../models' +import { Perm } from '../models' interface PermData{ repo_perm: string diff --git a/ui/src/apis/repo.ts b/ui/src/apis/repo.ts index a1000654..77ab68aa 100644 --- a/ui/src/apis/repo.ts +++ b/ui/src/apis/repo.ts @@ -55,19 +55,15 @@ export const listRepos = async (q: string, page = 1, perPage = 30): Promise => { - const repos: Repo[] = await _fetch(`${instance}/api/v1/repos?namespace=${namespace}&name=${name}`, { +export const getRepo = async (namespace: string, name: string): Promise => { + const repo: Repo = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}`, { headers, credentials: 'same-origin', }) .then(response => response.json()) - .then(repos => repos.map((r: any): Repo => (mapDataToRepo(r)))) - - if (repos.length !== 1) { - throw new Error(`It has failed to search the repository. The length is ${repos.length}.`) - } + .then(repo => mapDataToRepo(repo)) - return repos[0] + return repo } export const updateRepo = async (namespace: string, name: string, payload: {config_path: string}): Promise => { diff --git a/ui/src/redux/deployment.tsx b/ui/src/redux/deployment.tsx index 96352517..b9333d43 100644 --- a/ui/src/redux/deployment.tsx +++ b/ui/src/redux/deployment.tsx @@ -3,7 +3,6 @@ import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit' import { User, - Repo, Deployment, Commit, Approval, @@ -14,7 +13,6 @@ import { HttpUnprocessableEntityError, } from "../models" import { - searchRepo, getDeployment, updateDeploymentStatusCreated, listPerms, @@ -28,7 +26,9 @@ import { } from "../apis" interface DeploymentState { - repo?: Repo + display: boolean + namespace: string + name: string number: number deployment?: Deployment changes: Commit[] @@ -43,6 +43,9 @@ interface DeploymentState { } const initialState: DeploymentState = { + display: false, + namespace: "", + name: "", number: 0, changes: [], deploying: RequestStatus.Idle, @@ -51,27 +54,13 @@ const initialState: DeploymentState = { candidates: [], } -export const init = createAsyncThunk( - 'deployment/init', - async (params, {rejectWithValue}) => { - try { - const repo = await searchRepo(params.namespace, params.name) - return repo - } catch (e) { - console.log(e) - return rejectWithValue(e) - } - }, -) - export const fetchDeployment = createAsyncThunk( 'deployment/fetchDeployment', async (_, { getState, rejectWithValue } ) => { - const { repo, number } = getState().deployment - if (!repo) throw new Error("There is no repo.") + const { namespace, name, number } = getState().deployment try { - const deployment = await getDeployment(repo.id, number) + const deployment = await getDeployment(namespace, name, number) return deployment } catch(e) { return rejectWithValue(e) @@ -82,11 +71,10 @@ export const fetchDeployment = createAsyncThunk( 'deployment/fetchDeploymentChanges', async (_, { getState, rejectWithValue } ) => { - const { repo, number } = getState().deployment - if (!repo) throw new Error("There is no repo.") + const { namespace, name, number } = getState().deployment try { - const commits = await listDeploymentChanges(repo.id, number) + const commits = await listDeploymentChanges(namespace, name, number) return commits } catch(e) { return rejectWithValue(e) @@ -97,17 +85,14 @@ export const fetchDeploymentChanges = createAsyncThunk( 'deployment/deployToSCM', async (_, { getState, rejectWithValue, requestId } ) => { - const { repo, number, deploying, deployId } = getState().deployment - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name, number, deploying, deployId } = getState().deployment if (deploying !== RequestStatus.Pending || requestId !== deployId ) { throw new Error("The previous action is not finished.") } try { - const deployment = await updateDeploymentStatusCreated(repo.id, number) + const deployment = await updateDeploymentStatusCreated(namespace, name, number) message.info(`Deploy successfully.`, 3) return deployment @@ -130,11 +115,10 @@ export const deployToSCM = createAsyncThunk( 'deployment/fetchApprovals', async (_, { getState, rejectWithValue } ) => { - const { repo, number } = getState().deployment - if (!repo) throw new Error("There is no repo.") + const { namespace, name, number } = getState().deployment try { - const approvals = await listApprovals(repo.id, number) + const approvals = await listApprovals(namespace, name, number) return approvals } catch(e) { return rejectWithValue(e) @@ -145,13 +129,10 @@ export const fetchApprovals = createAsyncThunk( "deployment/fetchCandidates", async (q, { getState, rejectWithValue }) => { - const { repo } = getState().deployment - if (!repo) { - throw new Error("The repo is not set.") - } + const { namespace, name } = getState().deployment try { - const perms = await listPerms(repo, q) + const perms = await listPerms(namespace, name, q) const candidates = perms.map((p) => { return p.user }) @@ -165,16 +146,10 @@ export const searchCandidates = createAsyncThunk( "deployment/createApprover", async (candidate, { getState, rejectWithValue }) => { - const { repo, deployment } = getState().deployment - if (!repo) { - throw new Error("The repo is not set.") - } - if (!deployment) { - throw new Error("The deployment is not set.") - } + const { namespace, name, number } = getState().deployment try { - const approval = await _createApproval(repo, deployment, candidate) + const approval = await _createApproval(namespace, name, number, candidate.id) return approval } catch(e) { return rejectWithValue(e) @@ -186,13 +161,10 @@ export const createApproval = createAsyncThunk( "deployment/deleteApprover", async (approval, { getState, rejectWithValue }) => { - const { repo } = getState().deployment - if (!repo) { - throw new Error("The repo is not set.") - } + const { namespace, name } = getState().deployment try { - await _deleteApproval(repo, approval) + await _deleteApproval(namespace, name, approval.id) return approval } catch(e) { return rejectWithValue(e) @@ -203,11 +175,10 @@ export const deleteApproval = createAsyncThunk( 'deployment/fetchMyApproval', async (_, { getState, rejectWithValue } ) => { - const { repo, number } = getState().deployment - if (!repo) throw new Error("There is no repo.") + const { namespace, name, number } = getState().deployment try { - const approval = await getMyApproval(repo.id, number) + const approval = await getMyApproval(namespace, name, number) return approval } catch(e) { if (e instanceof HttpNotFoundError ) { @@ -222,11 +193,10 @@ export const fetchMyApproval = createAsyncThunk( 'deployment/approve', async (_, { getState, rejectWithValue } ) => { - const { repo, number } = getState().deployment - if (!repo) throw new Error("There is no repo.") + const { namespace, name, number } = getState().deployment try { - const approval = await setApprovalApproved(repo.id, number) + const approval = await setApprovalApproved(namespace, name, number) return approval } catch(e) { return rejectWithValue(e) @@ -237,11 +207,10 @@ export const approve = createAsyncThunk( 'deployment/decline', async (_, { getState, rejectWithValue } ) => { - const { repo, number } = getState().deployment - if (!repo) throw new Error("There is no repo.") + const { namespace, name, number } = getState().deployment try { - const approval = await setApprovalDeclined(repo.id, number) + const approval = await setApprovalDeclined(namespace, name, number) return approval } catch(e) { return rejectWithValue(e) @@ -253,8 +222,13 @@ export const deploymentSlice = createSlice({ name: "deployment", initialState, reducers: { - setNumber: (state, action: PayloadAction) => { - state.number = action.payload + init: (state, action: PayloadAction<{namespace: string, name: string, number: number}>) => { + state.namespace = action.payload.namespace + state.name = action.payload.name + state.number = action.payload.number + }, + setDisplay: (state, action: PayloadAction) => { + state.display = action.payload }, handleDeploymentEvent: (state, action: PayloadAction) => { const event = action.payload @@ -268,59 +242,44 @@ export const deploymentSlice = createSlice({ }, extraReducers: builder => { builder - .addCase(init.fulfilled, (state, action) => { - state.repo = action.payload - }) - .addCase(fetchDeployment.fulfilled, (state, action) => { state.deployment = action.payload }) - .addCase(fetchDeploymentChanges.fulfilled, (state, action) => { state.changes = action.payload }) - .addCase(deployToSCM.pending, (state, action) => { if (state.deploying === RequestStatus.Idle) { state.deploying = RequestStatus.Pending state.deployId = action.meta.requestId } }) - .addCase(deployToSCM.fulfilled, (state, action) => { state.deployment = action.payload state.deploying = RequestStatus.Idle }) - .addCase(deployToSCM.rejected, (state) => { state.deploying = RequestStatus.Idle }) - .addCase(fetchApprovals.fulfilled, (state, action) => { state.approvals = action.payload }) - .addCase(searchCandidates.pending, (state) => { state.candidates = [] }) - .addCase(searchCandidates.fulfilled, (state, action) => { state.candidates = action.payload }) - .addCase(createApproval.fulfilled, (state, action) => { state.approvals.push(action.payload) }) - .addCase(deleteApproval.fulfilled, (state, action) => { const approval = action.payload state.approvals = state.approvals.filter(a => a.id !== approval.id) }) - .addCase(fetchMyApproval.fulfilled, (state, action) => { state.myApproval = action.payload }) - .addCase(approve.fulfilled, (state, action) => { const myApproval = action.payload state.myApproval = myApproval @@ -331,7 +290,6 @@ export const deploymentSlice = createSlice({ return approval }) }) - .addCase(decline.fulfilled, (state, action) => { const myApproval = action.payload state.myApproval = myApproval diff --git a/ui/src/redux/repo.ts b/ui/src/redux/repo.ts index 6bb1d19d..ab4e47e2 100644 --- a/ui/src/redux/repo.ts +++ b/ui/src/redux/repo.ts @@ -1,7 +1,7 @@ import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit' import { message } from "antd" -import { searchRepo, activateRepo } from "../apis/repo" +import { getRepo, activateRepo } from "../apis/repo" import { Repo, RequestStatus } from "../models" import { HttpForbiddenError } from '../models/errors' @@ -20,7 +20,7 @@ export const init = createAsyncThunk { try { - const repo = await searchRepo(params.namespace, params.name) + const repo = await getRepo(params.namespace, params.name) return repo } catch (e) { console.log(e) @@ -33,11 +33,14 @@ export const activate = createAsyncThunk { const { repo } = getState().repo - if (!repo) throw new Error("There is no repo.") + + if (!repo) { + throw new Error("The repo is undefined.") + } try { - const nr = await activateRepo(repo) - return nr + const ret = await activateRepo(repo.namespace, repo.name) + return ret } catch(e) { if (e instanceof HttpForbiddenError) { message.warn("Only admin permission can activate.", 3) diff --git a/ui/src/redux/repoDeploy.tsx b/ui/src/redux/repoDeploy.tsx index db32c75f..21c1f0f6 100644 --- a/ui/src/redux/repoDeploy.tsx +++ b/ui/src/redux/repoDeploy.tsx @@ -3,7 +3,6 @@ import { message } from "antd" import { User, - Repo, Deployment, Branch, Commit, @@ -19,7 +18,6 @@ import { HttpUnprocessableEntityError } from '../models' import { - searchRepo, listPerms, getConfig, listDeployments, @@ -40,7 +38,8 @@ const perPage = 100 interface RepoDeployState { display: boolean - repo?: Repo + namespace: string + name: string config?: Config env?: Env envs: Env[] @@ -68,6 +67,8 @@ interface RepoDeployState { const initialState: RepoDeployState = { display: false, + namespace: "", + name: "", envs: [], branchStatuses: [], branches: [], @@ -81,22 +82,13 @@ const initialState: RepoDeployState = { deployId: "", } -export const init = createAsyncThunk( - 'repoDeploy/init', - async (params) => { - const repo = await searchRepo(params.namespace, params.name) - return repo - }, -) - export const fetchConfig = createAsyncThunk( "repoDeploy/fetchConfig", async (_, { getState, rejectWithValue } ) => { - const { repo } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + const { namespace, name } = getState().repoDeploy try { - const config = await getConfig(repo.id) + const config = await getConfig(namespace, name) return config } catch (e) { return rejectWithValue(e) @@ -107,13 +99,10 @@ export const fetchConfig = createAsyncThunk( "repoDeploy/fetchCurrentDeployment", async (env, { getState, rejectWithValue } ) => { - const { repo } = getState().repoDeploy - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name } = getState().repoDeploy try { - const deployments = await listDeployments(repo.id, env.name, "success", 1, 1) + const deployments = await listDeployments(namespace, name, env.name, "success", 1, 1) return (deployments.length > 0)? deployments[0] : null } catch (e) { return rejectWithValue(e) @@ -124,10 +113,9 @@ export const fetchCurrentDeploymentOfEnv = createAsyncThunk( "repoDeploy/fetchBranches", async (_, { getState }) => { - const { repo } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + const { namespace, name } = getState().repoDeploy - const branches = await listBranches(repo.id, firstPage, perPage) + const branches = await listBranches(namespace, name, firstPage, perPage) return branches } ) @@ -135,22 +123,23 @@ export const fetchBranches = createAsyncThunk( "repoDeploy/checkBranch", async (_, { getState }) => { - const { repo, branch } = getState().repoDeploy - if (!repo || !branch) throw new Error("The repo and branch are not set.") + const { namespace, name, branch } = getState().repoDeploy + if (!branch) { + throw new Error("The branch is undefined.") + } - const { statuses } = await listStatuses(repo.id, branch.commitSha) + const { statuses } = await listStatuses(namespace, name, branch.commitSha) return statuses } ) export const addBranchManually = createAsyncThunk( "repoDeploy/addBranchManually", - async (name: string, { getState, rejectWithValue }) => { - const { repo } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + async (brnach: string, { getState, rejectWithValue }) => { + const { namespace, name } = getState().repoDeploy try { - const branch = await getBranch(repo.id, name) + const branch = await getBranch(namespace, name, brnach) return branch } catch(e) { if (e instanceof HttpNotFoundError) { @@ -165,11 +154,10 @@ export const addBranchManually = createAsyncThunk( "repoDeploy/fetchCommits", async (_, { getState }) => { - const { repo, branch } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + const { namespace, name, branch } = getState().repoDeploy - const name = (branch)? branch.name : "" - const commits = await listCommits(repo.id, name, firstPage, perPage) + const branchName = (branch)? branch.name : "" + const commits = await listCommits(namespace, name, branchName, firstPage, perPage) return commits } ) @@ -177,10 +165,13 @@ export const fetchCommits = createAsyncThunk( "repoDeploy/checkCommit", async (_, { getState }) => { - const { repo, commit } = getState().repoDeploy - if (!repo || !commit) throw new Error("The repo and commit are not set.") + const { namespace, name, commit } = getState().repoDeploy + + if (!commit) { + throw new Error("The commit is undefined.") + } - const { statuses } = await listStatuses(repo.id, commit.sha) + const { statuses } = await listStatuses(namespace, name, commit.sha) return statuses } ) @@ -188,11 +179,10 @@ export const checkCommit = createAsyncThunk( "repoDeploy/addCommitManually", async (sha: string, { getState, rejectWithValue }) => { - const { repo } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + const { namespace, name } = getState().repoDeploy try { - const commit = await getCommit(repo.id, sha) + const commit = await getCommit(namespace, name, sha) return commit } catch(e) { if (e instanceof HttpNotFoundError) { @@ -207,10 +197,9 @@ export const addCommitManually = createAsyncThunk( "repoDeploy/fetchTags", async (_, { getState }) => { - const { repo } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + const { namespace, name } = getState().repoDeploy - const tags = await listTags(repo.id, firstPage, perPage) + const tags = await listTags(namespace, name, firstPage, perPage) return tags } ) @@ -218,22 +207,24 @@ export const fetchTags = createAsyncThunk( "repoDeploy/checkTag", async (_, { getState }) => { - const { repo, tag } = getState().repoDeploy - if (!repo || !tag) throw new Error("The repo and tag are not set.") + const { namespace, name, tag } = getState().repoDeploy - const { statuses } = await listStatuses(repo.id, tag.commitSha) + if (!tag) { + throw new Error("The tag is undefined.") + } + + const { statuses } = await listStatuses(namespace, name, tag.commitSha) return statuses } ) export const addTagManually = createAsyncThunk( "repoDeploy/addTagManually", - async (name: string, { getState, rejectWithValue }) => { - const { repo } = getState().repoDeploy - if (!repo) throw new Error("The repo is not set.") + async (tagName: string, { getState, rejectWithValue }) => { + const { namespace, name } = getState().repoDeploy try { - const tag = await getTag(repo.id, name) + const tag = await getTag(namespace, name, name) return tag } catch(e) { if (e instanceof HttpNotFoundError) { @@ -248,13 +239,10 @@ export const addTagManually = createAsyncThunk( "repoDeploy/searchCandidates", async (q, { getState, rejectWithValue }) => { - const { repo } = getState().repoDeploy - if (!repo) { - throw new Error("The repo is not set.") - } + const { namespace, name } = getState().repoDeploy try { - const perms = await listPerms(repo, q) + const perms = await listPerms(namespace, name, q) const candidates = perms.map((p) => { return p.user }) @@ -268,13 +256,11 @@ export const searchCandidates = createAsyncThunk ( "repoDeploy/deploy", async (_ , { getState, rejectWithValue, requestId }) => { - const { repo, env, type, branch, commit, tag, approvers, deploying, deployId } = getState().repoDeploy - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name, env, type, branch, commit, tag, approvers, deploying, deployId } = getState().repoDeploy if (!env) { throw new Error("The env is undefined.") } + if (deploying !== RequestStatus.Pending || requestId !== deployId ) { return } @@ -282,29 +268,29 @@ export const deploy = createAsyncThunk - It starts to deploy. #{deployment.number} + It starts to deploy. #{deployment.number} message.success(msg, 3) return } approvers.forEach(async (approver) => { - await createApproval(repo, deployment, approver) + await createApproval(namespace, name, deployment.number, approver.id) }) const msg = - It is waiting approvals. #{deployment.number} + It is waiting approvals. #{deployment.number} message.success(msg, 3) } catch(e) { @@ -328,6 +314,10 @@ export const repoDeploySlice = createSlice({ name: "repoDeploy", initialState, reducers: { + init: (state, action: PayloadAction<{namespace: string, name: string}>) => { + state.namespace = action.payload.namespace + state.name = action.payload.name + }, setDisplay: (state, action: PayloadAction) => { state.display = action.payload }, @@ -366,9 +356,6 @@ export const repoDeploySlice = createSlice({ }, extraReducers: builder => { builder - .addCase(init.fulfilled, (state, action) => { - state.repo = action.payload - }) .addCase(fetchConfig.fulfilled, (state, action) => { const config = action.payload state.envs = config.envs.map(e => e) diff --git a/ui/src/redux/repoHome.ts b/ui/src/redux/repoHome.ts index f4ebfa53..565d4e9c 100644 --- a/ui/src/redux/repoHome.ts +++ b/ui/src/redux/repoHome.ts @@ -1,13 +1,14 @@ import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit' -import { Repo, Deployment, Event, EventTypeEnum } from '../models' -import { searchRepo, listDeployments, getConfig } from '../apis' +import { Deployment, Event, EventTypeEnum } from '../models' +import { listDeployments, getConfig } from '../apis' export const perPage = 20; interface RepoHomeState { loading: boolean - repo?: Repo + namespace: string + name: string envs: string[] env: string deployments: Deployment[] @@ -16,46 +17,30 @@ interface RepoHomeState { const initialState: RepoHomeState = { loading: true, + namespace: "", + name: "", envs: [], env: "", deployments: [], page: 1, } -export const init = createAsyncThunk( - 'repoHome/init', - async (params) => { - const repo = await searchRepo(params.namespace, params.name) - return repo - }, -) - export const fetchEnvs = createAsyncThunk( "repoHome/fetchEnvs", - async (_, { getState, rejectWithValue } ) => { - const { repo, } = getState().repoHome - - if (!repo) { - rejectWithValue(new Error("repo doesn't exist.")) - return [] - } + async (_, { getState } ) => { + const { namespace, name } = getState().repoHome - const config = await getConfig(repo.id) + const config = await getConfig(namespace, name) return config.envs.map(e => e.name) }, ) export const fetchDeployments = createAsyncThunk( 'repoHome/fetchDeployments', - async (_, { getState, rejectWithValue } ) => { - const { repo, env, page} = getState().repoHome + async (_, { getState } ) => { + const { namespace, name, env, page} = getState().repoHome - if (!repo) { - rejectWithValue(new Error("repo doesn't exist.")) - return [] - } - - const deployments = await listDeployments(repo.id, env, "",page, perPage) + const deployments = await listDeployments(namespace, name, env, "",page, perPage) return deployments }, ) @@ -64,6 +49,10 @@ export const repoHomeSlice = createSlice({ name: "repoHome", initialState, reducers: { + init: (state, action: PayloadAction<{namespace: string, name: string}>) => { + state.namespace = action.payload.namespace + state.name = action.payload.name + }, setEnv: (state, action: PayloadAction) => { state.env = action.payload }, @@ -76,7 +65,8 @@ export const repoHomeSlice = createSlice({ handleDeploymentEvent: (state, action: PayloadAction) => { const event = action.payload - if (event.deployment?.repo?.id !== state.repo?.id) { + if (!(event.deployment?.repo?.namespace === state.namespace + && event.deployment?.repo?.name === state.name)) { return } @@ -96,10 +86,6 @@ export const repoHomeSlice = createSlice({ }, extraReducers: builder => { builder - .addCase(init.fulfilled, (state, action) => { - state.repo = action.payload - }) - .addCase(fetchEnvs.fulfilled, (state, action) => { state.envs = action.payload }) diff --git a/ui/src/redux/repoLock.ts b/ui/src/redux/repoLock.ts index 90a5df65..df4015de 100644 --- a/ui/src/redux/repoLock.ts +++ b/ui/src/redux/repoLock.ts @@ -2,13 +2,11 @@ import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit' import { message } from "antd" import { - Repo, Config, Lock, HttpForbiddenError } from "../models" import { - searchRepo, getConfig, listLocks as _listLocks, lock as _lock, @@ -17,34 +15,26 @@ import { interface RepoLockState { display: boolean - repo?: Repo + namespace: string + name: string config?: Config locks: Lock[] } const initialState: RepoLockState = { display: false, + namespace: "", + name: "", locks: [], } -export const init = createAsyncThunk( - 'repoLock/init', - async (params) => { - const repo = await searchRepo(params.namespace, params.name) - return repo - }, -) - export const fetchConfig = createAsyncThunk( "repoLock/fetchConfig", async (_, { getState, rejectWithValue } ) => { - const { repo } = getState().repoLock - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name } = getState().repoLock try { - const config = await getConfig(repo.id) + const config = await getConfig(namespace, name) return config } catch (e) { return rejectWithValue(e) @@ -55,13 +45,10 @@ export const fetchConfig = createAsyncThunk( 'repoLock/listLocks', async (_, { getState, rejectWithValue }) => { - const { repo } = getState().repoLock - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name } = getState().repoLock try { - const locks = await _listLocks(repo) + const locks = await _listLocks(namespace, name) return locks } catch (e) { return rejectWithValue(e) @@ -72,13 +59,10 @@ export const listLocks = createAsyncThunk( 'repoLock/lock', async (env, { getState, rejectWithValue }) => { - const { repo } = getState().repoLock - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name } = getState().repoLock try { - const locks = await _lock(repo, env) + const locks = await _lock(namespace, name, env) return locks } catch (e) { if (e instanceof HttpForbiddenError) { @@ -92,10 +76,7 @@ export const lock = createAsyncThunk( 'repoLock/unlock', async (env, { getState, rejectWithValue }) => { - const { repo, locks } = getState().repoLock - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name, locks } = getState().repoLock const lock = locks.find((lock) => lock.env === env) if (!lock) { @@ -103,7 +84,7 @@ export const unlock = createAsyncThunk) => { + state.namespace = action.payload.namespace + state.name = action.payload.name + }, setDisplay: (state, action: PayloadAction) => { state.display = action.payload }, }, extraReducers: builder => { builder - .addCase(init.fulfilled, (state, action) => { - state.repo = action.payload - }) - .addCase(fetchConfig.fulfilled, (state, action) => { state.config = action.payload }) - .addCase(listLocks.fulfilled, (state, action) => { state.locks = action.payload }) - .addCase(lock.fulfilled, (state, action) => { state.locks.push(action.payload) }) - .addCase(unlock.fulfilled, (state, action) => { const idx = state.locks.findIndex((lock) => lock.id === action.payload.id) diff --git a/ui/src/redux/repoRollback.tsx b/ui/src/redux/repoRollback.tsx index eb92a81e..c0927bf6 100644 --- a/ui/src/redux/repoRollback.tsx +++ b/ui/src/redux/repoRollback.tsx @@ -2,7 +2,6 @@ import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit' import { message } from "antd" import { - searchRepo, getConfig, listDeployments, rollbackDeployment, @@ -11,7 +10,6 @@ import { } from "../apis" import { User, - Repo, Deployment, DeploymentStatusEnum, Config, @@ -26,8 +24,9 @@ const page = 1 const perPage = 100 interface RepoRollbackState { - display: boolean, - repo?: Repo + display: boolean + namespace: string + name: string config?: Config env?: Env envs: Env[] @@ -46,6 +45,8 @@ interface RepoRollbackState { const initialState: RepoRollbackState = { display: false, + namespace: "", + name: "", envs: [], deployments: [], approvers: [], @@ -54,22 +55,13 @@ const initialState: RepoRollbackState = { deploying: RequestStatus.Idle } -export const init = createAsyncThunk( - 'repoRollback/init', - async (params) => { - const repo = await searchRepo(params.namespace, params.name) - return repo - }, -) - export const fetchConfig = createAsyncThunk( "repoRollback/fetchEnvs", async (_, { getState, rejectWithValue } ) => { - const { repo } = getState().repoRollback - if (!repo) throw new Error("The repo is not set.") + const { namespace, name } = getState().repoRollback try { - const config = await getConfig(repo.id) + const config = await getConfig(namespace, name) return config } catch (e) { return rejectWithValue(e) @@ -80,11 +72,13 @@ export const fetchConfig = createAsyncThunk( "repoRollback/fetchDeployments", async (_, { getState }) => { - const { repo, env } = getState().repoRollback - if (!repo) throw new Error("The repo is not set.") - if (!env) throw new Error("The env is not selected.") + const { namespace, name, env } = getState().repoRollback + + if (!env) { + throw new Error("The env is not selected.") + } - const deployments = await listDeployments(repo.id, env.name, DeploymentStatusEnum.Success, page, perPage) + const deployments = await listDeployments(namespace, name, env.name, DeploymentStatusEnum.Success, page, perPage) return deployments } ) @@ -92,13 +86,10 @@ export const fetchDeployments = createAsyncThunk( "repoRollback/searchCandidates", async (q, { getState, rejectWithValue }) => { - const { repo } = getState().repoRollback - if (!repo) { - throw new Error("The repo is not set.") - } + const { namespace, name } = getState().repoRollback try { - const perms = await listPerms(repo, q) + const perms = await listPerms(namespace, name, q) const candidates = perms.map((p) => { return p.user }) @@ -112,10 +103,7 @@ export const searchCandidates = createAsyncThunk ( "repoRollback/deploy", async (_ , { getState, rejectWithValue, requestId }) => { - const { repo, deployment, env, approvers, deployId, deploying } = getState().repoRollback - if (!repo) { - throw new Error("The repo is undefined.") - } + const { namespace, name, deployment, env, approvers, deployId, deploying } = getState().repoRollback if (!deployment) { throw new Error("The deployment is undefined.") } @@ -124,22 +112,22 @@ export const rollback = createAsyncThunk - It starts to rollback. #{rollback.number} + It starts to rollback. #{rollback.number} message.success(msg, 3) return } approvers.forEach(async (approver) => { - await createApproval(repo, rollback, approver) + await createApproval(namespace, name, rollback.number, approver.id) }) const msg = - It is waiting approvals. #{rollback.number} + It is waiting approvals. #{rollback.number} message.success(msg, 3) } catch(e) { @@ -163,6 +151,10 @@ export const repoRollbackSlice = createSlice({ name: "repoRollback", initialState, reducers: { + init: (state, action: PayloadAction<{namespace: string, name: string}>) => { + state.namespace = action.payload.namespace + state.name = action.payload.name + }, setDisplay: (state, action: PayloadAction) => { state.display = action.payload }, @@ -192,9 +184,6 @@ export const repoRollbackSlice = createSlice({ }, extraReducers: builder => { builder - .addCase(init.fulfilled, (state, action) => { - state.repo = action.payload - }) .addCase(fetchConfig.fulfilled, (state, action) => { const config = action.payload state.envs = config.envs.map(e => e) diff --git a/ui/src/redux/repoSettings.ts b/ui/src/redux/repoSettings.ts index d4c75db4..8bdaa5bd 100644 --- a/ui/src/redux/repoSettings.ts +++ b/ui/src/redux/repoSettings.ts @@ -1,7 +1,7 @@ import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit" import { message } from "antd" -import { searchRepo, updateRepo, deactivateRepo } from "../apis" +import { getRepo, updateRepo, deactivateRepo } from "../apis" import { Repo, RequestStatus, HttpForbiddenError } from "../models" interface RepoSettingsState { @@ -20,7 +20,7 @@ const initialState: RepoSettingsState = { export const init = createAsyncThunk( 'repoSettings/init', async (params) => { - const repo = await searchRepo(params.namespace, params.name) + const repo = await getRepo(params.namespace, params.name) return repo }, ) @@ -38,7 +38,7 @@ export const save = createAsyncThunk() const { + display, deployment, changes, deploying, @@ -54,9 +54,9 @@ export default function DeploymentView(): JSX.Element { useEffect(() => { const f = async () => { - await dispatch(init({namespace, name})) - await dispatch(slice.actions.setNumber(parseInt(number, 10))) + await dispatch(slice.actions.init({namespace, name, number: parseInt(number, 10)})) await dispatch(fetchDeployment()) + await dispatch(slice.actions.setDisplay(true)) await dispatch(fetchDeploymentChanges()) await dispatch(fetchApprovals()) await dispatch(fetchMyApproval()) @@ -116,10 +116,25 @@ export default function DeploymentView(): JSX.Element { dispatch(createApproval(candidate)) } + if (!display) { + return ( +
+
+ +
+
+ ) + } + if (!deployment) { - return
-
-
+ return ( +
+ +
+ ) } // buttons diff --git a/ui/src/views/RepoDeploy.tsx b/ui/src/views/RepoDeploy.tsx index 809d6f2d..5a9c3a84 100644 --- a/ui/src/views/RepoDeploy.tsx +++ b/ui/src/views/RepoDeploy.tsx @@ -6,7 +6,6 @@ import { PageHeader, Result, Button } from "antd"; import { useAppSelector, useAppDispatch } from "../redux/hooks" import { User,DeploymentType, Branch, Commit, Tag, RequestStatus, Env } from "../models"; import { - init, fetchConfig, repoDeploySlice, fetchCurrentDeploymentOfEnv, @@ -35,7 +34,6 @@ export default function RepoDeploy(): JSX.Element { const { namespace, name } = useParams() const { display, - repo, config, env, envs, @@ -52,7 +50,7 @@ export default function RepoDeploy(): JSX.Element { useEffect(() => { const f = async () => { - await dispatch(init({namespace, name})) + await dispatch(actions.init({namespace, name})) await dispatch(fetchConfig()) await dispatch(actions.setDisplay(true)) await dispatch(fetchBranches()) @@ -119,11 +117,11 @@ export default function RepoDeploy(): JSX.Element { f() } - if (!display || !repo) { + if (!display) { return
} - if (repo && !config) { + if (!config) { return ( { const f = async () => { - await dispatch(init({namespace, name})) + await dispatch(slice.actions.init({namespace, name})) await dispatch(fetchEnvs()) await dispatch(fetchDeployments()) } diff --git a/ui/src/views/RepoLock.tsx b/ui/src/views/RepoLock.tsx index c99fb3f1..7e1c7465 100644 --- a/ui/src/views/RepoLock.tsx +++ b/ui/src/views/RepoLock.tsx @@ -5,7 +5,7 @@ import { PageHeader, Button } from 'antd' import { Result } from "antd" import { useAppSelector, useAppDispatch } from "../redux/hooks" -import { init, fetchConfig, listLocks, lock, unlock, repoLockSlice as slice} from "../redux/repoLock" +import { fetchConfig, listLocks, lock, unlock, repoLockSlice as slice} from "../redux/repoLock" import LockList from '../components/LockList' interface Params { @@ -15,12 +15,12 @@ interface Params { export default function RepoLock(): JSX.Element { const { namespace, name } = useParams() - const { display, repo, config, locks } = useAppSelector(state => state.repoLock, shallowEqual) + const { display, config, locks } = useAppSelector(state => state.repoLock, shallowEqual) const dispatch = useAppDispatch() useEffect(() => { const f = async () => { - await dispatch(init({namespace, name})) + await dispatch(slice.actions.init({namespace, name})) await dispatch(fetchConfig()) await dispatch(listLocks()) await dispatch(slice.actions.setDisplay(true)) @@ -29,11 +29,11 @@ export default function RepoLock(): JSX.Element { // eslint-disable-next-line }, [dispatch]) - if (!display || !repo) { + if (!display) { return <> } - if (repo && !config) { + if (!config) { return ( () const { display, - repo, config, env, envs, @@ -31,7 +30,7 @@ export default function RepoHome(): JSX.Element { useEffect(() => { const f = async () => { - await dispatch(init({namespace, name})) + await dispatch(actions.init({namespace, name})) await dispatch(fetchConfig()) await dispatch(actions.setDisplay(true)) await dispatch(searchCandidates("")) @@ -68,11 +67,11 @@ export default function RepoHome(): JSX.Element { f() } - if (!display || !repo) { - return
+ if (!display) { + return <> } - if (repo && !config) { + if (!config) { return ( Date: Fri, 1 Oct 2021 10:59:20 +0900 Subject: [PATCH 3/3] Fix bug --- internal/server/slack/notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/server/slack/notification.go b/internal/server/slack/notification.go index 1fcbbc6c..d9fde411 100644 --- a/internal/server/slack/notification.go +++ b/internal/server/slack/notification.go @@ -93,7 +93,7 @@ func (s *Slack) notifyApprovalEvent(ctx context.Context, e *ent.Event) { return } - if d = a.Edges.Deployment; d != nil { + if d = a.Edges.Deployment; d == nil { s.log.Error("The eager loading of deployment has failed.") return }