Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Select All / None Checkbox to User Class Picker #2590

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locust/webui/dist/assets/auth-0ef39448.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion locust/webui/dist/assets/auth-e7925d10.js.map

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion locust/webui/dist/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />

<title>Locust</title>
<script type="module" crossorigin src="/assets/index-dc1c0e5b.js"></script>
<script type="module" crossorigin src="/assets/index-e80c0bba.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion locust/webui/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />

<title>Locust</title>
<script type="module" crossorigin src="/assets/index-dc1c0e5b.js"></script>
<script type="module" crossorigin src="/assets/index-e80c0bba.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
1 change: 1 addition & 0 deletions locust/webui/src/components/SwarmForm/SwarmForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function SwarmForm({
{showUserclassPicker && (
<Box marginBottom={2} marginTop={2}>
<SwarmUserClassPicker
availableUserClasses={availableUserClasses}
selectedUserClasses={selectedUserClasses}
setSelectedUserClasses={setSelectedUserClasses}
/>
Expand Down
27 changes: 25 additions & 2 deletions locust/webui/src/components/SwarmForm/SwarmUserClassPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TableBody,
TableContainer,
Paper,
TableHead,
} from '@mui/material';
import { connect } from 'react-redux';

Expand All @@ -33,7 +34,7 @@ interface IDispatchProps {

interface IUserClassPicker
extends IDispatchProps,
Pick<ISwarmState, 'availableUserTasks' | 'users'> {
Pick<ISwarmState, 'availableUserClasses' | 'availableUserTasks' | 'users'> {
selectedUserClasses: string[];
setSelectedUserClasses: (userClasses: string[]) => void;
}
Expand Down Expand Up @@ -76,6 +77,7 @@ function SwarmUserForm({ availableTasks, userToEdit, handleEditUser }: ISwarmUse
}

function SwarmUserClassPicker({
availableUserClasses,
availableUserTasks,
selectedUserClasses,
setSelectedUserClasses,
Expand Down Expand Up @@ -105,6 +107,14 @@ function SwarmUserClassPicker({
? setSelectedUserClasses(selectedUserClasses.filter(n => n !== name))
: setSelectedUserClasses(selectedUserClasses.concat(name));

const checkboxesSelected = selectedUserClasses.length;
const checkboxesTotal = availableUserClasses.length;

const onSelectAllClick = (event: React.ChangeEvent<HTMLInputElement>) =>
event.target.checked
? setSelectedUserClasses(availableUserClasses)
: setSelectedUserClasses([]);

return (
<>
<Box
Expand Down Expand Up @@ -139,11 +149,24 @@ function SwarmUserClassPicker({
<FormGroup>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell colSpan={4} padding='checkbox'>
<Checkbox
checked={checkboxesTotal > 0 && checkboxesSelected === checkboxesTotal}
indeterminate={
checkboxesSelected > 0 && checkboxesSelected < checkboxesTotal
}
onChange={onSelectAllClick}
/>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{Object.entries(users).map(([name, userClass]) => (
<TableRow hover key={`user-class-${name}`}>
<TableCell onClick={handleToggleUserSelected(name)} padding='checkbox'>
<Checkbox defaultChecked />
<Checkbox checked={selectedUserClasses.includes(name)} />
</TableCell>

<TableCell>{name}</TableCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('SwarmForm', () => {
});

act(() => {
fireEvent.click(getAllByRole('checkbox')[1]);
fireEvent.click(getAllByRole('checkbox')[2]);
});
act(() => {
fireEvent.click(getByText('Start Swarm'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const availableUserTasks = Object.entries(mockUsers).reduce(
);

const defaultProps = {
availableUserClasses: ['Example', 'ExampleTwo'],
selectedUserClasses: Object.keys(mockUsers),
setSelectedUserClasses: updateSelectedClasses,
setSwarm: updateSwarm,
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('SwarmUserClassPicker', () => {
});

act(() => {
fireEvent.click(getAllByRole('checkbox')[0]);
fireEvent.click(getAllByRole('checkbox')[1]);
});

expect(updateSelectedClasses.mock.calls[0][0]).toEqual([Object.keys(mockUsers)[1]]);
Expand Down
Loading