Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 622b602

Browse files
author
Noah Hanjun Lee
authored
Display the current deployment tag for the REF (#130)
1 parent c28fbe2 commit 622b602

File tree

3 files changed

+62
-13
lines changed

3 files changed

+62
-13
lines changed

ui/src/components/DeployForm.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from "react"
2-
import { Form, Select, Radio, Button, Typography, Avatar } from "antd"
2+
import { Form, Select, Radio, Button, Typography, Avatar, Tag as AntdTag } from "antd"
33

4-
import { Branch, Commit, Tag, DeploymentType, Status, User, Env } from "../models"
4+
import { Branch, Commit, Tag, Deployment, DeploymentType, Status, User, Env } from "../models"
55

66
import CreatableSelect, {Option as Op} from "./CreatableSelect"
77
import StatusStateIcon from "./StatusStateIcon"
@@ -16,6 +16,7 @@ interface DeployFormProps {
1616
envs: Env[]
1717
onSelectEnv(env: Env): void
1818
onChangeType(type: DeploymentType): void
19+
currentDeployment?: Deployment
1920
branches: Branch[]
2021
onSelectBranch(branch: Branch): void
2122
onClickAddBranch(option: Option): void
@@ -114,20 +115,28 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
114115
props.onChangeType(type)
115116
}
116117

117-
const mapBranchToOption = (branch: Branch) => {
118-
return {
119-
label: <Text className="gitploy-code" code>{branch.name}</Text>,
120-
value: branch.name
121-
} as Option
122-
}
123-
124118
const onSelectEnv = (value: string) => {
125119
const env = props.envs.find(env => env.name === value)
126120
if (env === undefined) throw new Error("The env doesn't exist.")
127121

128122
props.onSelectEnv(env)
129123
}
130124

125+
const mapBranchToOption = (branch: Branch) => {
126+
// Display the tag only when the type is 'branch'.
127+
const tag = (deploymentType === DeploymentType.Branch
128+
&& branch.commitSha === props.currentDeployment?.sha) ?
129+
<AntdTag color="success">{props.currentDeployment.env}</AntdTag> :
130+
null
131+
132+
return {
133+
label: <span>
134+
<Text className="gitploy-code" code>{branch.name}</Text>{tag}
135+
</span>,
136+
value: branch.name
137+
} as Option
138+
}
139+
131140
const onSelectBranch = (option: Option) => {
132141
const branch = props.branches.find(b => b.name === option.value)
133142
if (branch === undefined) throw new Error("The branch doesn't exist.")
@@ -137,7 +146,7 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
137146

138147
const mapCommitToOption = (commit: Commit) => {
139148
return {
140-
label: <CommitDecorator commit={commit}/>,
149+
label: <CommitDecorator commit={commit} currentDeployment={props.currentDeployment}/>,
141150
value: commit.sha,
142151
} as Option
143152
}
@@ -150,8 +159,12 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
150159
}
151160

152161
const mapTagToOption = (tag: Tag) => {
162+
const deploymentTag = (tag.commitSha === props.currentDeployment?.sha) ?
163+
<AntdTag color="success">{props.currentDeployment.env}</AntdTag> :
164+
null
165+
153166
return {
154-
label: <Text className="gitploy-code" code>{tag.name}</Text>,
167+
label: <Text className="gitploy-code" code>{tag.name} {deploymentTag}</Text>,
155168
value: tag.name
156169
} as Option
157170
}
@@ -279,16 +292,21 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
279292

280293
interface CommitDecoratorProps {
281294
commit: Commit
295+
currentDeployment?: Deployment
282296
}
283297

284298
function CommitDecorator(props: CommitDecoratorProps): JSX.Element {
299+
const tag = (props.commit.sha === props.currentDeployment?.sha) ?
300+
<AntdTag color="success">{props.currentDeployment.env}</AntdTag> :
301+
null
302+
285303
return (
286304
<span>
287-
<Text className="gitploy-code" code>{props.commit.sha.substring(0, 7)}</Text> - <Text strong>{props.commit.message}</Text> <br/>
305+
<Text className="gitploy-code" code>{props.commit.sha.substring(0, 7)}</Text>{tag}- <Text strong>{props.commit.message}</Text> <br/>
288306
{(props.commit?.author)?
289307
<span >
290308
&nbsp;<Text ><Avatar size="small" src={props.commit.author.avatarUrl} /> {props.commit.author.login}</Text> <Text >committed {moment(props.commit.author?.date).fromNow()}</Text>
291309
</span>: null}
292310
</span>
293311
)
294-
}
312+
}

