-
Notifications
You must be signed in to change notification settings - Fork 894
feat: delay pending-in-queue banner #8309
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,28 +133,37 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({ | |
transitionStats = ActiveTransition(template, workspace) | ||
} | ||
|
||
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false); | ||
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false) | ||
const now = dayjs() | ||
useEffect(() => { | ||
if (workspace.latest_build.status === "pending" && | ||
if ( | ||
workspace.latest_build.status === "pending" && | ||
workspace.latest_build.job.queue_size > 0 && | ||
dayjs(workspace.latest_build.created_at).isBefore(now.subtract(5, 'seconds'))) { | ||
setShowAlertPendingInQueue(true); | ||
dayjs(workspace.latest_build.created_at).isBefore( | ||
now.subtract(5, "seconds"), | ||
) | ||
) { | ||
setShowAlertPendingInQueue(true) | ||
return | ||
} | ||
|
||
if (workspace.latest_build.status === "pending" && | ||
workspace.latest_build.job.queue_size > 0) { | ||
const timer = setTimeout(() => { | ||
if (workspace.latest_build.status !== "pending" || workspace.latest_build.job.queue_size === 0) { | ||
return | ||
} | ||
setShowAlertPendingInQueue(true); | ||
}, 5000) | ||
|
||
return () => { | ||
clearTimeout(timer); | ||
if ( | ||
workspace.latest_build.status === "pending" && | ||
workspace.latest_build.job.queue_size > 0 | ||
) { | ||
const timer = setTimeout(() => { | ||
if ( | ||
workspace.latest_build.status !== "pending" || | ||
workspace.latest_build.job.queue_size === 0 | ||
) { | ||
return | ||
} | ||
setShowAlertPendingInQueue(true) | ||
}, 5000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using the difference here (now.subtract 5 sec) so that loading a new workspace doesn't reset the timer to 5 seconds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that I understand what you mean. Could you please elaborate a bit more about the case you have in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So let's say you:
Does this make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense now, thanks. I used the diff, feel free to review that part. |
||
|
||
return () => { | ||
clearTimeout(timer) | ||
} | ||
} | ||
}, [workspace, now]) | ||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed we're not setting
setShowAlertPendingInQueue(false)
anywhere? Perhaps this condition could be inverted and placed at the top with an false + early return. Should simplify the other checks as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed