@@ -17,7 +17,7 @@ import { terminalMachine } from "../../xServices/terminal/terminalXService"
17
17
import { useProxy } from "contexts/ProxyContext"
18
18
import Box from "@mui/material/Box"
19
19
import { useDashboard } from "components/Dashboard/DashboardProvider"
20
- import { Region } from "api/typesGenerated"
20
+ import { Region , WorkspaceAgent } from "api/typesGenerated"
21
21
import { getLatencyColor } from "utils/latency"
22
22
import Popover from "@mui/material/Popover"
23
23
import { ProxyStatusLatency } from "components/ProxyStatusLatency/ProxyStatusLatency"
@@ -29,6 +29,46 @@ export const Language = {
29
29
websocketErrorMessagePrefix : "WebSocket failed: " ,
30
30
}
31
31
32
+ const useTerminalWarning = ( {
33
+ agent,
34
+ fitAddon,
35
+ } : {
36
+ agent ?: WorkspaceAgent
37
+ fitAddon : FitAddon | null
38
+ } ) => {
39
+ const lifecycleState = agent ?. lifecycle_state
40
+ const [ startupWarning , setStartupWarning ] = useState <
41
+ TerminalPageAlertType | undefined
42
+ > ( undefined )
43
+ const shouldDisplayWarning = startupWarning !== undefined
44
+
45
+ useEffect ( ( ) => {
46
+ if ( lifecycleState === "start_error" ) {
47
+ setStartupWarning ( "error" )
48
+ } else if ( lifecycleState === "starting" ) {
49
+ setStartupWarning ( "starting" )
50
+ } else {
51
+ setStartupWarning ( ( prev ) => {
52
+ if ( prev === "starting" ) {
53
+ return "success"
54
+ }
55
+ return undefined
56
+ } )
57
+ }
58
+ } , [ lifecycleState ] )
59
+
60
+ // Resize the terminal when the warning toggles
61
+ useEffect ( ( ) => {
62
+ if ( fitAddon ) {
63
+ fitAddon . fit ( )
64
+ }
65
+ } , [ shouldDisplayWarning , fitAddon ] )
66
+
67
+ return {
68
+ startupWarning,
69
+ }
70
+ }
71
+
32
72
const TerminalPage : FC = ( ) => {
33
73
const navigate = useNavigate ( )
34
74
const styles = useStyles ( )
@@ -77,32 +117,16 @@ const TerminalPage: FC = () => {
77
117
websocketError,
78
118
} = terminalState . context
79
119
const reloading = useReloading ( isDisconnected )
80
- const lifecycleState = workspaceAgent ?. lifecycle_state
81
- const [ startupWarning , setStartupWarning ] = useState <
82
- TerminalPageAlertType | undefined
83
- > ( undefined )
84
-
85
- useEffect ( ( ) => {
86
- if ( lifecycleState === "start_error" ) {
87
- setStartupWarning ( "error" )
88
- } else if ( lifecycleState === "starting" ) {
89
- setStartupWarning ( "starting" )
90
- } else {
91
- setStartupWarning ( ( prev ) => {
92
- if ( prev === "starting" ) {
93
- return "success"
94
- }
95
- return undefined
96
- } )
97
- }
98
- } , [ lifecycleState ] )
99
-
100
120
const dashboard = useDashboard ( )
101
121
const proxyContext = useProxy ( )
102
122
const selectedProxy = proxyContext . proxy . proxy
103
123
const latency = selectedProxy
104
124
? proxyContext . proxyLatencies [ selectedProxy . id ]
105
125
: undefined
126
+ const { startupWarning } = useTerminalWarning ( {
127
+ agent : workspaceAgent ,
128
+ fitAddon,
129
+ } )
106
130
107
131
// handleWebLink handles opening of URLs in the terminal!
108
132
const handleWebLink = useCallback (
0 commit comments