Path: blob/trunk/javascript/grid-ui/src/components/NavBar/NavBar.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 Divider from '@mui/material/Divider'18import MuiDrawer from '@mui/material/Drawer'19import IconButton from '@mui/material/IconButton'20import List from '@mui/material/List'21import ListItem from '@mui/material/ListItem'22import ListItemIcon from '@mui/material/ListItemIcon'23import ListItemText from '@mui/material/ListItemText'24import { ChevronLeft as ChevronLeftIcon } from '@mui/icons-material'25import { Dashboard as DashboardIcon } from '@mui/icons-material'26import { Assessment as AssessmentIcon } from '@mui/icons-material'27import { Help as HelpIcon } from '@mui/icons-material'28import React from 'react'29import { Box, Typography } from '@mui/material'30import { useLocation } from 'react-router-dom'31import OverallConcurrency from './OverallConcurrency'32import { CSSObject, styled, Theme } from '@mui/material/styles'3334const drawerWidth = 2403536function ListItemLink (props): JSX.Element {37return <ListItem button component='a' {...props} />38}3940const openedMixin = (theme: Theme): CSSObject => ({41width: drawerWidth,42transition: theme.transitions.create('width', {43easing: theme.transitions.easing.sharp,44duration: theme.transitions.duration.enteringScreen45}),46overflowX: 'hidden'47})4849const closedMixin = (theme: Theme): CSSObject => ({50transition: theme.transitions.create('width', {51easing: theme.transitions.easing.sharp,52duration: theme.transitions.duration.leavingScreen53}),54overflowX: 'hidden',55width: `calc(${theme.spacing(7)} + 1px)`,56[theme.breakpoints.up('sm')]: {57width: `calc(${theme.spacing(8)} + 1px)`58}59})6061const Drawer = styled(MuiDrawer,62{ shouldForwardProp: (prop) => prop !== 'open' })(63({ theme, open }) => ({64width: drawerWidth,65flexShrink: 0,66whiteSpace: 'nowrap',67boxSizing: 'border-box',68...(open && {69...openedMixin(theme),70'& .MuiDrawer-paper': openedMixin(theme)71}),72...(!open && {73...closedMixin(theme),74'& .MuiDrawer-paper': closedMixin(theme)75})76})77)7879function NavBarBottom (props): JSX.Element {80const {81sessionQueueSize,82sessionCount,83maxSession,84nodeCount85} = props86const location = useLocation()87// Not showing the overall status when the user is on the Overview88// page and there is only one node, because polling is not happening89// at the same time, and it could be confusing for the user. So,90// displaying it when there is more than one node, or when the user is91// on a different page and there is at least one node registered.92const showOverallConcurrency =93nodeCount > 1 || (location.pathname !== '/' && nodeCount > 0)9495return (96<div>97<Box p={3} m={1}>98<Typography99align='center'100gutterBottom101variant='h4'102>103Queue size: {sessionQueueSize}104</Typography>105</Box>106{showOverallConcurrency && (107<OverallConcurrency108sessionCount={sessionCount}109maxSession={maxSession}110/>111)}112</div>113)114}115116function NavBar (props) {117const {118open,119maxSession,120sessionCount,121nodeCount,122sessionQueueSize123} = props124125return (126<Drawer127variant='permanent'128open={open}129>130<Box131display='flex'132alignItems='center'133justifyContent='flex-end'134sx={{ bgcolor: 'primary.main' }}135marginTop={2}136>137<IconButton color='secondary' size='large'>138<ChevronLeftIcon />139</IconButton>140</Box>141<Divider />142<List>143<div>144<ListItemLink href='#'>145<ListItemIcon>146<DashboardIcon />147</ListItemIcon>148<ListItemText primary='Overview' />149</ListItemLink>150<ListItemLink href='#/sessions'>151<ListItemIcon>152<AssessmentIcon />153</ListItemIcon>154<ListItemText primary='Sessions' />155</ListItemLink>156<ListItemLink href='#/help'>157<ListItemIcon>158<HelpIcon />159</ListItemIcon>160<ListItemText primary='Help' />161</ListItemLink>162</div>163</List>164<Box flexGrow={1} />165{open && (166<NavBarBottom167sessionQueueSize={sessionQueueSize}168sessionCount={sessionCount}169maxSession={maxSession}170nodeCount={nodeCount}171/>172)}173</Drawer>174)175}176177export default NavBar178179180