@@ -20,8 +20,9 @@ const estimateFinish = (
20
20
const realPercentage = dayjs ( ) . diff ( startedAt ) / templateAverage
21
21
22
22
// Showing a full bar is frustrating.
23
- if ( realPercentage > 0.95 ) {
24
- return [ 0.95 , "Any moment now..." ]
23
+ const maxPercentage = 0.99
24
+ if ( realPercentage > maxPercentage ) {
25
+ return [ maxPercentage , "Any moment now..." ]
25
26
}
26
27
27
28
return [
@@ -61,22 +62,27 @@ export const WorkspaceBuildProgress: FC<WorkspaceBuildProgressProps> = ({
61
62
buildEstimate,
62
63
} ) => {
63
64
const styles = useStyles ( )
64
-
65
65
const job = workspace . latest_build . job
66
-
67
66
const [ progressValue , setProgressValue ] = useState ( 0 )
67
+
68
68
// By default workspace is updated every second, which can cause visual stutter
69
69
// when the build estimate is a few seconds. The timer ensures no observable
70
70
// stutter in all cases.
71
71
useEffect ( ( ) => {
72
72
const updateProgress = ( ) => {
73
+ if ( job . status !== "running" ) {
74
+ setProgressValue ( 0 )
75
+ return
76
+ }
73
77
setProgressValue (
74
78
estimateFinish ( dayjs ( job . started_at ) , buildEstimate ) [ 0 ] * 100 ,
75
79
)
76
80
}
77
81
setTimeout ( updateProgress , 100 )
78
- } , [ progressValue , job . started_at , buildEstimate ] )
82
+ } , [ progressValue , job , buildEstimate ] )
79
83
84
+ // buildEstimate may be undefined if the template is new or coderd hasn't
85
+ // finished initial metrics collection.
80
86
if ( buildEstimate === undefined ) {
81
87
return (
82
88
< div className = { styles . stack } >
0 commit comments