Skip to content

Commit

Permalink
Disable accept button on pending action
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Oct 25, 2017
1 parent c826e2b commit ebcbce3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import Icon from 'react-fontawesome';
import Staus from './Status';
import Status from './Status';

const AssignmentStatusIcon = ({ id, status, accepted = false }) => {
switch (status) {
case 'done':
return (
<Staus
<Status
id={id}
accepted={accepted}
icon={<Icon name="thumbs-o-up" className="text-green" />}
Expand All @@ -23,7 +23,7 @@ const AssignmentStatusIcon = ({ id, status, accepted = false }) => {

case 'work-in-progress':
return (
<Staus
<Status
id={id}
icon={<Icon name="cogs" className="text-yellow" />}
message={
Expand All @@ -37,7 +37,7 @@ const AssignmentStatusIcon = ({ id, status, accepted = false }) => {

case 'failed':
return (
<Staus
<Status
id={id}
icon={<Icon name="thumbs-o-down" className="text-red" />}
message={
Expand All @@ -51,7 +51,7 @@ const AssignmentStatusIcon = ({ id, status, accepted = false }) => {

case 'evaluation-failed':
return (
<Staus
<Status
id={id}
icon={<Icon name="exclamation-triangle" className="text-yellow" />}
message={
Expand All @@ -65,7 +65,7 @@ const AssignmentStatusIcon = ({ id, status, accepted = false }) => {

default:
return (
<Staus
<Status
id={id}
icon={<Icon name="code" className="text-gray" />}
message={
Expand Down
11 changes: 6 additions & 5 deletions src/components/buttons/AcceptSolution/AcceptSolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import { FormattedMessage } from 'react-intl';
import Icon from 'react-fontawesome';
import Button from '../../widgets/FlatButton';

const AcceptSolution = ({ accepted, accept, unaccept }) =>
const AcceptSolution = ({ accepted, acceptPending, accept, unaccept }) =>
accepted === true
? <Button bsStyle="info" onClick={unaccept}>
? <Button bsStyle="info" onClick={unaccept} disabled={acceptPending}>
<Icon name="check-circle" />{' '}
<FormattedMessage
id="app.acceptSolution.accepted"
defaultMessage="Remove grading mark"
defaultMessage="Revoke as Final"
/>
</Button>
: <Button bsStyle="primary" onClick={accept}>
: <Button bsStyle="primary" onClick={accept} disabled={acceptPending}>
<Icon name="check-circle-o" />{' '}
<FormattedMessage
id="app.acceptSolution.notAccepted"
defaultMessage="Mark for grading"
defaultMessage="Accept as Final"
/>
</Button>;

AcceptSolution.propTypes = {
accepted: PropTypes.bool.isRequired,
acceptPending: PropTypes.bool.isRequired,
accept: PropTypes.func.isRequired,
unaccept: PropTypes.func.isRequired
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,35 @@ import {
acceptSubmission,
unacceptSubmission
} from '../../redux/modules/submissions';
import { isAccepted } from '../../redux/selectors/submissions';
import { isAccepted, isAcceptPending } from '../../redux/selectors/submissions';

const AcceptSolutionContainer = ({ accepted, accept, unaccept }) => {
const AcceptSolutionContainer = ({
accepted,
acceptPending,
accept,
unaccept
}) => {
return (
<AcceptSolution accepted={accepted} accept={accept} unaccept={unaccept} />
<AcceptSolution
accepted={accepted}
acceptPending={acceptPending}
accept={accept}
unaccept={unaccept}
/>
);
};

AcceptSolutionContainer.propTypes = {
id: PropTypes.string.isRequired,
accepted: PropTypes.bool.isRequired,
acceptPending: PropTypes.bool.isRequired,
accept: PropTypes.func.isRequired,
unaccept: PropTypes.func.isRequired
};

const mapStateToProps = (state, { id }) => ({
accepted: isAccepted(id)(state)
accepted: isAccepted(id)(state),
acceptPending: isAcceptPending(id)(state)
});

const mapDispatchToProps = (dispatch, { id }) => ({
Expand Down
4 changes: 2 additions & 2 deletions src/locales/cs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app.EditEnvironmentLimitsForm.cloneAll.yesNoQuestion": "Do you really want to use these limits for all the tests of all runtime environments?",
"app.acceptSolution.accepted": "Odebrat označení pro hodnocení",
"app.acceptSolution.notAccepted": "Označit pro hodnocení",
"app.acceptSolution.accepted": "Zrušit jako finální",
"app.acceptSolution.notAccepted": "Akceptovat jako finální",
"app.addLicence.addLicenceTitle": "Přidat novou licenci",
"app.addLicence.failed": "Přidávání licence selhalo.",
"app.addLicence.note": "Popis:",
Expand Down
4 changes: 2 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app.EditEnvironmentLimitsForm.cloneAll.yesNoQuestion": "Do you really want to use these limits for all the tests of all runtime environments?",
"app.acceptSolution.accepted": "Remove grading mark",
"app.acceptSolution.notAccepted": "Mark for grading",
"app.acceptSolution.accepted": "Revoke as Final",
"app.acceptSolution.notAccepted": "Accept as Final",
"app.addLicence.addLicenceTitle": "Add new licence",
"app.addLicence.failed": "Cannot add the licence.",
"app.addLicence.note": "Note:",
Expand Down
24 changes: 16 additions & 8 deletions src/redux/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ const reducer = handleActions(
),

[additionalActionTypes.ACCEPT_PENDING]: (state, { meta: { id } }) =>
state.setIn(['resources', id, 'data', 'accepted'], true),
state.setIn(['resources', id, 'data', 'accepted-pending'], true),

[additionalActionTypes.ACCEPT_FAILED]: (state, { meta: { id } }) =>
state.setIn(['resources', id, 'data', 'accepted'], false),
state.setIn(['resources', id, 'data', 'accepted-pending'], false),

[additionalActionTypes.ACCEPT_FULFILLED]: (state, { meta: { id } }) =>
state.update('resources', resources =>
Expand All @@ -143,17 +143,21 @@ const reducer = handleActions(
'data',
data =>
itemId === id
? data.set('accepted', true)
: data.set('accepted', false)
? data
.set('accepted', true)
.set('accepted-pending', false)
: data
.set('accepted', false)
.set('accepted-pending', false)
)
: item
)
),
[additionalActionTypes.UNACCEPT_PENDING]: (state, { meta: { id } }) =>
state.setIn(['resources', id, 'data', 'accepted'], false),
state.setIn(['resources', id, 'data', 'accepted-pending'], true),

[additionalActionTypes.UNACCEPT_FAILED]: (state, { meta: { id } }) =>
state.setIn(['resources', id, 'data', 'accepted'], true),
state.setIn(['resources', id, 'data', 'accepted-pending'], false),

[additionalActionTypes.UNACCEPT_FULFILLED]: (state, { meta: { id } }) =>
state.update('resources', resources =>
Expand All @@ -164,8 +168,12 @@ const reducer = handleActions(
'data',
data =>
itemId === id
? data.set('accepted', false)
: data.set('accepted', true)
? data
.set('accepted', false)
.set('accepted-pending', false)
: data
.set('accepted', true)
.set('accepted-pending', false)
)
: item
)
Expand Down
11 changes: 11 additions & 0 deletions src/redux/selectors/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ export const isAccepted = id =>
? false
: submission.getIn(['data', 'accepted'])
);

export const isAcceptPending = id =>
createSelector(
getSubmission(id),
submission =>
submission.get('data') === null
? false
: submission.getIn(['data', 'accepted-pending']) !== undefined
? submission.getIn(['data', 'accepted-pending'])
: false
);
6 changes: 6 additions & 0 deletions test/redux/modules/submissions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe('Submissions', () => {
const pendingState = reducer(initialState, pendingAction);
expect(
pendingState.getIn(['resources', id, 'data', 'accepted'])
).to.equal(false);
expect(
pendingState.getIn(['resources', id, 'data', 'accepted-pending'])
).to.equal(true);

const failedAction = {
Expand All @@ -46,6 +49,9 @@ describe('Submissions', () => {
expect(failedState.getIn(['resources', id, 'data', 'accepted'])).to.equal(
false
);
expect(
failedState.getIn(['resources', id, 'data', 'accepted-pending'])
).to.equal(false);

const successAction = {
type: additionalActionTypes.ACCEPT_FULFILLED,
Expand Down

0 comments on commit ebcbce3

Please sign in to comment.