Skip to content

Commit 100c0e9

Browse files
Make the locust UI responsive
1 parent 73d60fa commit 100c0e9

File tree

4 files changed

+85
-30
lines changed

4 files changed

+85
-30
lines changed

Diff for: locust/webui/src/components/Layout/Navbar/Navbar.tsx

+70-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,83 @@
1-
import { AppBar, Box, Container, Link, Toolbar } from '@mui/material';
1+
import { useState } from 'react';
2+
import MenuIcon from '@mui/icons-material/Menu';
3+
import {
4+
AppBar,
5+
Box,
6+
Container,
7+
Drawer,
8+
IconButton,
9+
Link,
10+
List,
11+
ListItem,
12+
ListItemText,
13+
Toolbar,
14+
} from '@mui/material';
215

316
import Logo from 'assets/Logo';
417
import DarkLightToggle from 'components/Layout/Navbar/DarkLightToggle';
518
import SwarmMonitor from 'components/Layout/Navbar/SwarmMonitor';
619
import StateButtons from 'components/StateButtons/StateButtons';
720

821
export default function Navbar() {
22+
const [drawerOpen, setDrawerOpen] = useState(false);
23+
24+
const toggleDrawer = (open: boolean) => () => {
25+
setDrawerOpen(open);
26+
};
27+
928
return (
10-
<AppBar position='static'>
11-
<Container maxWidth='xl'>
12-
<Toolbar disableGutters sx={{ display: 'flex', justifyContent: 'space-between', columnGap: 2 }}>
13-
<Link
14-
color='inherit'
15-
href='/'
16-
sx={{ display: 'flex', alignItems: 'center' }}
17-
underline='none'
29+
<>
30+
<AppBar position='static'>
31+
<Container maxWidth='xl'>
32+
<Toolbar
33+
disableGutters
34+
sx={{ display: 'flex', justifyContent: 'space-between', columnGap: 2 }}
1835
>
19-
<Logo />
20-
</Link>
21-
<Box sx={{ display: 'flex', columnGap: 6 }}>
22-
<SwarmMonitor />
23-
<StateButtons />
36+
<Link
37+
color='inherit'
38+
href='/'
39+
sx={{ display: 'flex', alignItems: 'center' }}
40+
underline='none'
41+
>
42+
<Logo />
43+
</Link>
44+
<IconButton
45+
aria-label='menu'
46+
color='inherit'
47+
edge='start'
48+
onClick={toggleDrawer(true)}
49+
sx={{ display: { xs: 'block', md: 'none' } }}
50+
>
51+
<MenuIcon />
52+
</IconButton>
53+
54+
<Box sx={{ display: { xs: 'none', md: 'flex' }, columnGap: { md: 2, lg: 6 } }}>
55+
<SwarmMonitor />
56+
<StateButtons />
57+
<DarkLightToggle />
58+
</Box>
59+
</Toolbar>
60+
</Container>
61+
</AppBar>
62+
63+
<Drawer anchor='right' onClose={toggleDrawer(false)} open={drawerOpen}>
64+
<Box
65+
sx={{
66+
display: 'flex',
67+
flexDirection: 'column',
68+
columnGap: { md: 2, lg: 6 },
69+
rowGap: 2,
70+
p: 2,
71+
maxWidth: '100vw',
72+
}}
73+
>
74+
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
2475
<DarkLightToggle />
2576
</Box>
26-
</Toolbar>
27-
</Container>
28-
</AppBar>
77+
<StateButtons />
78+
<SwarmMonitor />
79+
</Box>
80+
</Drawer>
81+
</>
2982
);
3083
}

Diff for: locust/webui/src/components/Layout/Navbar/SwarmMonitor.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ function SwarmMonitor({
2020
workerCount,
2121
}: ISwarmMonitor) {
2222
return (
23-
<Box sx={{ display: 'flex', columnGap: 2 }}>
23+
<Box
24+
sx={{ display: 'flex', columnGap: 2, rowGap: 1, flexDirection: { xs: 'column', md: 'row' } }}
25+
>
2426
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
2527
<Typography variant='button'>Host</Typography>
2628
<Tooltip title={host}>
@@ -29,7 +31,7 @@ function SwarmMonitor({
2931
sx={{
3032
overflow: 'hidden',
3133
textOverflow: 'ellipsis',
32-
maxWidth: '400px',
34+
maxWidth: { xs: '180px', lg: '400px' },
3335
}}
3436
>
3537
{host}
@@ -44,7 +46,7 @@ function SwarmMonitor({
4446
{(state === SWARM_STATE.RUNNING || state === SWARM_STATE.SPAWNING) && (
4547
<>
4648
<Divider flexItem orientation='vertical' />
47-
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
49+
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: { md: 'center' } }}>
4850
<Typography variant='button'>Users</Typography>
4951
<Typography noWrap variant='button'>
5052
{userCount}
@@ -55,7 +57,7 @@ function SwarmMonitor({
5557
{isDistributed && (
5658
<>
5759
<Divider flexItem orientation='vertical' />
58-
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
60+
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: { md: 'center' } }}>
5961
<Typography variant='button'>Workers</Typography>
6062
<Typography noWrap variant='button'>
6163
{workerCount}
@@ -64,14 +66,14 @@ function SwarmMonitor({
6466
</>
6567
)}
6668
<Divider flexItem orientation='vertical' />
67-
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
69+
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: { md: 'center' } }}>
6870
<Typography variant='button'>RPS</Typography>
6971
<Typography noWrap variant='button'>
7072
{totalRps}
7173
</Typography>
7274
</Box>
7375
<Divider flexItem orientation='vertical' />
74-
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
76+
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: { md: 'center' } }}>
7577
<Typography variant='button'>Failures</Typography>
7678
<Typography noWrap variant='button'>{`${failRatio}%`}</Typography>
7779
</Box>

Diff for: locust/webui/src/components/Table/Table.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ export default function Table<Row extends Record<string, any> = Record<string, s
6262
});
6363

6464
return (
65-
<TableContainer
66-
component={Paper}
67-
sx={{
68-
overflowX: 'visible',
69-
}}
70-
>
65+
<TableContainer component={Paper}>
7166
<MuiTable>
7267
<TableHead
7368
sx={{

Diff for: locust/webui/src/components/Tabs/Tabs.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ function Tabs({ currentTabIndexFromQuery, notification, setNotification, setUrl,
6060
return (
6161
<Container maxWidth='xl'>
6262
<Box sx={{ mb: 2 }}>
63-
<MuiTabs onChange={onTabChange} value={currentTabIndex}>
63+
<MuiTabs
64+
onChange={onTabChange}
65+
scrollButtons='auto'
66+
value={currentTabIndex}
67+
variant='scrollable'
68+
>
6469
{tabs.map(({ key: tabKey, title }, index) => (
6570
<MuiTab
6671
key={`tab-${index}`}

0 commit comments

Comments
 (0)