Skip to content

Commit

Permalink
Bug in reducers that load bestSolutions fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed Dec 30, 2017
1 parent acb414c commit a9e2a1e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const AssignmentTableRow = ({
<td>
<ResourceRenderer resource={bestSubmission}>
{data =>
data.lastSubmission
data && data.lastSubmission
? <span>
{data.lastSubmission.evaluation.points}
{data.bonusPoints > 0 &&
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Group/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ class Group extends Component {
}

componentWillReceiveProps(newProps) {
const { params: { groupId } } = this.props;
const { params: { groupId }, userId, isSuperAdmin } = this.props;

if (groupId !== newProps.params.groupId) {
if (
groupId !== newProps.params.groupId ||
userId !== newProps.userId ||
isSuperAdmin !== newProps.isSuperAdmin
) {
newProps.loadAsync(newProps.userId, newProps.isSuperAdmin);
return;
}
Expand Down
35 changes: 27 additions & 8 deletions src/redux/modules/groupResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,37 @@ const reducer = handleActions(
[additionalActionTypes.BEST_SUBMISSION_PENDING]: (
state,
{ payload, meta: { userId, assignmentId } }
) => state.setIn(['resources', assignmentId, userId], createRecord()),
) =>
userId !== undefined
? state.setIn(['resources', assignmentId, userId], createRecord())
: state,

[additionalActionTypes.BEST_SUBMISSION_FULFILLED]: (
state,
{ payload = {}, meta: { assignmentId, userId } }
) =>
state
.setIn(['resources', assignmentId, userId, 'data'], fromJS(payload))
.setIn(
['resources', assignmentId, userId, 'state'],
resourceStatus.FULFILLED
)
) => {
if (userId !== undefined) {
// update single-user record
return state
.setIn(['resources', assignmentId, userId, 'data'], fromJS(payload))
.setIn(
['resources', assignmentId, userId, 'state'],
resourceStatus.FULFILLED
);
} else {
// Update for each user in the payload
for (const uId in payload) {
state = state.setIn(
['resources', assignmentId, uId],
createRecord({
data: fromJS(payload[uId]),
state: resourceStatus.FULFILLED
})
);
}
return state;
}
}
}),
initialState
);
Expand Down

0 comments on commit a9e2a1e

Please sign in to comment.