Path: blob/trunk/javascript/grid-ui/src/components/QueuedSessions/QueuedSessions.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 * as React from 'react'18import {19Box, Button,20Dialog, DialogActions, DialogContent,21DialogTitle,22IconButton,23} from '@mui/material'24import EnhancedTableToolbar from '../EnhancedTableToolbar'25import OsLogo from '../common/OsLogo'26import { Size } from '../../models/size'27import BrowserLogo from '../common/BrowserLogo'28import browserVersion from '../../util/browser-version'29import Grid from '@mui/material/Grid';30import { experimentalStyled as styled } from '@mui/material/styles';31import Paper from '@mui/material/Paper';32import { Info as InfoIcon } from '@mui/icons-material'33import { useState } from 'react'34import Typography from '@mui/material/Typography'3536const Item = styled(Paper)(({ theme }) => ({37backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',38...theme.typography.body2,39padding: theme.spacing(2),40textAlign: 'center',41color: theme.palette.text.secondary,42}));4344function QueuedSessions (props) {45const [itemOpen, setItemOpen] = useState('')46const { sessionQueueRequests } = props47const queue = sessionQueueRequests.map((sessionQueueRequest) => {48return JSON.parse(sessionQueueRequest)49});5051const displayRequestInfo = (id: string): JSX.Element => {52const handleInfoIconClick = (): void => {53setItemOpen(id)54}55return (56<IconButton57sx={{ padding: '1px' }}58onClick={handleInfoIconClick}59size='large'60>61<InfoIcon />62</IconButton>63)64}6566return (67<Box68paddingTop='30px'69width='100%'70bgcolor='background.paper'71marginTop='30px'72marginBottom='20px'73sx={{flexGrow: 1}}74>75{queue.length > 0 && (76<Box minWidth='750px'>77<EnhancedTableToolbar title={`Queue (${queue.length})`} />78<Grid container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}>79{queue.map((queueItem, index) => (80<Grid item xs={2} sm={4} md={4} key={index}>81<Item>82{displayRequestInfo(index as string)}83{(queueItem.platformName ?? '' as string).length > 0 &&84<OsLogo85osName={queueItem.platformName as string}86size={Size.S}87/>88}89{(queueItem.browserName ?? '' as string).length > 0 &&90<BrowserLogo91browserName={queueItem.browserName as string}92/>93}94{browserVersion(queueItem.browserVersion as string)}95<Dialog96onClose={() => setItemOpen('')}97aria-labelledby='session-info-dialog'98open={itemOpen === index}99fullWidth100maxWidth='md'101>102<DialogTitle id='session-info-dialog'>103<Typography104gutterBottom component='span'105sx={{ paddingX: '10px' }}106>107<Box108fontWeight='fontWeightBold'109mr={1}110display='inline'111>112Session Request113</Box>114</Typography>115{(queueItem.platformName ?? '' as string).length > 0 &&116<OsLogo117osName={queueItem.platformName as string}118size={Size.S}119/>120}121{(queueItem.browserName ?? '' as string).length > 0 &&122<BrowserLogo123browserName={queueItem.browserName as string}124/>125}126{browserVersion(queueItem.browserVersion as string)}127</DialogTitle>128<DialogContent dividers>129<Typography gutterBottom>130Capabilities:131</Typography>132<Typography gutterBottom component='span'>133<pre>134{JSON.stringify(queueItem,null, 2)}135</pre>136</Typography>137</DialogContent>138<DialogActions>139<Button140onClick={() => setItemOpen('')}141color='primary'142variant='contained'143>144Close145</Button>146</DialogActions>147</Dialog>148</Item>149</Grid>150))}151</Grid>152</Box>153)}154</Box>155)156}157158export default QueuedSessions159160161