7
7
ActiveTransition ,
8
8
WorkspaceBuildProgress ,
9
9
} from "components/WorkspaceBuildProgress/WorkspaceBuildProgress"
10
- import { FC } from "react"
10
+ import { FC , useEffect , useState } from "react"
11
11
import { useTranslation } from "react-i18next"
12
12
import { useNavigate } from "react-router-dom"
13
13
import * as TypesGen from "../../api/typesGenerated"
@@ -32,6 +32,7 @@ import { useLocalStorage } from "hooks"
32
32
import { ChooseOne , Cond } from "components/Conditionals/ChooseOne"
33
33
import AlertTitle from "@mui/material/AlertTitle"
34
34
import { Maybe } from "components/Conditionals/Maybe"
35
+ import dayjs from "dayjs"
35
36
36
37
export enum WorkspaceErrors {
37
38
GET_BUILDS_ERROR = "getBuildsError" ,
@@ -131,6 +132,38 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
131
132
if ( template !== undefined ) {
132
133
transitionStats = ActiveTransition ( template , workspace )
133
134
}
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 ] )
134
167
return (
135
168
< >
136
169
< FullWidthPageHeader >
@@ -208,12 +241,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
208
241
209
242
< TemplateVersionWarnings warnings = { templateWarnings } />
210
243
211
- < Maybe
212
- condition = {
213
- workspace . latest_build . status === "pending" &&
214
- workspace . latest_build . job . queue_size > 0
215
- }
216
- >
244
+ < Maybe condition = { showAlertPendingInQueue } >
217
245
< Alert severity = "info" >
218
246
< AlertTitle > Workspace build is pending</ AlertTitle >
219
247
< AlertDetail >
0 commit comments