Skip to content

Commit 458887d

Browse files
Make the locust UI responsive
1 parent 73d60fa commit 458887d

File tree

4 files changed

+74
-30
lines changed

4 files changed

+74
-30
lines changed

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

+59-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,72 @@
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 { AppBar, Box, Container, Drawer, IconButton, Link, Toolbar } from '@mui/material';
24

35
import Logo from 'assets/Logo';
46
import DarkLightToggle from 'components/Layout/Navbar/DarkLightToggle';
57
import SwarmMonitor from 'components/Layout/Navbar/SwarmMonitor';
68
import StateButtons from 'components/StateButtons/StateButtons';
79

810
export default function Navbar() {
11+
const [drawerOpen, setDrawerOpen] = useState(false);
12+
13+
const toggleDrawer = (open: boolean) => () => {
14+
setDrawerOpen(open);
15+
};
16+
917
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'
18+
<>
19+
<AppBar position='static'>
20+
<Container maxWidth='xl'>
21+
<Toolbar
22+
disableGutters
23+
sx={{ display: 'flex', justifyContent: 'space-between', columnGap: 2 }}
1824
>
19-
<Logo />
20-
</Link>
21-
<Box sx={{ display: 'flex', columnGap: 6 }}>
22-
<SwarmMonitor />
23-
<StateButtons />
25+
<Link
26+
color='inherit'
27+
href='/'
28+
sx={{ display: 'flex', alignItems: 'center' }}
29+
underline='none'
30+
>
31+
<Logo />
32+
</Link>
33+
<IconButton
34+
aria-label='menu'
35+
color='inherit'
36+
edge='start'
37+
onClick={toggleDrawer(true)}
38+
sx={{ display: { xs: 'block', md: 'none' } }}
39+
>
40+
<MenuIcon />
41+
</IconButton>
42+
43+
<Box sx={{ display: { xs: 'none', md: 'flex' }, columnGap: { md: 2, lg: 6 } }}>
44+
<SwarmMonitor />
45+
<StateButtons />
46+
<DarkLightToggle />
47+
</Box>
48+
</Toolbar>
49+
</Container>
50+
</AppBar>
51+
52+
<Drawer anchor='right' onClose={toggleDrawer(false)} open={drawerOpen}>
53+
<Box
54+
sx={{
55+
display: 'flex',
56+
flexDirection: 'column',
57+
columnGap: { md: 2, lg: 6 },
58+
rowGap: 2,
59+
p: 2,
60+
maxWidth: '100vw',
61+
}}
62+
>
63+
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
2464
<DarkLightToggle />
2565
</Box>
26-
</Toolbar>
27-
</Container>
28-
</AppBar>
66+
<StateButtons />
67+
<SwarmMonitor />
68+
</Box>
69+
</Drawer>
70+
</>
2971
);
3072
}

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)