15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
- import React , { useState , useRef } from 'react'
18
+ import React , { useState , useRef , useEffect } from 'react'
19
19
import Table from '@mui/material/Table'
20
20
import TableBody from '@mui/material/TableBody'
21
21
import TableCell from '@mui/material/TableCell'
@@ -50,6 +50,7 @@ import RunningSessionsSearchBar from './RunningSessionsSearchBar'
50
50
import { Size } from '../../models/size'
51
51
import LiveView from '../LiveView/LiveView'
52
52
import SessionData , { createSessionData } from '../../models/session-data'
53
+ import { useNavigate } from 'react-router-dom'
53
54
54
55
function descendingComparator < T > ( a : T , b : T , orderBy : keyof T ) : number {
55
56
if ( orderBy === 'sessionDurationMillis' ) {
@@ -181,12 +182,13 @@ function RunningSessions (props) {
181
182
const [ searchFilter , setSearchFilter ] = useState ( '' )
182
183
const [ searchBarHelpOpen , setSearchBarHelpOpen ] = useState ( false )
183
184
const liveViewRef = useRef ( null )
185
+ const navigate = useNavigate ( )
184
186
185
187
const handleDialogClose = ( ) => {
186
188
if ( liveViewRef . current ) {
187
189
liveViewRef . current . disconnect ( )
188
190
}
189
- setRowLiveViewOpen ( ' ')
191
+ navigate ( '/sessions ')
190
192
}
191
193
192
194
const handleRequestSort = ( event : React . MouseEvent < unknown > ,
@@ -247,7 +249,7 @@ function RunningSessions (props) {
247
249
248
250
const displayLiveView = ( id : string ) : JSX . Element => {
249
251
const handleLiveViewIconClick = ( ) : void => {
250
- setRowLiveViewOpen ( id )
252
+ navigate ( `/session/ ${ id } ` )
251
253
}
252
254
return (
253
255
< IconButton
@@ -260,7 +262,7 @@ function RunningSessions (props) {
260
262
)
261
263
}
262
264
263
- const { sessions, origin } = props
265
+ const { sessions, origin, sessionId } = props
264
266
265
267
const rows = sessions . map ( ( session ) => {
266
268
return createSessionData (
@@ -277,6 +279,19 @@ function RunningSessions (props) {
277
279
} )
278
280
const emptyRows = rowsPerPage - Math . min ( rowsPerPage , rows . length - page * rowsPerPage )
279
281
282
+ useEffect ( ( ) => {
283
+ let s = sessionId || ''
284
+
285
+ let session_ids = sessions . map ( ( session ) => session . id )
286
+
287
+ if ( ! session_ids . includes ( s ) ) {
288
+ setRowLiveViewOpen ( '' )
289
+ navigate ( '/sessions' )
290
+ } else {
291
+ setRowLiveViewOpen ( s )
292
+ }
293
+ } , [ sessionId , sessions ] )
294
+
280
295
return (
281
296
< Box width = '100%' >
282
297
{ rows . length > 0 && (
@@ -354,7 +369,7 @@ function RunningSessions (props) {
354
369
{
355
370
( row . vnc as string ) . length > 0 &&
356
371
< Dialog
357
- onClose = { ( ) => setRowLiveViewOpen ( '' ) }
372
+ onClose = { ( ) => navigate ( "/sessions" ) }
358
373
aria-labelledby = 'live-view-dialog'
359
374
open = { rowLiveViewOpen === row . id }
360
375
fullWidth
@@ -393,7 +408,7 @@ function RunningSessions (props) {
393
408
ref = { liveViewRef }
394
409
url = { row . vnc as string }
395
410
scaleViewport
396
- onClose = { ( ) => setRowLiveViewOpen ( '' ) }
411
+ onClose = { ( ) => navigate ( "/sessions" ) }
397
412
/>
398
413
</ DialogContent >
399
414
< DialogActions >
0 commit comments