-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from ReCodEx/fixes
Another set of fixes
- Loading branch information
Showing
30 changed files
with
655 additions
and
603 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
src/components/Exercises/ForkExerciseButton/FailedForkExerciseButton.js
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/components/Exercises/ForkExerciseButton/ForkExerciseButton.js
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/components/Exercises/ForkExerciseButton/PendingForkExerciseButton.js
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/components/Exercises/ForkExerciseButton/SuccessfulForkExerciseButton.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,8 @@ | |
border-color: #f5f5f5; | ||
color: grey; | ||
} | ||
|
||
.slashStyle { | ||
margin: 0 5px; | ||
color: #aaa; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './HierarchyLine'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
169
src/components/forms/ForkExerciseForm/ForkExerciseForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './ForkExerciseForm'; |
Oops, something went wrong.