ui/src/redux/repoDeploy.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
searchRepo,
2323
listPerms,
2424
getConfig,
25+
listDeployments,
2526
listBranches,
2627
getBranch,
2728
listCommits,
@@ -43,6 +44,7 @@ interface RepoDeployState {
4344
config?: Config
4445
env?: Env
4546
envs: Env[]
47+
currentDeployment?: Deployment
4648
type?: DeploymentType
4749
branch?: Branch
4850
branchStatuses: Status[]
@@ -102,6 +104,23 @@ export const fetchConfig = createAsyncThunk<Config, void, { state: {repoDeploy:
102104
},
103105
)
104106

107+
export const fetchCurrentDeploymentOfEnv = createAsyncThunk<Deployment | null, Env, { state: {repoDeploy: RepoDeployState} }>(
108+
"repoDeploy/fetchCurrentDeployment",
109+
async (env, { getState, rejectWithValue } ) => {
110+
const { repo } = getState().repoDeploy
111+
if (!repo) {
112+
throw new Error("The repo is undefined.")
113+
}
114+
115+
try {
116+
const deployments = await listDeployments(repo.id, env.name, "success", 1, 1)
117+
return (deployments.length > 0)? deployments[0] : null
118+
} catch (e) {
119+
return rejectWithValue(e)
120+
}
121+
},
122+
)
123+
105124
export const fetchBranches = createAsyncThunk<Branch[], void, { state: {repoDeploy: RepoDeployState }}>(
106125
"repoDeploy/fetchBranches",
107126
async (_, { getState }) => {
@@ -355,6 +374,14 @@ export const repoDeploySlice = createSlice({
355374
state.envs = config.envs.map(e => e)
356375
state.config = config
357376
})
377+
.addCase(fetchCurrentDeploymentOfEnv.fulfilled, (state, action) => {
378+
if (action.payload) {
379+
state.currentDeployment = action.payload
380+
}
381+
})
382+
.addCase(fetchCurrentDeploymentOfEnv.rejected, (state) => {
383+
state.currentDeployment = undefined
384+
})
358385
.addCase(fetchBranches.fulfilled, (state, action) => {
359386
state.branches = action.payload
360387
})

ui/src/views/RepoDeploy.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
init,
1010
fetchConfig,
1111
repoDeploySlice,
12+
fetchCurrentDeploymentOfEnv,
1213
fetchBranches,
1314
checkBranch,
1415
addBranchManually,
@@ -38,6 +39,7 @@ export default function RepoDeploy(): JSX.Element {
3839
config,
3940
env,
4041
envs,
42+
currentDeployment,
4143
branches,
4244
branchStatuses,
4345
commits,
@@ -63,6 +65,7 @@ export default function RepoDeploy(): JSX.Element {
6365

6466
const onSelectEnv = (env: Env) => {
6567
dispatch(actions.setEnv(env))
68+
dispatch(fetchCurrentDeploymentOfEnv(env))
6669
}
6770

6871
const onChangeType = (type: DeploymentType) => {
@@ -146,6 +149,7 @@ export default function RepoDeploy(): JSX.Element {
146149
envs={envs}
147150
onSelectEnv={onSelectEnv}
148151
onChangeType={onChangeType}
152+
currentDeployment={currentDeployment}
149153
branches={branches}
150154
onSelectBranch={onSelectBranch}
151155
onClickAddBranch={onClickAddBranch}

0 commit comments

Comments
 (0)