Skip to content

Support delete & stop transitions in build progress bar #4575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 17, 2022
Prev Previous commit
Next Next commit
Comment
  • Loading branch information
ammario committed Oct 16, 2022
commit 75b32c043c124fe10426e69c4ac59f8b1fb78040
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ const estimateFinish = (
const realPercentage = dayjs().diff(startedAt) / templateAverage

// Showing a full bar is frustrating.
if (realPercentage > 0.95) {
return [0.95, "Any moment now..."]
const maxPercentage = 0.99
if (realPercentage > maxPercentage) {
return [maxPercentage, "Any moment now..."]
}

return [
Expand Down Expand Up @@ -61,22 +62,27 @@ export const WorkspaceBuildProgress: FC<WorkspaceBuildProgressProps> = ({
buildEstimate,
}) => {
const styles = useStyles()

const job = workspace.latest_build.job

const [progressValue, setProgressValue] = useState(0)

// By default workspace is updated every second, which can cause visual stutter
// when the build estimate is a few seconds. The timer ensures no observable
// stutter in all cases.
useEffect(() => {
const updateProgress = () => {
if (job.status !== "running") {
setProgressValue(0)
return
}
setProgressValue(
estimateFinish(dayjs(job.started_at), buildEstimate)[0] * 100,
)
}
setTimeout(updateProgress, 100)
}, [progressValue, job.started_at, buildEstimate])
}, [progressValue, job, buildEstimate])

// buildEstimate may be undefined if the template is new or coderd hasn't
// finished initial metrics collection.
if (buildEstimate === undefined) {
return (
<div className={styles.stack}>
Expand Down