Skip to content

Commit 0d3b486

Browse files
committed
Moving add test button to the top of the form so it will not be scrolled away when pressed.
1 parent ca8a7f6 commit 0d3b486

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

src/components/forms/EditTestsForm/EditTestsForm.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Box from '../../widgets/Box';
1414
import Button, { TheButtonGroup } from '../../widgets/TheButton';
1515
import Callout from '../../widgets/Callout';
1616
import OptionalTooltipWrapper from '../../widgets/OptionalTooltipWrapper';
17-
import Icon, { AddIcon, CloseIcon, SaveIcon, RefreshIcon, WarningIcon } from '../../icons';
17+
import Icon, { CloseIcon, SaveIcon, RefreshIcon, WarningIcon } from '../../icons';
1818
import {
1919
UNIFORM_ID,
2020
WEIGHTED_ID,
@@ -99,14 +99,25 @@ class EditTestsForm extends Component {
9999
this.props.registerExtraData && this.props.registerExtraData(this.getAst().getRoot());
100100
};
101101

102+
addNewTest = () => {
103+
const { change, formValues } = this.props;
104+
change('tests', [
105+
...formValues.tests,
106+
{
107+
id: this.getUniqueId(),
108+
name: 'Test ' + (formValues.tests.length + 1).toString().padStart(2, '0'),
109+
weight: '100',
110+
},
111+
]);
112+
};
113+
102114
render() {
103115
const {
104116
calculator = UNIFORM_ID,
105117
readOnly = false,
106118
dirty,
107119
submitting,
108120
handleSubmit,
109-
change,
110121
submitFailed,
111122
submitSucceeded,
112123
invalid,
@@ -155,29 +166,12 @@ class EditTestsForm extends Component {
155166
readOnly={readOnly}
156167
usedTests={this.getUsedTests()}
157168
calculator={calculator}
169+
addNewTest={this.addNewTest}
158170
/>
159171

160172
{!readOnly && (
161173
<div className="text-center">
162174
<TheButtonGroup>
163-
{formValues && formValues.tests.length < 99 && (
164-
<Button
165-
onClick={() =>
166-
change('tests', [
167-
...formValues.tests,
168-
{
169-
id: this.getUniqueId(),
170-
name: 'Test ' + (formValues.tests.length + 1).toString().padStart(2, '0'),
171-
weight: '100',
172-
},
173-
])
174-
}
175-
variant="primary">
176-
<AddIcon gapRight />
177-
<FormattedMessage id="app.editTestsTest.add" defaultMessage="Add Test" />
178-
</Button>
179-
)}
180-
181175
{(dirty || (this.getAst() && this.getAst().canUndo())) && !submitting && (
182176
<Button type="reset" onClick={this.reset} variant="danger">
183177
<RefreshIcon gapRight />

src/components/forms/EditTestsForm/EditTestsTest.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { FormattedMessage } from 'react-intl';
66

77
import EditTestsTestRow from './EditTestsTestRow';
88
import Callout from '../../widgets/Callout';
9+
import Button from '../../widgets/TheButton';
10+
import { AddIcon } from '../../icons';
911
import { prettyPrintPercent } from '../../helpers/stringFormatters';
1012
import { safeGet } from '../../../helpers/common';
1113
import { WEIGHTED_ID, UNIVERSAL_ID } from '../../../helpers/exercise/testsAndScore';
1214

13-
const EditTestsTest = ({ fields, calculator, testValues, usedTests, readOnly = false }) => {
15+
const EditTestsTest = ({ fields, calculator, testValues, usedTests, addNewTest, readOnly = false }) => {
1416
const weightSum = Math.max(
1517
1, // make sure the sum is not zero (it is used in division)
1618
calculator === WEIGHTED_ID
@@ -37,7 +39,16 @@ const EditTestsTest = ({ fields, calculator, testValues, usedTests, readOnly = f
3739
<FormattedMessage id="app.editTestsTest.pointsPercentage" defaultMessage="Points Percentage:" />
3840
</th>
3941
)}
40-
{!readOnly && <th />}
42+
{!readOnly && addNewTest && (
43+
<th className="valign-middle text-right">
44+
{fields.length < 99 && (
45+
<Button onClick={addNewTest} variant="primary" size="xs">
46+
<AddIcon gapRight />
47+
<FormattedMessage id="app.editTestsTest.add" defaultMessage="Add Test" />
48+
</Button>
49+
)}
50+
</th>
51+
)}
4152
</tr>
4253
</thead>
4354
<tbody>
@@ -72,6 +83,7 @@ EditTestsTest.propTypes = {
7283
calculator: PropTypes.string,
7384
testValues: PropTypes.array,
7485
usedTests: PropTypes.object,
86+
addNewTest: PropTypes.func,
7587
};
7688

7789
export default formValues({

0 commit comments

Comments
 (0)