-
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.
Implementing redux module and selectors for handling solution reviews.
- Loading branch information
1 parent
4371fe3
commit 751d84b
Showing
4 changed files
with
180 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { handleActions, createAction } from 'redux-actions'; | ||
import { fromJS } from 'immutable'; | ||
|
||
import { createApiAction } from '../middleware/apiMiddleware'; | ||
import factory, { initialState, createRecord, resourceStatus } from '../helpers/resourceManager'; | ||
import { actionTypes as submissionActionTypes } from './submission'; | ||
import { actionTypes as submissionEvaluationActionTypes } from './submissionEvaluations'; | ||
import { getAssignmentSolversLastUpdate } from '../selectors/solutions'; | ||
import { objectFilter } from '../../helpers/common'; | ||
|
||
const resourceName = 'solutionReviews'; | ||
|
||
const apiEndpointFactory = id => `/assignment-solutions/${id}/review`; | ||
const { actions, actionTypes, reduceActions } = factory({ | ||
resourceName, | ||
apiEndpointFactory, | ||
}); | ||
|
||
/** | ||
* Actions | ||
*/ | ||
export { actionTypes }; | ||
export const additionalActionTypes = {}; | ||
|
||
export const fetchSolutionReview = actions.fetchResource; | ||
export const fetchSolutionReviewIfNeeded = actions.fetchOneIfNeeded; | ||
export const deleteSolutionReview = actions.removeResource; | ||
|
||
/** | ||
* Reducer | ||
*/ | ||
|
||
const reducer = handleActions( | ||
Object.assign({}, reduceActions, { | ||
[actionTypes.FETCH_FULFILLED]: (state, { meta: { id }, payload: { reviewComments: data } }) => | ||
state.setIn(['resources', id], createRecord({ state: resourceStatus.FULFILLED, data })), | ||
}), | ||
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,9 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
const getSolutionsReviewsResources = state => state.solutionReviews.get('resources'); | ||
const getParam = (_, id) => id; | ||
|
||
export const getSolutionReviewComments = createSelector( | ||
[getSolutionsReviewsResources, getParam], | ||
(reviewComments, id) => reviewComments.get(id) | ||
); |