Path: blob/trunk/javascript/grid-ui/src/screens/Sessions/Sessions.tsx
2887 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617import React, { useEffect } from 'react'18import RunningSessions from '../../components/RunningSessions/RunningSessions'19import { useQuery } from '@apollo/client'20import { loader } from 'graphql.macro'21import Grid from '@mui/material/Grid'22import QueuedSessions from '../../components/QueuedSessions/QueuedSessions'23import NoData from '../../components/NoData/NoData'24import Loading from '../../components/Loading/Loading'25import Error from '../../components/Error/Error'26import { GridConfig } from '../../config'27import {GRID_SESSIONS_QUERY} from "../../graphql/sessions";28import { useNavigate, useParams } from 'react-router-dom'2930function Sessions (): JSX.Element {31const { loading, error, data } = useQuery(GRID_SESSIONS_QUERY, {32pollInterval: GridConfig.status.xhrPollingIntervalMillis,33fetchPolicy: 'network-only'34})35const navigate = useNavigate()3637const { sessionId } = useParams<{ sessionId: string }>()3839useEffect(() => {40if (data === undefined || data.sessionsInfo === undefined || data.sessionsInfo.sessions === undefined) {41return42}43if (sessionId && data.sessionsInfo.sessions.length === 0) {44navigate("/sessions")45}46}, [data, sessionId])4748if (error !== undefined) {49const message = 'There has been an error while loading running and ' +50'queued Sessions from the Grid.'51const errorMessage = error?.networkError?.message52return (53<Grid container>54<Error message={message} errorMessage={errorMessage} />55</Grid>56)57}5859if (loading) {60return (61<Grid container>62<Loading />63</Grid>64)65}6667if (data.sessionsInfo.sessionQueueRequests.length === 0 &&68data.sessionsInfo.sessions.length === 0) {69const shortMessage = 'No running or queued sessions at the moment.'70return (71<Grid container>72<NoData message={shortMessage} />73</Grid>74)75}7677return (78<Grid container>79<RunningSessions80sessions={data.sessionsInfo.sessions}81origin={window.location.origin}82sessionId={sessionId}83/>84<QueuedSessions85sessionQueueRequests={data.sessionsInfo.sessionQueueRequests}86/>87</Grid>88)89}9091export default Sessions929394