Skip to content

Commit

Permalink
Edit simple exercise configuration form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Dec 1, 2017
1 parent 671ed62 commit 8df5b4c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,78 @@ EditExerciseSimpleConfigForm.propTypes = {
exerciseTests: PropTypes.array
};

const validate = () => {
const validate = ({ config }) => {
const errors = {};

const configErrors = {};
for (let i = 0; i < config.length; ++i) {
const test = config[i];
const testErrors = {};

if (!test.expectedOutput || test.expectedOutput === '') {
testErrors['expectedOutput'] = (
<FormattedMessage
id="app.editExerciseSimpleConfigForm.validation.expectedOutput"
defaultMessage="Please fill the expected output file."
/>
);
}

if (test.useOutFile && (!test.outputFile || test.outputFile === '')) {
testErrors['outputFile'] = (
<FormattedMessage
id="app.editExerciseSimpleConfigForm.validation.outputFile"
defaultMessage="Please fill the name of the output file or use standard input instead."
/>
);
}

if (!test.judgeBinary || test.judgeBinary === '') {
testErrors['judgeBinary'] = (
<FormattedMessage
id="app.editExerciseSimpleConfigForm.validation.judgeBinary"
defaultMessage="Please select the judge type for this test."
/>
);
}

if (
test.useCustomJudge &&
(!test.customJudgeBinary || test.customJudgeBinary === '')
) {
testErrors['customJudgeBinary'] = (
<FormattedMessage
id="app.editExerciseSimpleConfigForm.validation.customJudge"
defaultMessage="Please select the custom judge binary for this test or use one of the standard judges instead."
/>
);
}

const inputErrorMessage = (
<FormattedMessage
id="app.editExerciseSimpleConfigForm.validation.inputFilesNotPaired"
defaultMessage="Input files are not properly paired with their names. Please make sure each file has a name."
/>
);
for (const inputFilePair of test.inputFiles) {
if (
(!inputFilePair.first || inputFilePair.first === '') &&
inputFilePair.second !== ''
) {
testErrors['inputFiles'] = inputErrorMessage;
}
if (
(!inputFilePair.second || inputFilePair.second === '') &&
inputFilePair.first !== ''
) {
testErrors['inputFiles'] = inputErrorMessage;
}
}

configErrors[i] = testErrors;
}
errors['config'] = configErrors;

return errors;
};

Expand Down
45 changes: 20 additions & 25 deletions src/components/forms/Fields/ExpandingInputFilesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ExpandingInputFilesField extends Component {
const {
leftLabel = '',
rightLabel = '',
input: { onChange },
input: { onChange, ...input },
meta: { touched, error },
style = {},
options,
Expand All @@ -69,15 +69,15 @@ class ExpandingInputFilesField extends Component {
const { texts } = this.state;

return (
<Row>
<Col sm={6}>
<FormGroup
controlId={'first'}
validationState={
error ? (touched ? 'error' : 'warning') : undefined
}
>
<ControlLabel>{leftLabel}</ControlLabel>
<FormGroup
controlId={input.name}
validationState={error ? (touched ? 'error' : 'warning') : undefined}
>
<Row>
<Col sm={6}>
<ControlLabel>
{leftLabel}
</ControlLabel>
<div style={style}>
{texts.map((text, i) =>
<FormControl
Expand All @@ -96,17 +96,12 @@ class ExpandingInputFilesField extends Component {
)}
</FormControl>
)}
</div>{' '}
</FormGroup>
</Col>
<Col sm={6}>
<FormGroup
controlId={'second'}
validationState={
error ? (touched ? 'error' : 'warning') : undefined
}
>
<ControlLabel>{rightLabel}</ControlLabel>
</div>
</Col>
<Col sm={6}>
<ControlLabel>
{rightLabel}
</ControlLabel>
<div style={style}>
{texts.map((text, i) =>
<FormControl
Expand All @@ -119,9 +114,9 @@ class ExpandingInputFilesField extends Component {
{...props}
/>
)}
</div>{' '}
</FormGroup>
</Col>
</div>
</Col>
</Row>
{error &&
<HelpBlock>
{' '}{touched
Expand All @@ -131,7 +126,7 @@ class ExpandingInputFilesField extends Component {
id="app.field.isRequired"
/>}{' '}
</HelpBlock>}
</Row>
</FormGroup>
);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/exerciseSimpleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ export const transformAndSendConfigValues = (
environments,
setConfig
) => {
console.log(environments);
console.log(pipelines);

let testVars = [];
for (const test of formData.config) {
let variables = [];
Expand Down

0 comments on commit 8df5b4c

Please sign in to comment.