Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grid] Add feature to go directly to a VNC session #15179

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions javascript/grid-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function App () {
<Container maxWidth={false} sx={{ paddingY: 4 }}>
<Routes>
<Route path='/sessions' element={<Sessions />} />
<Route path='/session/:sessionId' element={<Sessions />} />
<Route path='/help' element={<Help />} />
<Route path='/' element={<Overview />} />
<Route path='*' element={<Help />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

import React, { useState, useRef } from 'react'
import React, { useState, useRef, useEffect } from 'react'
import Table from '@mui/material/Table'
import TableBody from '@mui/material/TableBody'
import TableCell from '@mui/material/TableCell'
Expand Down Expand Up @@ -50,6 +50,7 @@ import RunningSessionsSearchBar from './RunningSessionsSearchBar'
import { Size } from '../../models/size'
import LiveView from '../LiveView/LiveView'
import SessionData, { createSessionData } from '../../models/session-data'
import { useNavigate } from 'react-router-dom'

function descendingComparator<T> (a: T, b: T, orderBy: keyof T): number {
if (orderBy === 'sessionDurationMillis') {
Expand Down Expand Up @@ -181,12 +182,13 @@ function RunningSessions (props) {
const [searchFilter, setSearchFilter] = useState('')
const [searchBarHelpOpen, setSearchBarHelpOpen] = useState(false)
const liveViewRef = useRef(null)
const navigate = useNavigate()

const handleDialogClose = () => {
if (liveViewRef.current) {
liveViewRef.current.disconnect()
}
setRowLiveViewOpen('')
navigate('/sessions')
}

const handleRequestSort = (event: React.MouseEvent<unknown>,
Expand Down Expand Up @@ -247,7 +249,7 @@ function RunningSessions (props) {

const displayLiveView = (id: string): JSX.Element => {
const handleLiveViewIconClick = (): void => {
setRowLiveViewOpen(id)
navigate(`/session/${id}`)
}
return (
<IconButton
Expand All @@ -260,7 +262,7 @@ function RunningSessions (props) {
)
}

const { sessions, origin } = props
const { sessions, origin, sessionId } = props

const rows = sessions.map((session) => {
return createSessionData(
Expand All @@ -277,6 +279,19 @@ function RunningSessions (props) {
})
const emptyRows = rowsPerPage - Math.min(rowsPerPage, rows.length - page * rowsPerPage)

useEffect(() => {
let s = sessionId || ''

let session_ids = sessions.map((session) => session.id)

if (!session_ids.includes(s)) {
setRowLiveViewOpen('')
navigate('/sessions')
} else {
setRowLiveViewOpen(s)
}
}, [sessionId, sessions])

return (
<Box width='100%'>
{rows.length > 0 && (
Expand Down Expand Up @@ -354,7 +369,7 @@ function RunningSessions (props) {
{
(row.vnc as string).length > 0 &&
<Dialog
onClose={() => setRowLiveViewOpen('')}
onClose={() => navigate("/sessions")}
aria-labelledby='live-view-dialog'
open={rowLiveViewOpen === row.id}
fullWidth
Expand Down Expand Up @@ -393,7 +408,7 @@ function RunningSessions (props) {
ref={liveViewRef}
url={row.vnc as string}
scaleViewport
onClose={() => setRowLiveViewOpen('')}
onClose={() => navigate("/sessions")}
/>
</DialogContent>
<DialogActions>
Expand Down
16 changes: 15 additions & 1 deletion javascript/grid-ui/src/screens/Sessions/Sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

import React from 'react'
import React, { useEffect } from 'react'
import RunningSessions from '../../components/RunningSessions/RunningSessions'
import { useQuery } from '@apollo/client'
import { loader } from 'graphql.macro'
Expand All @@ -26,12 +26,25 @@ import Loading from '../../components/Loading/Loading'
import Error from '../../components/Error/Error'
import { GridConfig } from '../../config'
import {GRID_SESSIONS_QUERY} from "../../graphql/sessions";
import { useNavigate, useParams } from 'react-router-dom'

function Sessions (): JSX.Element {
const { loading, error, data } = useQuery(GRID_SESSIONS_QUERY, {
pollInterval: GridConfig.status.xhrPollingIntervalMillis,
fetchPolicy: 'network-only'
})
const navigate = useNavigate()

const { sessionId } = useParams<{ sessionId: string }>()

useEffect(() => {
if (data === undefined || data.sessionsInfo === undefined || data.sessionsInfo.sessions === undefined) {
return
}
if (sessionId && data.sessionsInfo.sessions.length === 0) {
navigate("/sessions")
}
}, [data, sessionId])

if (error !== undefined) {
const message = 'There has been an error while loading running and ' +
Expand Down Expand Up @@ -67,6 +80,7 @@ function Sessions (): JSX.Element {
<RunningSessions
sessions={data.sessionsInfo.sessions}
origin={window.location.origin}
sessionId={sessionId}
/>
<QueuedSessions
sessionQueueRequests={data.sessionsInfo.sessionQueueRequests}
Expand Down
Loading