Skip to content

Commit

Permalink
Fix loading issue on new students and supervisors
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Dec 21, 2017
1 parent 354299a commit 1cb1ec8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
19 changes: 10 additions & 9 deletions src/components/Users/SupervisorsList/SupervisorsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ const SupervisorsList = ({
}) =>
<Table hover>
<tbody>
{users.map(user =>
<SupervisorsListItem
key={user.id}
{...user}
groupId={groupId}
isAdmin={isAdmin}
primaryAdminsIds={primaryAdminsIds}
/>
)}
{isLoaded &&
users.map(user =>
<SupervisorsListItem
key={user.id}
{...user}
groupId={groupId}
isAdmin={isAdmin}
primaryAdminsIds={primaryAdminsIds}
/>
)}

{users.length === 0 &&
isLoaded &&
Expand Down
8 changes: 2 additions & 6 deletions src/components/Users/UsersList/UsersList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
<UsersListItem
id={user.id}
createActions={createActions}
key={user.id}
/>
.map((user, i) =>
<UsersListItem id={user.id} createActions={createActions} key={i} />
)}

{users.length === 0 &&
Expand Down
20 changes: 17 additions & 3 deletions src/pages/Group/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) =>
Expand All @@ -86,7 +87,7 @@ class Group extends Component {
? Promise.all([
dispatch(fetchAssignmentsForGroup(groupId)),
dispatch(fetchStudents(groupId)),
dispatch(fetchGroupsStatsIfNeeded(groupId))
dispatch(fetchGroupsStats(groupId))
])
: Promise.resolve()
])
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1cb1ec8

Please sign in to comment.