Skip to content

Commit 349c453

Browse files
committed
Adding select/clear all buttons to group selection in collective assignment creation form.
1 parent 4a18de0 commit 349c453

File tree

2 files changed

+79
-18
lines changed

2 files changed

+79
-18
lines changed

src/components/forms/EditAssignmentForm/AssignmentFormGroupsList.js

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ import { injectIntl, FormattedMessage } from 'react-intl';
44
import { Field } from 'redux-form';
55

66
import { CheckboxField } from '../Fields';
7-
import Icon from '../../icons';
8-
import Button from '../../widgets/TheButton';
7+
import Icon, { SquareIcon } from '../../icons';
8+
import Button, { TheButtonGroup } from '../../widgets/TheButton';
99
import { getGroupCanonicalLocalizedName } from '../../../helpers/localizedData.js';
1010

11-
const AssignmentFormGroupsList = ({ groups, groupsAccessor, isOpen, toggleOpenState, intl: { locale } }) => (
11+
const AssignmentFormGroupsList = ({
12+
groups,
13+
groupsAccessor,
14+
isOpen,
15+
toggleOpenState,
16+
selectAllGroupsHandler,
17+
clearAllGroupsHandler,
18+
intl: { locale },
19+
}) => (
1220
<>
1321
{groups.map((group, i) => (
1422
<Field
@@ -20,21 +28,35 @@ const AssignmentFormGroupsList = ({ groups, groupsAccessor, isOpen, toggleOpenSt
2028
))}
2129

2230
<div className="text-center">
23-
{toggleOpenState !== null && (
24-
<Button size="xs" variant="primary" onClick={toggleOpenState}>
25-
{isOpen ? (
26-
<span>
27-
<Icon icon="minus-square" gapRight={2} />
28-
<FormattedMessage id="app.multiAssignForm.showMyGroups" defaultMessage="Show My Groups Only" />
29-
</span>
30-
) : (
31-
<span>
32-
<Icon icon="plus-square" gapRight={2} />
33-
<FormattedMessage id="app.multiAssignForm.showAllGroups" defaultMessage="Show All Groups" />
34-
</span>
35-
)}
36-
</Button>
37-
)}
31+
<TheButtonGroup>
32+
{Boolean(selectAllGroupsHandler) && (
33+
<Button onClick={selectAllGroupsHandler} variant="primary" size="sm">
34+
<SquareIcon checked gapRight={2} />
35+
<FormattedMessage id="generic.selectAll" defaultMessage="Select All" />
36+
</Button>
37+
)}
38+
{Boolean(clearAllGroupsHandler) && (
39+
<Button onClick={clearAllGroupsHandler} variant="primary" size="sm">
40+
<SquareIcon gapRight={2} />
41+
<FormattedMessage id="generic.clearAll" defaultMessage="Clear All" />
42+
</Button>
43+
)}
44+
{toggleOpenState !== null && (
45+
<Button size="sm" variant="secondary" onClick={toggleOpenState}>
46+
{isOpen ? (
47+
<span>
48+
<Icon icon="minus-square" gapRight={2} />
49+
<FormattedMessage id="app.multiAssignForm.showMyGroups" defaultMessage="Show My Groups Only" />
50+
</span>
51+
) : (
52+
<span>
53+
<Icon icon="plus-square" gapRight={2} />
54+
<FormattedMessage id="app.multiAssignForm.showAllGroups" defaultMessage="Show All Groups" />
55+
</span>
56+
)}
57+
</Button>
58+
)}
59+
</TheButtonGroup>
3860
</div>
3961
<hr />
4062
</>
@@ -45,6 +67,8 @@ AssignmentFormGroupsList.propTypes = {
4567
groupsAccessor: PropTypes.func.isRequired,
4668
isOpen: PropTypes.bool.isRequired,
4769
toggleOpenState: PropTypes.func,
70+
selectAllGroupsHandler: PropTypes.func,
71+
clearAllGroupsHandler: PropTypes.func,
4872
intl: PropTypes.object.isRequired,
4973
};
5074

src/components/forms/EditAssignmentForm/EditAssignmentForm.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,41 @@ class EditAssignmentForm extends Component {
294294
this.props.change('maxPointsBeforeSecondDeadline', maxPointsBeforeSecondDeadline);
295295
};
296296

297+
selectAllGroups = () => {
298+
this.clearAllGroups(); // clears really all
299+
300+
const {
301+
change,
302+
groups,
303+
userId,
304+
groupsAccessor,
305+
intl: { locale },
306+
} = this.props;
307+
308+
// checks only those visible
309+
const visibleGroups = this.state.open
310+
? getAllGroups(groups, groupsAccessor, locale)
311+
: getUserGroups(groups, userId, groupsAccessor, locale);
312+
313+
visibleGroups.forEach(group => {
314+
change(`groups.id${group.id}`, true);
315+
});
316+
};
317+
318+
clearAllGroups = () => {
319+
const {
320+
change,
321+
groups,
322+
groupsAccessor,
323+
intl: { locale },
324+
} = this.props;
325+
326+
const visibleGroups = getAllGroups(groups, groupsAccessor, locale);
327+
visibleGroups.forEach(group => {
328+
change(`groups.id${group.id}`, false);
329+
});
330+
};
331+
297332
/**
298333
* Wraps the onSubmit callback passed from the parent component.
299334
* (note that submitHandler in which this function is used is redux-form internal routine to handle submits)
@@ -376,6 +411,8 @@ class EditAssignmentForm extends Component {
376411
? this.toggleOpenState
377412
: null
378413
}
414+
selectAllGroupsHandler={this.selectAllGroups}
415+
clearAllGroupsHandler={this.clearAllGroups}
379416
/>
380417
)}
381418

0 commit comments

Comments
 (0)