Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another set of fixes #130

Merged
merged 6 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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.

File renamed without changes.
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 style={{ margin: '0 5px', color: '#aaa' }}>/</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch.

</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;
}
171 changes: 171 additions & 0 deletions src/components/forms/ForkExerciseForm/ForkExerciseForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
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
}))
)}
disabled
/>}
</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"
/>
)
}}
disabled
/>
</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';
6 changes: 5 additions & 1 deletion src/components/forms/SubmitButton/SubmitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SubmitButton extends Component {
invalid,
asyncValidating = false,
noIcons = false,
disabled = false,
messages: {
submit: submitMsg = (
<FormattedMessage
Expand Down Expand Up @@ -91,7 +92,9 @@ class SubmitButton extends Component {
: hasFailed ? 'danger' : dirty ? 'warning' : 'success'
}
className="btn-flat"
disabled={invalid || asyncValidating !== false || submitting}
disabled={
invalid || asyncValidating !== false || submitting || disabled
}
>
{!submitting
? hasSucceeded
Expand Down Expand Up @@ -128,6 +131,7 @@ SubmitButton.propTypes = {
asyncValidating: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
noIcons: PropTypes.bool,
invalid: PropTypes.bool,
disabled: PropTypes.bool,
reset: PropTypes.func,
messages: PropTypes.shape({
submit: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
Expand Down
Loading