Skip to content

Commit 29301b9

Browse files
committed
Show warning
1 parent 8d1f163 commit 29301b9

File tree

1 file changed

+86
-29
lines changed

1 file changed

+86
-29
lines changed

site/src/pages/TerminalPage/TerminalPage.tsx

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { makeStyles } from "@material-ui/core/styles"
2+
import WarningIcon from "@material-ui/icons/ErrorOutlineRounded"
23
import { useMachine } from "@xstate/react"
4+
import { WorkspaceAgent } from "api/typesGenerated"
35
import { portForwardURL } from "components/PortForwardButton/PortForwardButton"
46
import { Stack } from "components/Stack/Stack"
57
import { FC, useCallback, useEffect, useRef, useState } from "react"
@@ -21,34 +23,6 @@ export const Language = {
2123
websocketErrorMessagePrefix: "WebSocket failed: ",
2224
}
2325

24-
const useReloading = (isDisconnected: boolean) => {
25-
const [status, setStatus] = useState<"reloading" | "notReloading">(
26-
"notReloading",
27-
)
28-
29-
// Retry connection on key press when it is disconnected
30-
useEffect(() => {
31-
if (!isDisconnected) {
32-
return
33-
}
34-
35-
const keyDownHandler = () => {
36-
setStatus("reloading")
37-
window.location.reload()
38-
}
39-
40-
document.addEventListener("keydown", keyDownHandler)
41-
42-
return () => {
43-
document.removeEventListener("keydown", keyDownHandler)
44-
}
45-
}, [isDisconnected])
46-
47-
return {
48-
status,
49-
}
50-
}
51-
5226
const TerminalPage: FC<
5327
React.PropsWithChildren<{
5428
readonly renderer?: XTerm.RendererType
@@ -100,6 +74,7 @@ const TerminalPage: FC<
10074
applicationsHost,
10175
} = terminalState.context
10276
const reloading = useReloading(isDisconnected)
77+
const startupWarning = useStartupWarning(workspaceAgent)
10378

10479
// handleWebLink handles opening of URLs in the terminal!
10580
const handleWebLink = useCallback(
@@ -309,12 +284,70 @@ const TerminalPage: FC<
309284
</Stack>
310285
)}
311286
</div>
287+
{startupWarning.shouldDisplay && (
288+
<div className={styles.alert} role="alert">
289+
<WarningIcon className={styles.alertIcon} />
290+
<div>
291+
<div className={styles.alertTitle}>
292+
Startup script is still running
293+
</div>
294+
<div className={styles.alertMessage}>
295+
You can use it but dotfiles aren&lsquo;t setup yet
296+
</div>
297+
</div>
298+
</div>
299+
)}
312300
<div className={styles.terminal} ref={xtermRef} data-testid="terminal" />
313301
</>
314302
)
315303
}
316304

317-
export default TerminalPage
305+
const useStartupWarning = (agent?: WorkspaceAgent) => {
306+
const [shouldDisplay, setShouldDisplay] = useState(false)
307+
308+
useEffect(() => {
309+
if (agent) {
310+
setShouldDisplay(
311+
["starting", "starting_timeout", "start_error"].includes(
312+
agent.lifecycle_state,
313+
),
314+
)
315+
}
316+
}, [agent])
317+
318+
return {
319+
shouldDisplay,
320+
dismiss: () => setShouldDisplay(false),
321+
}
322+
}
323+
324+
const useReloading = (isDisconnected: boolean) => {
325+
const [status, setStatus] = useState<"reloading" | "notReloading">(
326+
"notReloading",
327+
)
328+
329+
// Retry connection on key press when it is disconnected
330+
useEffect(() => {
331+
if (!isDisconnected) {
332+
return
333+
}
334+
335+
const keyDownHandler = () => {
336+
setStatus("reloading")
337+
window.location.reload()
338+
}
339+
340+
document.addEventListener("keydown", keyDownHandler)
341+
342+
return () => {
343+
document.removeEventListener("keydown", keyDownHandler)
344+
}
345+
}, [isDisconnected])
346+
347+
return {
348+
status,
349+
}
350+
}
318351

319352
const useStyles = makeStyles((theme) => ({
320353
overlay: {
@@ -348,6 +381,8 @@ const useStyles = makeStyles((theme) => ({
348381
width: "100vw",
349382
height: "100vh",
350383
overflow: "hidden",
384+
padding: theme.spacing(1),
385+
backgroundColor: theme.palette.background.paper,
351386
// These styles attempt to mimic the VS Code scrollbar.
352387
"& .xterm": {
353388
padding: 4,
@@ -370,4 +405,26 @@ const useStyles = makeStyles((theme) => ({
370405
backgroundColor: "rgba(255, 255, 255, 0.18)",
371406
},
372407
},
408+
alert: {
409+
display: "flex",
410+
background: theme.palette.background.paperLight,
411+
alignItems: "center",
412+
padding: theme.spacing(2),
413+
gap: theme.spacing(2),
414+
borderBottom: `1px solid ${theme.palette.divider}`,
415+
},
416+
alertIcon: {
417+
color: theme.palette.warning.light,
418+
fontSize: theme.spacing(3),
419+
},
420+
alertTitle: {
421+
fontWeight: 600,
422+
color: theme.palette.text.primary,
423+
},
424+
alertMessage: {
425+
fontSize: 14,
426+
color: theme.palette.text.secondary,
427+
},
373428
}))
429+
430+
export default TerminalPage

0 commit comments

Comments
 (0)