Skip to content

Commit 45eca67

Browse files
authored
feat: delay pending-in-queue banner (#8309)
1 parent d843735 commit 45eca67

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

site/src/components/Workspace/Workspace.tsx

+35-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ActiveTransition,
88
WorkspaceBuildProgress,
99
} from "components/WorkspaceBuildProgress/WorkspaceBuildProgress"
10-
import { FC } from "react"
10+
import { FC, useEffect, useState } from "react"
1111
import { useTranslation } from "react-i18next"
1212
import { useNavigate } from "react-router-dom"
1313
import * as TypesGen from "../../api/typesGenerated"
@@ -32,6 +32,7 @@ import { useLocalStorage } from "hooks"
3232
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
3333
import AlertTitle from "@mui/material/AlertTitle"
3434
import { Maybe } from "components/Conditionals/Maybe"
35+
import dayjs from "dayjs"
3536

3637
export enum WorkspaceErrors {
3738
GET_BUILDS_ERROR = "getBuildsError",
@@ -131,6 +132,38 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
131132
if (template !== undefined) {
132133
transitionStats = ActiveTransition(template, workspace)
133134
}
135+
136+
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false)
137+
const now = dayjs()
138+
useEffect(() => {
139+
if (
140+
workspace.latest_build.status !== "pending" ||
141+
workspace.latest_build.job.queue_size === 0
142+
) {
143+
if (!showAlertPendingInQueue) {
144+
return
145+
}
146+
147+
const hideTimer = setTimeout(() => {
148+
setShowAlertPendingInQueue(false)
149+
}, 250)
150+
return () => {
151+
clearTimeout(hideTimer)
152+
}
153+
}
154+
155+
const t = Math.max(
156+
0,
157+
5000 - dayjs().diff(dayjs(workspace.latest_build.created_at)),
158+
)
159+
const showTimer = setTimeout(() => {
160+
setShowAlertPendingInQueue(true)
161+
}, t)
162+
163+
return () => {
164+
clearTimeout(showTimer)
165+
}
166+
}, [workspace, now, showAlertPendingInQueue])
134167
return (
135168
<>
136169
<FullWidthPageHeader>
@@ -208,12 +241,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
208241

209242
<TemplateVersionWarnings warnings={templateWarnings} />
210243

211-
<Maybe
212-
condition={
213-
workspace.latest_build.status === "pending" &&
214-
workspace.latest_build.job.queue_size > 0
215-
}
216-
>
244+
<Maybe condition={showAlertPendingInQueue}>
217245
<Alert severity="info">
218246
<AlertTitle>Workspace build is pending</AlertTitle>
219247
<AlertDetail>

0 commit comments

Comments
 (0)