Skip to content

Commit

Permalink
Private/public consolidation (#161)
Browse files Browse the repository at this point in the history
* Most of the changes to join endpoints

* Fix loading admin names in group hierarchy

* Fix loading on user pages

* More privateData fixes

* More fixes

* Fix redirect after auth

* Do not duplicate users name container
  • Loading branch information
SemaiCZE committed Jan 8, 2018
1 parent 6e1fa17 commit 135c5f1
Show file tree
Hide file tree
Showing 32 changed files with 240 additions and 328 deletions.
5 changes: 4 additions & 1 deletion src/components/Groups/AdminsView/AdminsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const AdminsView = ({ group, addSubgroup, formValues, intl: { locale } }) =>
/>
}
>
<AddSupervisor instanceId={group.instanceId} groupId={group.id} />
<AddSupervisor
instanceId={group.privateData.instanceId}
groupId={group.id}
/>
</Box>
</Col>
<Col md={6}>
Expand Down
31 changes: 16 additions & 15 deletions src/components/Groups/GroupDetail/GroupDetail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { FormattedMessage, FormattedNumber, injectIntl } from 'react-intl';
import { Row, Col, Table } from 'react-bootstrap';
import ReactMarkdown from 'react-remarkable';
Expand All @@ -20,16 +19,17 @@ const GroupDetail = ({
externalId,
name,
localizedTexts,
description,
threshold,
parentGroupId,
isPublic = false,
childGroups,
primaryAdminsIds,
...group
childGroups,
privateData: {
description,
threshold,
parentGroupId,
isPublic = false,
...privateGroup
}
},
groups,
publicGroups,
supervisors,
isAdmin,
intl: { locale }
Expand Down Expand Up @@ -120,7 +120,7 @@ const GroupDetail = ({
deletable={false}
isAdmin={isAdmin}
isOpen
groups={publicGroups}
groups={groups}
level={1}
/>
</Box>
Expand All @@ -147,7 +147,7 @@ const GroupDetail = ({
users={supervisors}
isAdmin={isAdmin}
primaryAdminsIds={primaryAdminsIds}
isLoaded={supervisors.length === group.supervisors.length}
isLoaded={supervisors.length === privateGroup.supervisors.length}
/>
</Box>
</Col>
Expand All @@ -158,19 +158,20 @@ GroupDetail.propTypes = {
group: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
parentGroupId: PropTypes.string,
childGroups: PropTypes.shape({
all: PropTypes.array,
public: PropTypes.array.isRequired
}),
threshold: PropTypes.number,
isPublic: PropTypes.bool,
supervisors: PropTypes.array.isRequired,
primaryAdminsIds: PropTypes.array.isRequired
primaryAdminsIds: PropTypes.array.isRequired,
privateData: PropTypes.shape({
description: PropTypes.string.isRequired,
isPublic: PropTypes.bool,
supervisors: PropTypes.array.isRequired
})
}),
groups: PropTypes.object.isRequired,
publicGroups: ImmutablePropTypes.map.isRequired,
supervisors: PropTypes.array.isRequired,
isAdmin: PropTypes.bool,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
Expand Down
6 changes: 3 additions & 3 deletions src/components/Groups/GroupTree/GroupTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class GroupTree extends Component {
const {
name,
localizedTexts,
admins,
canView,
childGroups: { all: allChildGroups, public: publicChildGroups },
canView
primaryAdminsIds
} = getJsData(group);

return (
Expand All @@ -79,7 +79,7 @@ class GroupTree extends Component {
/>
}
level={level}
admins={admins}
admins={primaryAdminsIds}
isOpen={currentGroupId === id || isOpen}
actions={
currentGroupId !== id && canView
Expand Down
5 changes: 4 additions & 1 deletion src/components/Groups/SupervisorsView/SupervisorsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ const SupervisorsView = ({
}
isOpen
>
<AddStudent instanceId={group.instanceId} groupId={group.id} />
<AddStudent
instanceId={group.privateData.instanceId}
groupId={group.id}
/>
</Box>
<Box
title={
Expand Down
7 changes: 4 additions & 3 deletions src/components/widgets/TreeView/TreeViewLeaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Icon from 'react-fontawesome';
import { LoadingIcon } from '../../icons';
import LevelGap from './LevelGap';
import GroupsName from '../../../components/Groups/GroupsName';
import UsersNameContainer from '../../../containers/UsersNameContainer';

const TreeViewLeaf = ({
loading = false,
Expand Down Expand Up @@ -32,9 +33,9 @@ const TreeViewLeaf = ({
<span>
&nbsp;&nbsp; (<small>
<em>
{admins
.map(a => a.name.firstName + ' ' + a.name.lastName)
.join(', ')}
{admins.map(a =>
<UsersNameContainer key={a} userId={a} isSimple />
)}
</em>
</small>)
</span>}
Expand Down
8 changes: 4 additions & 4 deletions src/containers/GroupsNameContainer/GroupsNameContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';

import { fetchPublicGroupIfNeeded } from '../../redux/modules/publicGroups';
import { publicGroupSelector } from '../../redux/selectors/publicGroups';
import { fetchGroupIfNeeded } from '../../redux/modules/groups';
import { groupSelector } from '../../redux/selectors/groups';
import ResourceRenderer from '../../components/helpers/ResourceRenderer';
import GroupsName, {
LoadingGroupsName
Expand All @@ -22,7 +22,7 @@ class GroupsNameContainer extends Component {
}

static loadAsync = ({ groupId }, dispatch) => {
dispatch(fetchPublicGroupIfNeeded(groupId));
dispatch(fetchGroupIfNeeded(groupId));
};

render() {
Expand All @@ -44,7 +44,7 @@ GroupsNameContainer.propTypes = {

export default connect(
(state, { groupId }) => ({
group: publicGroupSelector(groupId)(state)
group: groupSelector(groupId)(state)
}),
(dispatch, { groupId }) => ({
loadAsync: () => GroupsNameContainer.loadAsync({ groupId }, dispatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HierarchyLineContainer extends Component {
{group =>
<HierarchyLine
groupId={group.id}
parentGroupsIds={group.parentGroupsIds}
parentGroupsIds={group.privateData.parentGroupsIds}
/>}
</ResourceRenderer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { makeSupervisor, removeSupervisor } from '../../redux/modules/groups';
import { fetchProfileIfNeeded } from '../../redux/modules/publicProfiles';
import { fetchUserIfNeeded } from '../../redux/modules/users';
import { isSupervisorOf } from '../../redux/selectors/users';

import MakeSupervisorButton from '../../components/Groups/MakeSupervisorButton';
Expand All @@ -14,7 +14,7 @@ const MakeRemoveSupervisorButtonContainer = ({
groupId,
makeSupervisor,
removeSupervisor,
fetchProfileIfNeeded,
fetchUserIfNeeded,
...props
}) =>
isSupervisor
Expand All @@ -26,9 +26,7 @@ const MakeRemoveSupervisorButtonContainer = ({
: <MakeSupervisorButton
{...props}
onClick={() => {
fetchProfileIfNeeded(userId).then(() =>
makeSupervisor(groupId, userId)
);
fetchUserIfNeeded(userId).then(() => makeSupervisor(groupId, userId));
}}
bsSize="xs"
/>;
Expand All @@ -39,7 +37,7 @@ MakeRemoveSupervisorButtonContainer.propTypes = {
isSupervisor: PropTypes.bool.isRequired,
makeSupervisor: PropTypes.func.isRequired,
removeSupervisor: PropTypes.func.isRequired,
fetchProfileIfNeeded: PropTypes.func.isRequired
fetchUserIfNeeded: PropTypes.func.isRequired
};

const mapStateToProps = (state, { groupId, userId }) => ({
Expand All @@ -49,7 +47,7 @@ const mapStateToProps = (state, { groupId, userId }) => ({
const mapDispatchToProps = {
makeSupervisor,
removeSupervisor,
fetchProfileIfNeeded
fetchUserIfNeeded
};

export default connect(mapStateToProps, mapDispatchToProps)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Button from '../../components/widgets/FlatButton';
import { LinkContainer } from 'react-router-bootstrap';
import Icon from 'react-fontawesome';

import { fetchPublicGroupsIfNeeded } from '../../redux/modules/publicGroups';
import { fetchGroupsIfNeeded } from '../../redux/modules/groups';
import { fetchSisStatusIfNeeded } from '../../redux/modules/sisStatus';
import {
fetchSisSupervisedCourses,
Expand All @@ -21,7 +21,7 @@ import { sisPossibleParentsSelector } from '../../redux/selectors/sisPossiblePar
import { sisStateSelector } from '../../redux/selectors/sisStatus';
import { sisSupervisedCoursesSelector } from '../../redux/selectors/sisSupervisedCourses';
import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import { publicGroupDataAccessorSelector } from '../../redux/selectors/publicGroups';
import { groupDataAccessorSelector } from '../../redux/selectors/groups';

import UsersNameContainer from '../UsersNameContainer';
import ResourceRenderer from '../../components/helpers/ResourceRenderer';
Expand Down Expand Up @@ -73,7 +73,7 @@ class SisSupervisorGroupsContainer extends Component {
.then(parents =>
parents.map(parent =>
dispatch(
fetchPublicGroupsIfNeeded(
fetchGroupsIfNeeded(
parent.id,
...parent.parentGroupsIds
)
Expand Down Expand Up @@ -346,7 +346,7 @@ export default injectIntl(
currentUserId,
sisCourses: sisSupervisedCoursesSelector(state),
sisPossibleParents: sisPossibleParentsSelector(state),
groupsAccessor: publicGroupDataAccessorSelector(state)
groupsAccessor: groupDataAccessorSelector(state)
};
},
dispatch => ({
Expand Down
7 changes: 3 additions & 4 deletions src/containers/StudentsListContainer/StudentsListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ class StudentsListContainer extends Component {
const { group, students, stats, ...props } = this.props;
return (
<ResourceRenderer resource={group}>
{group => (
{group =>
<StudentsList
{...props}
users={students}
isLoaded={students.length === group.students.length}
isLoaded={students.length === group.privateData.students.length}
stats={stats}
/>
)}
/>}
</ResourceRenderer>
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/containers/UsersNameContainer/UsersNameContainer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.simpleName {
margin-left: 4px;
margin-right: 4px;
white-space: nowrap;
}
35 changes: 21 additions & 14 deletions src/containers/UsersNameContainer/UsersNameContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';

import { fetchProfileIfNeeded } from '../../redux/modules/publicProfiles';
import { getProfile } from '../../redux/selectors/publicProfiles';
import { fetchUserIfNeeded } from '../../redux/modules/users';
import { getUser } from '../../redux/selectors/users';
import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import ResourceRenderer from '../../components/helpers/ResourceRenderer';
import UsersName, {
LoadingUsersName,
FailedUsersName
} from '../../components/Users/UsersName';

import './UsersNameContainer.css';

class UsersNameContainer extends Component {
componentWillMount() {
this.props.loadAsync();
Expand All @@ -24,11 +26,11 @@ class UsersNameContainer extends Component {
}

static loadAsync = ({ userId }, dispatch) => {
dispatch(fetchProfileIfNeeded(userId));
dispatch(fetchUserIfNeeded(userId));
};

render() {
const { user, large, noLink, currentUserId } = this.props;
const { user, large, noLink, currentUserId, isSimple = false } = this.props;
const size = large ? 45 : 22;
return (
<ResourceRenderer
Expand All @@ -37,13 +39,17 @@ class UsersNameContainer extends Component {
failed={<FailedUsersName size={size} />}
>
{user =>
<UsersName
{...user}
large={large}
size={size}
noLink={noLink}
currentUserId={currentUserId}
/>}
isSimple
? <span className="simpleName">
{user.name.firstName} {user.name.lastName}
</span>
: <UsersName
{...user}
large={large}
size={size}
noLink={noLink}
currentUserId={currentUserId}
/>}
</ResourceRenderer>
);
}
Expand All @@ -55,16 +61,17 @@ UsersNameContainer.propTypes = {
large: PropTypes.bool,
user: ImmutablePropTypes.map,
noLink: PropTypes.bool,
loadAsync: PropTypes.func.isRequired
loadAsync: PropTypes.func.isRequired,
isSimple: PropTypes.bool
};

export default connect(
(state, { userId }) => ({
user: getProfile(userId)(state),
user: getUser(userId)(state),
currentUserId: loggedInUserIdSelector(state)
}),
(dispatch, { userId }) => ({
loadProfileIfNeeded: () => dispatch(fetchProfileIfNeeded(userId)),
loadProfileIfNeeded: () => dispatch(fetchUserIfNeeded(userId)),
loadAsync: () => UsersNameContainer.loadAsync({ userId }, dispatch)
})
)(UsersNameContainer);
Loading

0 comments on commit 135c5f1

Please sign in to comment.