@@ -14,7 +14,7 @@ import {
14
14
apiQueryClient ,
15
15
instanceCan ,
16
16
usePrefetchedApiQuery ,
17
- type InstanceState ,
17
+ type Instance ,
18
18
} from '@oxide/api'
19
19
import { PrevArrow12Icon } from '@oxide/design-system/icons/react'
20
20
@@ -53,14 +53,24 @@ SerialConsolePage.loader = async ({ params }: LoaderFunctionArgs) => {
53
53
return null
54
54
}
55
55
56
+ function isStarting ( i : Instance | undefined ) {
57
+ return i ?. runState === 'creating' || i ?. runState === 'starting'
58
+ }
59
+
56
60
export function SerialConsolePage ( ) {
57
61
const instanceSelector = useInstanceSelector ( )
58
62
const { project, instance } = instanceSelector
59
63
60
- const { data : instanceData } = usePrefetchedApiQuery ( 'instanceView' , {
61
- query : { project } ,
62
- path : { instance } ,
63
- } )
64
+ const { data : instanceData } = usePrefetchedApiQuery (
65
+ 'instanceView' ,
66
+ {
67
+ query : { project } ,
68
+ path : { instance } ,
69
+ } ,
70
+ // if we land here and the instance is starting, we will not be able to
71
+ // connect, so we poll and connect as soon as it's running.
72
+ { refetchInterval : ( q ) => ( isStarting ( q . state . data ) ? 1000 : false ) }
73
+ )
64
74
65
75
const ws = useRef < WebSocket | null > ( null )
66
76
@@ -140,7 +150,7 @@ export function SerialConsolePage() {
140
150
{ connectionStatus === 'connecting' && < ConnectingSkeleton /> }
141
151
{ connectionStatus === 'error' && < ErrorSkeleton /> }
142
152
{ connectionStatus === 'closed' && ! canConnect && (
143
- < CannotConnect instanceState = { instanceData . runState } />
153
+ < CannotConnect instance = { instanceData } />
144
154
) }
145
155
{ /* closed && canConnect shouldn't be possible because there's no way to
146
156
* close an open connection other than leaving the page */ }
@@ -161,21 +171,20 @@ export function SerialConsolePage() {
161
171
)
162
172
}
163
173
164
- function SerialSkeleton ( {
165
- children,
166
- connecting,
167
- } : {
174
+ type SkeletonProps = {
168
175
children : React . ReactNode
169
- connecting ?: boolean
170
- } ) {
176
+ animate ?: boolean
177
+ }
178
+
179
+ function SerialSkeleton ( { children, animate } : SkeletonProps ) {
171
180
return (
172
181
< div className = "relative h-full shrink grow overflow-hidden" >
173
182
< div className = "h-full space-y-2 overflow-hidden" >
174
183
{ [ ...Array ( 200 ) ] . map ( ( _e , i ) => (
175
184
< div
176
185
key = { i }
177
186
className = { cn ( 'h-4 rounded bg-tertiary' , {
178
- 'motion-safe:animate-pulse' : connecting ,
187
+ 'motion-safe:animate-pulse' : animate ,
179
188
} ) }
180
189
style = { {
181
190
width : `${ Math . sin ( Math . sin ( i ) ) * 20 + 40 } %` ,
@@ -198,22 +207,24 @@ function SerialSkeleton({
198
207
}
199
208
200
209
const ConnectingSkeleton = ( ) => (
201
- < SerialSkeleton connecting >
210
+ < SerialSkeleton animate >
202
211
< Spinner size = "lg" />
203
212
< div className = "mt-4 text-center" >
204
213
< p className = "text-sans-xl" > Connecting to serial console</ p >
205
214
</ div >
206
215
</ SerialSkeleton >
207
216
)
208
217
209
- const CannotConnect = ( { instanceState } : { instanceState : InstanceState } ) => (
210
- < SerialSkeleton >
218
+ const CannotConnect = ( { instance } : { instance : Instance } ) => (
219
+ < SerialSkeleton animate = { isStarting ( instance ) } >
211
220
< p className = "flex items-center justify-center text-sans-xl" >
212
- < span > The instance is</ span >
213
- < InstanceStatusBadge className = "ml-1" status = { instanceState } />
221
+ < span > The instance is </ span >
222
+ < InstanceStatusBadge className = "ml-1.5 " status = { instance . runState } />
214
223
</ p >
215
- < p className = "mt-2 text-center text-secondary" >
216
- You can only connect to the serial console on a running instance.
224
+ < p className = "mt-2 text-balance text-center text-secondary" >
225
+ { isStarting ( instance )
226
+ ? 'Waiting for the instance to start before connecting.'
227
+ : 'You can only connect to the serial console on a running instance.' }
217
228
</ p >
218
229
</ SerialSkeleton >
219
230
)
0 commit comments