From 1cb1ec8bebc7f008329c94d7d131f32520592995 Mon Sep 17 00:00:00 2001 From: Petr Stefan Date: Thu, 21 Dec 2017 16:53:21 +0100 Subject: [PATCH] Fix loading issue on new students and supervisors --- .../Users/SupervisorsList/SupervisorsList.js | 19 +++++++++--------- src/components/Users/UsersList/UsersList.js | 8 ++------ src/pages/Group/Group.js | 20 ++++++++++++++++--- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/components/Users/SupervisorsList/SupervisorsList.js b/src/components/Users/SupervisorsList/SupervisorsList.js index efaab793a..7b74fdf3b 100644 --- a/src/components/Users/SupervisorsList/SupervisorsList.js +++ b/src/components/Users/SupervisorsList/SupervisorsList.js @@ -15,15 +15,16 @@ const SupervisorsList = ({ }) => - {users.map(user => - - )} + {isLoaded && + users.map(user => + + )} {users.length === 0 && isLoaded && diff --git a/src/components/Users/UsersList/UsersList.js b/src/components/Users/UsersList/UsersList.js index a40a45a95..9b58e689f 100644 --- a/src/components/Users/UsersList/UsersList.js +++ b/src/components/Users/UsersList/UsersList.js @@ -13,12 +13,8 @@ const UsersList = ({ users = [], createActions, intl, ...rest }) => const bName = b.name.lastName + ' ' + b.name.firstName; return aName.localeCompare(bName, intl.locale); }) - .map(user => - + .map((user, i) => + )} {users.length === 0 && diff --git a/src/pages/Group/Group.js b/src/pages/Group/Group.js index c9093fca6..f4eb80114 100644 --- a/src/pages/Group/Group.js +++ b/src/pages/Group/Group.js @@ -27,7 +27,7 @@ import { fetchInstanceGroupsIfNeeded, fetchSubgroups } from '../../redux/modules/groups'; -import { fetchGroupsStatsIfNeeded } from '../../redux/modules/stats'; +import { fetchGroupsStats } from '../../redux/modules/stats'; import { fetchSupervisors, fetchStudents } from '../../redux/modules/users'; import { fetchAssignmentsForGroup, @@ -61,6 +61,7 @@ import { getStatusesForLoggedUser } from '../../redux/selectors/stats'; import { getLocalizedName } from '../../helpers/getLocalizedData'; import withLinks from '../../hoc/withLinks'; +import { isReady } from '../../redux/helpers/resourceManager/index'; class Group extends Component { static isAdminOrSupervisorOf = (group, userId) => @@ -86,7 +87,7 @@ class Group extends Component { ? Promise.all([ dispatch(fetchAssignmentsForGroup(groupId)), dispatch(fetchStudents(groupId)), - dispatch(fetchGroupsStatsIfNeeded(groupId)) + dispatch(fetchGroupsStats(groupId)) ]) : Promise.resolve() ]) @@ -105,6 +106,17 @@ class Group extends Component { if (groupId !== newProps.params.groupId) { newProps.loadAsync(newProps.userId, newProps.isSuperAdmin); } + + if (isReady(this.props.group) && isReady(newProps.group)) { + const thisData = this.props.group.toJS().data; + const newData = newProps.group.toJS().data; + if (thisData.supervisors.length !== newData.supervisors.length) { + newProps.refetchSupervisors(); + } + if (thisData.students.length !== newData.students.length) { + newProps.loadAsync(newProps.userId, newProps.isSuperAdmin); + } + } } getBreadcrumbs = () => { @@ -278,6 +290,7 @@ Group.propTypes = { assignExercise: PropTypes.func.isRequired, createGroupExercise: PropTypes.func.isRequired, push: PropTypes.func.isRequired, + refetchSupervisors: PropTypes.func.isRequired, links: PropTypes.object, intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired }; @@ -322,7 +335,8 @@ const mapDispatchToProps = (dispatch, { params }) => ({ dispatch(assignExercise(params.groupId, exerciseId)), createGroupExercise: () => dispatch(createExercise({ groupId: params.groupId })), - push: url => dispatch(push(url)) + push: url => dispatch(push(url)), + refetchSupervisors: () => dispatch(fetchSupervisors(params.groupId)) }); export default withLinks(