Skip to content

Commit

Permalink
Fixed problems in selectors in reductors created by latest API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed Nov 18, 2017
1 parent 0080564 commit ab0d2aa
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
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 || true)
),
canUseDOM && window.devToolsExtension ? window.devToolsExtension() : f => f // use the DEVtools if the extension is installed
);

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

0 comments on commit ab0d2aa

Please sign in to comment.