Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/grid-ui/src/screens/Sessions/Sessions.tsx
2887 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
import React, { useEffect } from 'react'
19
import RunningSessions from '../../components/RunningSessions/RunningSessions'
20
import { useQuery } from '@apollo/client'
21
import { loader } from 'graphql.macro'
22
import Grid from '@mui/material/Grid'
23
import QueuedSessions from '../../components/QueuedSessions/QueuedSessions'
24
import NoData from '../../components/NoData/NoData'
25
import Loading from '../../components/Loading/Loading'
26
import Error from '../../components/Error/Error'
27
import { GridConfig } from '../../config'
28
import {GRID_SESSIONS_QUERY} from "../../graphql/sessions";
29
import { useNavigate, useParams } from 'react-router-dom'
30
31
function Sessions (): JSX.Element {
32
const { loading, error, data } = useQuery(GRID_SESSIONS_QUERY, {
33
pollInterval: GridConfig.status.xhrPollingIntervalMillis,
34
fetchPolicy: 'network-only'
35
})
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])
48
49
if (error !== undefined) {
50
const message = 'There has been an error while loading running and ' +
51
'queued Sessions from the Grid.'
52
const errorMessage = error?.networkError?.message
53
return (
54
<Grid container>
55
<Error message={message} errorMessage={errorMessage} />
56
</Grid>
57
)
58
}
59
60
if (loading) {
61
return (
62
<Grid container>
63
<Loading />
64
</Grid>
65
)
66
}
67
68
if (data.sessionsInfo.sessionQueueRequests.length === 0 &&
69
data.sessionsInfo.sessions.length === 0) {
70
const shortMessage = 'No running or queued sessions at the moment.'
71
return (
72
<Grid container>
73
<NoData message={shortMessage} />
74
</Grid>
75
)
76
}
77
78
return (
79
<Grid container>
80
<RunningSessions
81
sessions={data.sessionsInfo.sessions}
82
origin={window.location.origin}
83
sessionId={sessionId}
84
/>
85
<QueuedSessions
86
sessionQueueRequests={data.sessionsInfo.sessionQueueRequests}
87
/>
88
</Grid>
89
)
90
}
91
92
export default Sessions
93
94