1515// specific language governing permissions and limitations
1616// under the License.
1717
18- import React , { useState , useRef } from 'react'
18+ import React , { useState , useRef , useEffect } from 'react'
1919import Table from '@mui/material/Table'
2020import TableBody from '@mui/material/TableBody'
2121import TableCell from '@mui/material/TableCell'
@@ -50,6 +50,7 @@ import RunningSessionsSearchBar from './RunningSessionsSearchBar'
5050import { Size } from '../../models/size'
5151import LiveView from '../LiveView/LiveView'
5252import SessionData , { createSessionData } from '../../models/session-data'
53+ import { useNavigate } from 'react-router-dom'
5354
5455function descendingComparator < T > ( a : T , b : T , orderBy : keyof T ) : number {
5556 if ( orderBy === 'sessionDurationMillis' ) {
@@ -181,12 +182,13 @@ function RunningSessions (props) {
181182 const [ searchFilter , setSearchFilter ] = useState ( '' )
182183 const [ searchBarHelpOpen , setSearchBarHelpOpen ] = useState ( false )
183184 const liveViewRef = useRef ( null )
185+ const navigate = useNavigate ( )
184186
185187 const handleDialogClose = ( ) => {
186188 if ( liveViewRef . current ) {
187189 liveViewRef . current . disconnect ( )
188190 }
189- setRowLiveViewOpen ( ' ')
191+ navigate ( '/sessions ')
190192 }
191193
192194 const handleRequestSort = ( event : React . MouseEvent < unknown > ,
@@ -247,7 +249,7 @@ function RunningSessions (props) {
247249
248250 const displayLiveView = ( id : string ) : JSX . Element => {
249251 const handleLiveViewIconClick = ( ) : void => {
250- setRowLiveViewOpen ( id )
252+ navigate ( `/session/ ${ id } ` )
251253 }
252254 return (
253255 < IconButton
@@ -260,7 +262,7 @@ function RunningSessions (props) {
260262 )
261263 }
262264
263- const { sessions, origin } = props
265+ const { sessions, origin, sessionId } = props
264266
265267 const rows = sessions . map ( ( session ) => {
266268 return createSessionData (
@@ -277,6 +279,19 @@ function RunningSessions (props) {
277279 } )
278280 const emptyRows = rowsPerPage - Math . min ( rowsPerPage , rows . length - page * rowsPerPage )
279281
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+
280295 return (
281296 < Box width = '100%' >
282297 { rows . length > 0 && (
@@ -354,7 +369,7 @@ function RunningSessions (props) {
354369 {
355370 ( row . vnc as string ) . length > 0 &&
356371 < Dialog
357- onClose = { ( ) => setRowLiveViewOpen ( '' ) }
372+ onClose = { ( ) => navigate ( "/sessions" ) }
358373 aria-labelledby = 'live-view-dialog'
359374 open = { rowLiveViewOpen === row . id }
360375 fullWidth
@@ -393,7 +408,7 @@ function RunningSessions (props) {
393408 ref = { liveViewRef }
394409 url = { row . vnc as string }
395410 scaleViewport
396- onClose = { ( ) => setRowLiveViewOpen ( '' ) }
411+ onClose = { ( ) => navigate ( "/sessions" ) }
397412 />
398413 </ DialogContent >
399414 < DialogActions >
0 commit comments