Skip to content

Commit

Permalink
Merge pull request #130 from ReCodEx/fixes
Browse files Browse the repository at this point in the history
Another set of fixes
  • Loading branch information
SemaiCZE committed Nov 3, 2017
2 parents 35cdc0a + 96f63ea commit 32b2eab
Show file tree
Hide file tree
Showing 30 changed files with 655 additions and 603 deletions.

This file was deleted.

41 changes: 0 additions & 41 deletions src/components/Exercises/ForkExerciseButton/ForkExerciseButton.js

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/components/Exercises/ForkExerciseButton/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
border-color: #f5f5f5;
color: grey;
}

.slashStyle {
margin: 0 5px;
color: #aaa;
}
26 changes: 26 additions & 0 deletions src/components/Groups/HierarchyLine/HierarchyLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Well } from 'react-bootstrap';
import GroupsNameContainer from '../../../containers/GroupsNameContainer';

import './HierarchyLine.css';

const HierarchyLine = ({ groupId, parentGroupsIds }) =>
<Well bsSize="sm" className="groupParents">
{parentGroupsIds.map(
(groupId, i) =>
i !== 0 &&
<span key={i}>
<GroupsNameContainer groupId={groupId} />{' '}
<span className="slashStyle">/</span>
</span>
)}
<GroupsNameContainer groupId={groupId} noLink />
</Well>;

HierarchyLine.propTypes = {
groupId: PropTypes.string.isRequired,
parentGroupsIds: PropTypes.array
};

export default HierarchyLine;
1 change: 1 addition & 0 deletions src/components/Groups/HierarchyLine/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './HierarchyLine';
1 change: 1 addition & 0 deletions src/components/Submissions/TestResults/TestResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const TestResults = ({ evaluation, runtimeEnvironmentId }) =>
noPadding={true}
collapsable={true}
isOpen={true}
unlimitedHeight
>
<TestResultsTable
results={evaluation.testResults}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EditExerciseConfigForm extends Component {

componentWillReceiveProps(newProps) {
if (this.props.exercise.id !== newProps.exercise.id) {
this.setState({ testConfigs: newProps.initialValues.config });
newProps.fetchFiles();
}
}
Expand All @@ -36,11 +37,9 @@ class EditExerciseConfigForm extends Component {
if (!testConfig.tests) {
testConfig.tests = [];
}
testConfig.tests = testConfig.tests.concat([
{
name: 'Test ' + (testConfig.tests.length + 1)
}
]);
testConfig.tests.push({
name: 'Test ' + (testConfig.tests.length + 1)
});
return testConfig;
})
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/forms/ForkExerciseForm/ForkExerciseForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.formSpace {
padding-left: 10px;
display: flex;
}
169 changes: 169 additions & 0 deletions src/components/forms/ForkExerciseForm/ForkExerciseForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl, FormattedMessage } from 'react-intl';
import { Alert, Form } from 'react-bootstrap';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { reduxForm, Field } from 'redux-form';
import { SelectField } from '../Fields';
import SubmitButton from '../SubmitButton';
import Button from '../../../components/widgets/FlatButton';
import { SuccessIcon } from '../../../components/icons';
import { forkStatuses } from '../../../redux/modules/exercises';
import { getFork } from '../../../redux/selectors/exercises';
import ResourceRenderer from '../../helpers/ResourceRenderer';

import withLinks from '../../../hoc/withLinks';

import './ForkExerciseForm.css';

class ForkExerciseForm extends Component {
viewForkedExercise() {
const {
forkedExerciseId: id,
push,
links: { EXERCISE_URI_FACTORY }
} = this.props;

const url = EXERCISE_URI_FACTORY(id);
push(url);
}

render() {
const {
forkStatus,
anyTouched,
submitting,
handleSubmit,
hasFailed = false,
hasSucceeded = false,
invalid,
groups,
intl
} = this.props;

switch (forkStatus) {
case forkStatuses.FULFILLED:
return (
<Button
bsStyle="success"
bsSize="sm"
className="btn-flat"
onClick={() => this.viewForkedExercise()}
>
<SuccessIcon />{' '}
<FormattedMessage
id="app.forkExerciseButton.success"
defaultMessage="Show the forked exercise"
/>
</Button>
);
default:
return (
<div>
{hasFailed &&
<Alert bsStyle="danger">
<FormattedMessage
id="app.forkExerciseForm.failed"
defaultMessage="Saving failed. Please try again later."
/>
</Alert>}
<Form inline className="formSpace">
<ResourceRenderer resource={groups.toArray()}>
{(...groups) =>
<Field
name={'groupId'}
component={SelectField}
label={''}
options={[{ key: '', name: '_Public_' }].concat(
groups
.sort((a, b) =>
a.name.localeCompare(b.name, intl.locale)
)
.filter((item, pos, arr) => arr.indexOf(item) === pos)
.map(group => ({
key: group.id,
name: group.name
}))
)}
/>}
</ResourceRenderer>

<SubmitButton
id="forkExercise"
invalid={invalid}
submitting={submitting}
hasSucceeded={hasSucceeded}
dirty={anyTouched}
hasFailed={hasFailed}
handleSubmit={handleSubmit}
noIcons
messages={{
submit: (
<FormattedMessage
id="app.forkExerciseForm.submit"
defaultMessage="Fork exercise"
/>
),
submitting: (
<FormattedMessage
id="app.forkExerciseForm.submitting"
defaultMessage="Forking ..."
/>
),
success: (
<FormattedMessage
id="app.forkExerciseForm.success"
defaultMessage="Exercise forked"
/>
)
}}
/>
</Form>
</div>
);
}
}
}

ForkExerciseForm.propTypes = {
exerciseId: PropTypes.string.isRequired,
forkId: PropTypes.string.isRequired,
forkStatus: PropTypes.string,
forkedExerciseId: PropTypes.string,
anyTouched: PropTypes.bool,
submitting: PropTypes.bool,
hasFailed: PropTypes.bool,
hasSucceeded: PropTypes.bool,
invalid: PropTypes.bool,
handleSubmit: PropTypes.func.isRequired,
push: PropTypes.func.isRequired,
links: PropTypes.object,
groups: ImmutablePropTypes.map,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

const mapStateToProps = (state, { exerciseId, forkId }) => {
const fork = getFork(exerciseId, forkId)(state);
return {
forkStatus: fork ? fork.status : null,
forkedExerciseId:
fork && fork.status === forkStatuses.FULFILLED ? fork.exerciseId : null
};
};

const mapDispatchToProps = (dispatch, { exerciseId, forkId }) => ({
push: url => dispatch(push(url))
});

const validate = () => {};

export default withLinks(
connect(mapStateToProps, mapDispatchToProps)(
reduxForm({
form: 'forkExercise',
validate
})(injectIntl(ForkExerciseForm))
)
);
1 change: 1 addition & 0 deletions src/components/forms/ForkExerciseForm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './ForkExerciseForm';
Loading

0 comments on commit 32b2eab

Please sign in to comment.