1
+ import CircularProgress from "@material-ui/core/CircularProgress"
1
2
import { makeStyles } from "@material-ui/core/styles"
2
3
import dayjs from "dayjs"
3
4
import { FC } from "react"
4
5
import { ProvisionerJobLog } from "../../api/typesGenerated"
5
6
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
6
7
import { Logs } from "../Logs/Logs"
7
8
9
+ const Language = {
10
+ seconds : "seconds" ,
11
+ }
12
+
8
13
type Stage = ProvisionerJobLog [ "stage" ]
9
14
10
15
const groupLogsByStage = ( logs : ProvisionerJobLog [ ] ) => {
@@ -35,29 +40,38 @@ const getStageDurationInSeconds = (logs: ProvisionerJobLog[]) => {
35
40
36
41
export interface WorkspaceBuildLogsProps {
37
42
logs : ProvisionerJobLog [ ]
43
+ isWaitingForLogs : boolean
38
44
}
39
45
40
- export const WorkspaceBuildLogs : FC < WorkspaceBuildLogsProps > = ( { logs } ) => {
46
+ export const WorkspaceBuildLogs : FC < WorkspaceBuildLogsProps > = ( { logs, isWaitingForLogs } ) => {
41
47
const groupedLogsByStage = groupLogsByStage ( logs )
42
48
const stages = Object . keys ( groupedLogsByStage )
43
49
const styles = useStyles ( )
44
50
45
51
return (
46
52
< div className = { styles . logs } >
47
- { stages . map ( ( stage ) => {
53
+ { stages . map ( ( stage , stageIndex ) => {
48
54
const logs = groupedLogsByStage [ stage ]
49
55
const isEmpty = logs . every ( ( log ) => log . output === "" )
50
56
const lines = logs . map ( ( log ) => ( {
51
57
time : log . created_at ,
52
58
output : log . output ,
53
59
} ) )
54
60
const duration = getStageDurationInSeconds ( logs )
61
+ const isLastStage = stageIndex === stages . length - 1
62
+ const shouldDisplaySpinner = isWaitingForLogs && isLastStage
63
+ const shouldDisplayDuration = ! isWaitingForLogs && duration
55
64
56
65
return (
57
66
< div key = { stage } >
58
67
< div className = { styles . header } >
59
68
< div > { stage } </ div >
60
- { duration && < div className = { styles . duration } > { duration } seconds</ div > }
69
+ { shouldDisplaySpinner && < CircularProgress size = { 14 } className = { styles . spinner } /> }
70
+ { shouldDisplayDuration && (
71
+ < div className = { styles . duration } >
72
+ { duration } { Language . seconds }
73
+ </ div >
74
+ ) }
61
75
</ div >
62
76
{ ! isEmpty && < Logs lines = { lines } className = { styles . codeBlock } /> }
63
77
</ div >
@@ -78,6 +92,7 @@ const useStyles = makeStyles((theme) => ({
78
92
fontSize : theme . typography . body1 . fontSize ,
79
93
padding : theme . spacing ( 2 ) ,
80
94
paddingLeft : theme . spacing ( 4 ) ,
95
+ paddingRight : theme . spacing ( 4 ) ,
81
96
borderBottom : `1px solid ${ theme . palette . divider } ` ,
82
97
backgroundColor : theme . palette . background . paper ,
83
98
display : "flex" ,
@@ -94,4 +109,8 @@ const useStyles = makeStyles((theme) => ({
94
109
padding : theme . spacing ( 2 ) ,
95
110
paddingLeft : theme . spacing ( 4 ) ,
96
111
} ,
112
+
113
+ spinner : {
114
+ marginLeft : "auto" ,
115
+ } ,
97
116
} ) )
0 commit comments