Path: blob/trunk/javascript/grid-ui/src/components/Node/NodeLoad.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 { Box, Grid, Typography } from '@mui/material'18import React from 'react'19import LinearProgress, {20LinearProgressProps21} from '@mui/material/LinearProgress'2223function LinearProgressWithLabel (props: LinearProgressProps & { value: number }): JSX.Element {24return (25<Box display='flex' alignItems='center'>26<Box width='100%' mr={1}>27<LinearProgress variant='determinate' {...props} />28</Box>29<Box minWidth={35}>30<Typography variant='body2' color='textSecondary'>31{`${Math.round(props.value)}%`}32</Typography>33</Box>34</Box>35)36}3738function NodeLoad (props) {39const { node } = props40const sessionCount = node.sessionCount ?? 041const currentLoad = sessionCount === 042? 043: Math.min(((sessionCount / node.maxSession) * 100), 100).toFixed(2)4445return (46<Grid item xs={12}>47<Grid48container49justifyContent='space-between'50spacing={2}51>52<Grid item xs={3}>53<Box pt={1} mt={2}>54<Typography55variant='body2'56gutterBottom57>58Sessions: {sessionCount}59</Typography>60</Box>61</Grid>62<Grid item xs={9}>63<Box pt={1} mt={2}>64<Typography65variant='body2'66gutterBottom67>68Max. Concurrency: {node.maxSession}69</Typography>70</Box>71</Grid>72<Grid item xs={12}>73<LinearProgressWithLabel value={Number(currentLoad)} />74</Grid>75</Grid>76</Grid>77)78}7980export default NodeLoad818283