11import { Form , Typography , Avatar , Button , Collapse , Timeline } from "antd"
22import moment from "moment"
3+ import { useState } from "react"
34
45import { Deployment , Commit } from "../models"
56import DeploymentRefCode from "./DeploymentRefCode"
67import DeploymentStatusSteps from "./DeploymentStatusSteps"
78
8- const { Text } = Typography
9+ const { Paragraph , Text } = Typography
910const { Panel } = Collapse
1011
1112interface DeployConfirmProps {
@@ -119,19 +120,56 @@ function CommitChanges(props: CommitChangesProps): JSX.Element {
119120 if ( props . changes . length === 0 ) {
120121 return < div > There are no commits.</ div >
121122 }
123+
122124 return (
123125 < Timeline >
124126 { props . changes . slice ( 0 , 10 ) . map ( ( change , idx ) => {
125- const style : React . CSSProperties = ( idx === props . changes . length - 1 ) ? { height : 0 } : { }
126- // Omit lines after the first feedline.
127- const message = change . message . split ( "\n" , 1 ) [ 0 ]
128-
129- return < Timeline . Item key = { idx } color = "gray" style = { style } >
130- < a href = { change . htmlUrl } className = "gitploy-link" >
131- { message . substr ( 0 , 50 ) }
132- </ a >
127+ return < Timeline . Item key = { idx } color = "gray" >
128+ < CommitChange commit = { change } />
133129 </ Timeline . Item >
134130 } ) }
135131 </ Timeline >
136132 )
133+ }
134+
135+ interface CommitChangeProps {
136+ commit : Commit
137+ }
138+
139+ function CommitChange ( props : CommitChangeProps ) : JSX . Element {
140+ const commit = props . commit
141+ const [ message , description ] = commit . message . split ( "\n\n" , 2 )
142+
143+ const [ hide , setHide ] = useState ( true )
144+
145+ const onClickHide = ( ) => {
146+ setHide ( ! hide )
147+ }
148+
149+ return (
150+ < span >
151+ < a href = { commit . htmlUrl } className = "gitploy-link" > < strong > { message . substring ( 0 , 50 ) } </ strong > </ a >
152+ { ( description ) ?
153+ < Button size = "small" type = "text" onClick = { onClickHide } >
154+ < Text className = "gitploy-code" code > ...</ Text >
155+ </ Button > :
156+ null }
157+ { /* Display the description of the commit. */ }
158+ { ( ! hide ) ?
159+ < Paragraph style = { { margin : 0 } } >
160+ < pre style = { { marginBottom : 0 } } >
161+ { description . split ( / ( \r \n ) / g) . map ( ( line , idx ) => {
162+ return ( line !== "\r\n" ) ? < Text key = { idx } > { line } </ Text > : < br />
163+ } ) }
164+ </ pre >
165+ </ Paragraph > :
166+ null }
167+ < br />
168+ { ( commit ?. author ) ?
169+ < span >
170+ < Text > < Avatar size = "small" src = { commit . author . avatarUrl } /> { commit . author . login } </ Text > < Text > committed { moment ( commit . author ?. date ) . fromNow ( ) } </ Text >
171+ </ span > :
172+ null }
173+ </ span >
174+ )
137175}
0 commit comments