11import { 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
66import CreatableSelect , { Option as Op } from "./CreatableSelect"
77import 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
280293interface CommitDecoratorProps {
281294 commit : Commit
295+ currentDeployment ?: Deployment
282296}
283297
284298function 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 < 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+ }
0 commit comments