Skip to content

Commit 7e5b0a0

Browse files
emilhemVietND96pujagani
authored
[grid] Add feature to go directly to a VNC session (#15179)
* [grid] Add feature to go directly to a VNC session Users can now go directly to a VNC session if they have the session ID. This makes it easier to create direct links to a running session which can make it easier to fault trace a running session. Fixes #15178 * Simplify sessionId check logic --------- Co-authored-by: Viet Nguyen Duc <[email protected]> Co-authored-by: Puja Jagani <[email protected]>
1 parent 0135df2 commit 7e5b0a0

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

javascript/grid-ui/src/App.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function App () {
104104
<Container maxWidth={false} sx={{ paddingY: 4 }}>
105105
<Routes>
106106
<Route path='/sessions' element={<Sessions />} />
107+
<Route path='/session/:sessionId' element={<Sessions />} />
107108
<Route path='/help' element={<Help />} />
108109
<Route path='/' element={<Overview />} />
109110
<Route path='*' element={<Help />} />

javascript/grid-ui/src/components/RunningSessions/RunningSessions.tsx

+21-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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'
1919
import Table from '@mui/material/Table'
2020
import TableBody from '@mui/material/TableBody'
2121
import TableCell from '@mui/material/TableCell'
@@ -50,6 +50,7 @@ import RunningSessionsSearchBar from './RunningSessionsSearchBar'
5050
import { Size } from '../../models/size'
5151
import LiveView from '../LiveView/LiveView'
5252
import SessionData, { createSessionData } from '../../models/session-data'
53+
import { useNavigate } from 'react-router-dom'
5354

5455
function 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>

javascript/grid-ui/src/screens/Sessions/Sessions.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import React from 'react'
18+
import React, { useEffect } from 'react'
1919
import RunningSessions from '../../components/RunningSessions/RunningSessions'
2020
import { useQuery } from '@apollo/client'
2121
import { loader } from 'graphql.macro'
@@ -26,12 +26,25 @@ import Loading from '../../components/Loading/Loading'
2626
import Error from '../../components/Error/Error'
2727
import { GridConfig } from '../../config'
2828
import {GRID_SESSIONS_QUERY} from "../../graphql/sessions";
29+
import { useNavigate, useParams } from 'react-router-dom'
2930

3031
function Sessions (): JSX.Element {
3132
const { loading, error, data } = useQuery(GRID_SESSIONS_QUERY, {
3233
pollInterval: GridConfig.status.xhrPollingIntervalMillis,
3334
fetchPolicy: 'network-only'
3435
})
36+
const navigate = useNavigate()
37+
38+
const { sessionId } = useParams<{ sessionId: string }>()
39+
40+
useEffect(() => {
41+
if (data === undefined || data.sessionsInfo === undefined || data.sessionsInfo.sessions === undefined) {
42+
return
43+
}
44+
if (sessionId && data.sessionsInfo.sessions.length === 0) {
45+
navigate("/sessions")
46+
}
47+
}, [data, sessionId])
3548

3649
if (error !== undefined) {
3750
const message = 'There has been an error while loading running and ' +
@@ -67,6 +80,7 @@ function Sessions (): JSX.Element {
6780
<RunningSessions
6881
sessions={data.sessionsInfo.sessions}
6982
origin={window.location.origin}
83+
sessionId={sessionId}
7084
/>
7185
<QueuedSessions
7286
sessionQueueRequests={data.sessionsInfo.sessionQueueRequests}

0 commit comments

Comments
 (0)