Skip to content

Commit

Permalink
Merge pull request #140 from ReCodEx/sis-create-group-update-sidebar
Browse files Browse the repository at this point in the history
Sidebar is now refreshing when new group is created from SIS course.
  • Loading branch information
Martin Kruliš committed Nov 18, 2017
2 parents 234f366 + d4ccb73 commit 14d5cf9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/containers/SidebarContainer/SidebarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import Sidebar from '../../components/layout/Sidebar/Sidebar';
import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import { memberOfInstances } from '../../redux/selectors/instances';
import {
studentOfSelector,
supervisorOfSelector
} from '../../redux/selectors/groups';
loggedInStudentOfSelector,
loggedInSupervisorOfSelector
} from '../../redux/selectors/usersGroups';
import {
notificationsSelector,
isSupervisor,
Expand All @@ -16,10 +16,10 @@ const mapStateToProps = state => {
const userId = loggedInUserIdSelector(state);
return {
instances: memberOfInstances(userId)(state),
studentOf: studentOfSelector(userId)(state),
studentOf: loggedInStudentOfSelector(state),
isAdmin: isLoggedAsSuperAdmin(state),
isSupervisor: isSupervisor(userId)(state),
supervisorOf: supervisorOfSelector(userId)(state),
supervisorOf: loggedInSupervisorOfSelector(state),
notifications: notificationsSelector(state)
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/redux/middleware/loggerMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const middleware = isDev => store => next => action => {
/* eslint no-console: ["error", { allow: ["log", "error"] }] */
let verbose = false && isDev;
let verbose = false;
var actionType = action.type;
if (verbose) {
console.log('Starting ' + actionType);
Expand All @@ -13,7 +13,7 @@ const middleware = isDev => store => next => action => {
var res = next(action);
} catch (e) {
console.error('Exception thrown when processing action ' + actionType);
if (isDev) console.error(e);
if (verbose) console.error(e);
throw e;
}
if (verbose) {
Expand Down
12 changes: 12 additions & 0 deletions src/redux/modules/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { addNotification } from './notifications';
import { createApiAction } from '../middleware/apiMiddleware';
import factory, { initialState } from '../helpers/resourceManager';

import createRecord from '../helpers/resourceManager/recordFactory';
import { resourceStatus } from '../helpers/resourceManager/status';
import { actionTypes as assignmentsActionTypes } from './assignments';
import { actionTypes as sisSupervisedCoursesActionTypes } from './sisSupervisedCourses';

const resourceName = 'groups';
const { actions, actionTypes, reduceActions } = factory({ resourceName });
Expand Down Expand Up @@ -383,6 +386,15 @@ const reducer = handleActions(
.update('public', ids => ids.filter(id => id !== assignmentId))
)
)
),

[sisSupervisedCoursesActionTypes.CREATE_FULFILLED]: (
state,
{ payload: data }
) =>
state.setIn(
['resources', data.id],
createRecord({ state: resourceStatus.FULFILLED, data })
)
}),
initialState
Expand Down
15 changes: 15 additions & 0 deletions src/redux/modules/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import factory, { initialState } from '../helpers/resourceManager';
import { createApiAction } from '../middleware/apiMiddleware';

import { additionalActionTypes as groupsActionTypes } from './groups';
import { actionTypes as sisSupervisedCoursesActionTypes } from './sisSupervisedCourses';
import { actionTypes as emailVerificationActionTypes } from './emailVerification';

export const additionalActionTypes = {
Expand Down Expand Up @@ -151,6 +152,20 @@ const reducer = handleActions(
);
},

[sisSupervisedCoursesActionTypes.CREATE_FULFILLED]: (
state,
{ meta: { userId }, payload }
) => {
if (!state.getIn(['resources', userId])) {
return state;
}

return state.updateIn(
['resources', userId, 'data', 'groups', 'supervisorOf'],
list => list.push(payload.id)
);
},

[groupsActionTypes.MAKE_SUPERVISOR_REJECTED]: (
state,
{ meta: { groupId, userId } }
Expand Down
1 change: 1 addition & 0 deletions src/redux/selectors/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isReady, getId, getJsData } from '../helpers/resourceManager';
const EMPTY_MAP = Map();

export const groupsSelector = state => state.groups.get('resources');

export const filterGroups = (ids, groups) =>
groups.filter(isReady).filter(group => ids.contains(getId(group)));

Expand Down

0 comments on commit 14d5cf9

Please sign in to comment.