Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problems in selectors and reductors caused by latest API update #139

Merged
merged 2 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/redux/middleware/loggerMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
const middleware = store => next => action => {
/* eslint no-console: ["error", { allow: ["log"] }] */
let verbose = false;
const middleware = isDev => store => next => action => {
/* eslint no-console: ["error", { allow: ["log", "error"] }] */
let verbose = false && isDev;
var actionType = action.type;
if (verbose) {
console.log('Starting ' + actionType);
console.log(action);
} else {
console.log(action.type);
} else if (isDev) {
console.log(actionType);
}

let res = next(action);

try {
var res = next(action);
} catch (e) {
console.error('Exception thrown when processing action ' + actionType);
if (isDev) console.error(e);
throw e;
}
if (verbose) {
console.log('State After Actions:');
console.log('State After Action ' + actionType);
console.log(store.getState().groups);
console.log('--------------------');
console.log(store.getState().assignments);
}

return res;
Expand Down
34 changes: 12 additions & 22 deletions src/redux/modules/stats.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { handleActions } from 'redux-actions';
import { fromJS, List } from 'immutable';
import factory, {
initialState,
createRecord,
resourceStatus
} from '../helpers/resourceManager';
import { additionalActionTypes as additionalGroupActionTypes } from './groups';
import factory, { initialState } from '../helpers/resourceManager';
import { additionalActionTypes as additionalSubmissionActionTypes } from './submissions';

/**
Expand All @@ -23,24 +18,19 @@ export const fetchGroupsStatsIfNeeded = actions.fetchOneIfNeeded;

const reducer = handleActions(
Object.assign({}, reduceActions, {
[additionalGroupActionTypes.LOAD_USERS_GROUPS_FULFILLED]: (
[additionalSubmissionActionTypes.ACCEPT_FULFILLED]: (state, { payload }) =>
state.updateIn(['resources', payload.groupId, 'data'], stats => {
if (!stats) {
stats = List();
}
return stats
.filter(userStats => userStats.get('userId') !== payload.userId)
.push(fromJS(payload));
}),
[additionalSubmissionActionTypes.UNACCEPT_FULFILLED]: (
state,
{ payload }
) => {
payload.stats.map(item => {
state.setIn(
'resources',
item.id,
createRecord({
data: item,
status: resourceStatus.FULFILLED
})
);
});

return state;
},
[additionalSubmissionActionTypes.ACCEPT_FULFILLED]: (state, { payload }) =>
) =>
state.updateIn(['resources', payload.groupId, 'data'], stats => {
if (!stats) {
stats = List();
Expand Down
2 changes: 2 additions & 0 deletions src/redux/selectors/submissionEvaluations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const evaluationsForSubmissionSelector = submissionId =>
.filter(isReady)
.filter(
evaluation =>
submission &&
submission.getIn(['data', 'submissions']) &&
submission
.get('data')
.get('submissions')
Expand Down
7 changes: 5 additions & 2 deletions src/redux/selectors/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ export const loggedInUserSelector = createSelector(
);

export const isLoggedAsSuperAdmin = createSelector(
[usersSelector, loggedInUserIdSelector],
(users, id) => users.get(id).getIn(['data', 'role']) === 'superadmin'
[loggedInUserSelector],
loggedInUser =>
loggedInUser && isReady(loggedInUser)
? loggedInUser.getIn(['data', 'role']) === 'superadmin'
: false
);

export const memberOfInstancesIdsSelector = userId =>
Expand Down
10 changes: 5 additions & 5 deletions src/redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const getMiddleware = history => [

const dev = history =>
compose(
applyMiddleware(...getMiddleware(history)),
canUseDOM && window.devToolsExtension ? window.devToolsExtension() : f => f, // use the DEVtools if the extension is installed
!canUseDOM || !window.devToolsExtension // dev tools not available, or we are at server -> manual logging
? applyMiddleware(loggerMiddleware)
: f => f
applyMiddleware(
...getMiddleware(history),
loggerMiddleware(!canUseDOM || !window.devToolsExtension)
),
canUseDOM && window.devToolsExtension ? window.devToolsExtension() : f => f // use the DEVtools if the extension is installed
);

const prod = history => compose(applyMiddleware(...getMiddleware(history)));
Expand Down