1
1
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"
3
3
4
- import { Branch , Commit , Tag , DeploymentType , Status , User , Env } from "../models"
4
+ import { Branch , Commit , Tag , Deployment , DeploymentType , Status , User , Env } from "../models"
5
5
6
6
import CreatableSelect , { Option as Op } from "./CreatableSelect"
7
7
import StatusStateIcon from "./StatusStateIcon"
@@ -16,6 +16,7 @@ interface DeployFormProps {
16
16
envs : Env [ ]
17
17
onSelectEnv ( env : Env ) : void
18
18
onChangeType ( type : DeploymentType ) : void
19
+ currentDeployment ?: Deployment
19
20
branches : Branch [ ]
20
21
onSelectBranch ( branch : Branch ) : void
21
22
onClickAddBranch ( option : Option ) : void
@@ -114,20 +115,28 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
114
115
props . onChangeType ( type )
115
116
}
116
117
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
-
124
118
const onSelectEnv = ( value : string ) => {
125
119
const env = props . envs . find ( env => env . name === value )
126
120
if ( env === undefined ) throw new Error ( "The env doesn't exist." )
127
121
128
122
props . onSelectEnv ( env )
129
123
}
130
124
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
+
131
140
const onSelectBranch = ( option : Option ) => {
132
141
const branch = props . branches . find ( b => b . name === option . value )
133
142
if ( branch === undefined ) throw new Error ( "The branch doesn't exist." )
@@ -137,7 +146,7 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
137
146
138
147
const mapCommitToOption = ( commit : Commit ) => {
139
148
return {
140
- label : < CommitDecorator commit = { commit } /> ,
149
+ label : < CommitDecorator commit = { commit } currentDeployment = { props . currentDeployment } /> ,
141
150
value : commit . sha ,
142
151
} as Option
143
152
}
@@ -150,8 +159,12 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
150
159
}
151
160
152
161
const mapTagToOption = ( tag : Tag ) => {
162
+ const deploymentTag = ( tag . commitSha === props . currentDeployment ?. sha ) ?
163
+ < AntdTag color = "success" > { props . currentDeployment . env } </ AntdTag > :
164
+ null
165
+
153
166
return {
154
- label : < Text className = "gitploy-code" code > { tag . name } </ Text > ,
167
+ label : < Text className = "gitploy-code" code > { tag . name } { deploymentTag } </ Text > ,
155
168
value : tag . name
156
169
} as Option
157
170
}
@@ -279,16 +292,21 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
279
292
280
293
interface CommitDecoratorProps {
281
294
commit : Commit
295
+ currentDeployment ?: Deployment
282
296
}
283
297
284
298
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
+
285
303
return (
286
304
< 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 />
288
306
{ ( props . commit ?. author ) ?
289
307
< span >
290
308
< Text > < Avatar size = "small" src = { props . commit . author . avatarUrl } /> { props . commit . author . login } </ Text > < Text > committed { moment ( props . commit . author ?. date ) . fromNow ( ) } </ Text >
291
309
</ span > : null }
292
310
</ span >
293
311
)
294
- }
312
+ }
0 commit comments