-
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 #122 from ReCodEx/score_config
WIP: Score config
- Loading branch information
Showing
9 changed files
with
196 additions
and
36 deletions.
There are no files selected for viewing
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
94 changes: 94 additions & 0 deletions
94
src/components/forms/EditScoreConfigForm/EditScoreConfigForm.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,94 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { canUseDOM } from 'exenv'; | ||
import { reduxForm, Field } from 'redux-form'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Alert } from 'react-bootstrap'; | ||
|
||
import { SourceCodeField } from '../Fields'; | ||
import SubmitButton from '../SubmitButton'; | ||
|
||
if (canUseDOM) { | ||
require('codemirror/mode/yaml/yaml'); | ||
} | ||
|
||
const EditScoreConfigForm = ({ | ||
anyTouched, | ||
submitting, | ||
handleSubmit, | ||
hasFailed = false, | ||
hasSucceeded = false, | ||
invalid | ||
}) => | ||
<div> | ||
{hasFailed && | ||
<Alert bsStyle="danger"> | ||
<FormattedMessage | ||
id="app.editScoreConfigForm.failed" | ||
defaultMessage="Saving failed. Please try again later." | ||
/> | ||
</Alert>} | ||
|
||
<Field | ||
name="scoreConfig" | ||
component={SourceCodeField} | ||
mode="yaml" | ||
label={ | ||
<FormattedMessage | ||
id="app.editScoreConfigForm.scoreConfig" | ||
defaultMessage="Score configuration:" | ||
/> | ||
} | ||
/> | ||
|
||
<div className="text-center"> | ||
<SubmitButton | ||
id="editEnvironmentConfig" | ||
invalid={invalid} | ||
submitting={submitting} | ||
hasSucceeded={hasSucceeded} | ||
dirty={anyTouched} | ||
hasFailed={hasFailed} | ||
handleSubmit={handleSubmit} | ||
messages={{ | ||
submit: ( | ||
<FormattedMessage | ||
id="app.editScoreConfigForm.submit" | ||
defaultMessage="Change configuration" | ||
/> | ||
), | ||
submitting: ( | ||
<FormattedMessage | ||
id="app.editScoreConfigForm.submitting" | ||
defaultMessage="Saving configuration ..." | ||
/> | ||
), | ||
success: ( | ||
<FormattedMessage | ||
id="app.editScoreConfigForm.success" | ||
defaultMessage="Configuration was changed." | ||
/> | ||
) | ||
}} | ||
/> | ||
</div> | ||
</div>; | ||
|
||
EditScoreConfigForm.propTypes = { | ||
handleSubmit: PropTypes.func.isRequired, | ||
anyTouched: PropTypes.bool, | ||
submitting: PropTypes.bool, | ||
hasFailed: PropTypes.bool, | ||
hasSucceeded: PropTypes.bool, | ||
invalid: PropTypes.bool | ||
}; | ||
|
||
const validate = () => { | ||
const errors = {}; | ||
return errors; | ||
}; | ||
|
||
export default reduxForm({ | ||
form: 'editScoreConfig', | ||
validate | ||
})(EditScoreConfigForm); |
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 './EditScoreConfigForm'; |
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,19 @@ | ||
import { handleActions } from 'redux-actions'; | ||
import factory, { initialState } from '../helpers/resourceManager'; | ||
|
||
/** | ||
* Create actions & reducer | ||
*/ | ||
|
||
const resourceName = 'exerciseScoreConfig'; | ||
const { actions, reduceActions } = factory({ | ||
resourceName, | ||
apiEndpointFactory: id => `/exercises/${id}/score-config` | ||
}); | ||
|
||
export const fetchScoreConfig = actions.fetchResource; | ||
export const fetchScoreConfigIfNeeded = actions.fetchOneIfNeeded; | ||
export const setScoreConfig = actions.updateResource; | ||
|
||
const reducer = handleActions(reduceActions, initialState); | ||
export default reducer; |
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,14 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
const getExerciseScoreConfig = state => state.exerciseScoreConfig; | ||
const getResources = exerciseScoreConfig => | ||
exerciseScoreConfig.get('resources'); | ||
|
||
export const exerciseScoreConfigsSelector = createSelector( | ||
getExerciseScoreConfig, | ||
getResources | ||
); | ||
export const exerciseScoreConfigSelector = exerciseId => | ||
createSelector(exerciseScoreConfigsSelector, configs => | ||
configs.get(exerciseId) | ||
); |