Skip to content

Commit 90adee6

Browse files
committed
Improving how some buttons (tests and runtime environments) are displayed on exercise config page.
1 parent 8abad50 commit 90adee6

File tree

2 files changed

+63
-53
lines changed

2 files changed

+63
-53
lines changed

src/components/forms/EditEnvironmentSimpleForm/EditEnvironmentSimpleForm.js

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,43 +117,49 @@ class EditEnvironmentSimpleForm extends Component {
117117

118118
{error && <Callout variant="danger">{error}</Callout>}
119119

120-
<div className="text-center">
121-
<TheButtonGroup>
122-
{dirty && (
123-
<Button type="reset" onClick={reset} variant={'danger'}>
124-
<RefreshIcon gapRight />
125-
<FormattedMessage id="generic.reset" defaultMessage="Reset" />
126-
</Button>
127-
)}
128-
129-
<SubmitButton
130-
id="editTests"
131-
invalid={invalid}
132-
submitting={submitting}
133-
hasSucceeded={submitSucceeded}
134-
dirty={dirty}
135-
hasFailed={submitFailed}
136-
handleSubmit={handleSubmit}
137-
messages={{
138-
submit: (
139-
<FormattedMessage id="app.editEnvironmentSimpleForm.submit" defaultMessage="Save Environments" />
140-
),
141-
submitting: (
142-
<FormattedMessage
143-
id="app.editEnvironmentSimpleForm.submitting"
144-
defaultMessage="Saving Environments..."
145-
/>
146-
),
147-
success: (
148-
<FormattedMessage
149-
id="app.editEnvironmentSimpleForm.success"
150-
defaultMessage="Environments Saved."
151-
/>
152-
),
153-
}}
154-
/>
155-
</TheButtonGroup>
156-
</div>
120+
{(!invalid || dirty) && (
121+
<div className="text-center">
122+
<TheButtonGroup>
123+
{dirty && (
124+
<Button type="reset" onClick={reset} variant={'danger'}>
125+
<RefreshIcon gapRight />
126+
<FormattedMessage id="generic.reset" defaultMessage="Reset" />
127+
</Button>
128+
)}
129+
130+
{!invalid && (
131+
<SubmitButton
132+
id="editTests"
133+
submitting={submitting}
134+
hasSucceeded={submitSucceeded}
135+
dirty={dirty}
136+
hasFailed={submitFailed}
137+
handleSubmit={handleSubmit}
138+
messages={{
139+
submit: (
140+
<FormattedMessage
141+
id="app.editEnvironmentSimpleForm.submit"
142+
defaultMessage="Save Environments"
143+
/>
144+
),
145+
submitting: (
146+
<FormattedMessage
147+
id="app.editEnvironmentSimpleForm.submitting"
148+
defaultMessage="Saving Environments..."
149+
/>
150+
),
151+
success: (
152+
<FormattedMessage
153+
id="app.editEnvironmentSimpleForm.success"
154+
defaultMessage="Environments Saved."
155+
/>
156+
),
157+
}}
158+
/>
159+
)}
160+
</TheButtonGroup>
161+
</div>
162+
)}
157163
</>
158164
) : (
159165
<>

src/components/forms/EditTestsForm/EditTestsForm.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class EditTestsForm extends Component {
122122
submitSucceeded,
123123
invalid,
124124
formValues,
125+
initialValues,
125126
} = this.props;
126127

127128
return (
@@ -188,6 +189,7 @@ class EditTestsForm extends Component {
188189
hasFailed={submitFailed}
189190
handleSubmit={handleSubmit}
190191
defaultIcon={<SaveIcon gapRight />}
192+
disabled={formValues.tests.length === 0}
191193
messages={{
192194
submit: <FormattedMessage id="app.editTestsForm.submit" defaultMessage="Save Tests" />,
193195
submitting: (
@@ -197,22 +199,24 @@ class EditTestsForm extends Component {
197199
}}
198200
/>
199201

200-
<OptionalTooltipWrapper
201-
tooltip={
202-
<FormattedMessage
203-
id="app.editTestsForm.changeCalculatorDisabledTooltip"
204-
defaultMessage="The scoring algorithm may be changed only when there are no unsaved modifications in this form."
205-
/>
206-
}
207-
hide={!dirty}>
208-
<Button onClick={this.openDialog} variant={dirty ? 'secondary' : 'primary'} disabled={dirty}>
209-
<Icon icon="calculator" gapRight />
210-
<FormattedMessage
211-
id="app.editTestsForm.changeCalculator"
212-
defaultMessage="Scoring Algorithm"
213-
/>
214-
</Button>
215-
</OptionalTooltipWrapper>
202+
{initialValues.tests.length > 0 && (
203+
<OptionalTooltipWrapper
204+
tooltip={
205+
<FormattedMessage
206+
id="app.editTestsForm.changeCalculatorDisabledTooltip"
207+
defaultMessage="The scoring algorithm may be changed only when there are no unsaved modifications in this form."
208+
/>
209+
}
210+
hide={!dirty}>
211+
<Button onClick={this.openDialog} variant={dirty ? 'secondary' : 'primary'} disabled={dirty}>
212+
<Icon icon="calculator" gapRight />
213+
<FormattedMessage
214+
id="app.editTestsForm.changeCalculator"
215+
defaultMessage="Scoring Algorithm"
216+
/>
217+
</Button>
218+
</OptionalTooltipWrapper>
219+
)}
216220
</TheButtonGroup>
217221

218222
<Modal show={this.state.dialogOpen} backdrop="static" onHide={this.closeDialog} size="xl">

0 commit comments

Comments
 (0)