Skip to content

Commit

Permalink
Merge pull request #108 from ReCodEx/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
SemaiCZE committed Oct 19, 2017
2 parents c47ee3a + 3f447f3 commit 6a1e97f
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const SupplementaryFilesTableHeaderRow = () =>
defaultMessage="Uploaded at"
/>
</th>
<th />
</tr>;

export default SupplementaryFilesTableHeaderRow;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import prettyBytes from 'pretty-bytes';
import { FormattedDate, FormattedTime } from 'react-intl';
import { FormattedDate, FormattedTime, FormattedMessage } from 'react-intl';
import { Button } from 'react-bootstrap';
import Confirm from '../../../components/forms/Confirm';
import { DeleteIcon } from '../../../components/icons';
import { downloadSupplementaryFile } from '../../../redux/modules/files';
import { removeSupplementaryFile } from '../../../redux/modules/supplementaryFiles';

const SupplementaryFilesTableRow = ({
id,
name,
hashName,
size,
uploadedAt,
downloadFile
downloadFile,
removeSupplementaryFile
}) =>
<tr>
<td>
Expand All @@ -27,6 +32,27 @@ const SupplementaryFilesTableRow = ({
&nbsp;
<FormattedTime value={uploadedAt * 1000} />
</td>
<td>
<Confirm
id={id}
onConfirmed={() => removeSupplementaryFile(id)}
question={
<FormattedMessage
id="app.supplementaryFiles.deleteConfirm"
defaultMessage="Are you sure you want to delete the file? This cannot be undone."
/>
}
className="pull-right"
>
<Button bsSize="xs" className="btn-flat" bsStyle="danger">
<DeleteIcon />{' '}
<FormattedMessage
id="app.supplementaryFiles.deleteButton"
defaultMessage="Delete"
/>
</Button>
</Confirm>
</td>
</tr>;

SupplementaryFilesTableRow.propTypes = {
Expand All @@ -35,7 +61,8 @@ SupplementaryFilesTableRow.propTypes = {
hashName: PropTypes.string.isRequired,
size: PropTypes.number.isRequired,
uploadedAt: PropTypes.number.isRequired,
downloadFile: PropTypes.func.isRequired
downloadFile: PropTypes.func.isRequired,
removeSupplementaryFile: PropTypes.func.isRequired
};

export default connect(
Expand All @@ -44,6 +71,7 @@ export default connect(
downloadFile: e => {
e.preventDefault();
dispatch(downloadSupplementaryFile(id));
}
},
removeSupplementaryFile: fileId => dispatch(removeSupplementaryFile(fileId))
})
)(SupplementaryFilesTableRow);
26 changes: 13 additions & 13 deletions src/components/Groups/GroupDetail/GroupDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ const GroupDetail = ({
parentGroupId,
isPublic = false,
childGroups,
adminId,
...group
},
groups,
publicGroups,
supervisors,
isAdmin
}) => (
}) =>
<div>
<Row>
<Col lg={6} sm={12}>
Expand All @@ -47,7 +48,7 @@ const GroupDetail = ({
>
<Table>
<tbody>
{externalId && (
{externalId &&
<tr>
<th>
<FormattedMessage
Expand All @@ -56,10 +57,11 @@ const GroupDetail = ({
/>
</th>
<td>
<code>{externalId}</code>
<code>
{externalId}
</code>
</td>
</tr>
)}
</tr>}
<tr>
<th>
<FormattedMessage
Expand All @@ -71,7 +73,7 @@ const GroupDetail = ({
<MaybeSucceededIcon success={isPublic} />
</td>
</tr>
{threshold !== null && (
{threshold !== null &&
<tr>
<th>
<FormattedMessage
Expand All @@ -82,14 +84,13 @@ const GroupDetail = ({
<td>
<FormattedNumber value={threshold} style="percent" />
</td>
</tr>
)}
</tr>}
</tbody>
</Table>
</Box>
</Col>
</Row>
{childGroups.all.length > 0 && (
{childGroups.all.length > 0 &&
<Row>
<Col sm={12}>
<Box
Expand All @@ -111,8 +112,7 @@ const GroupDetail = ({
/>
</Box>
</Col>
</Row>
)}
</Row>}
</Col>
<Col lg={6} sm={12}>
<Box
Expand All @@ -131,13 +131,13 @@ const GroupDetail = ({
groupId={id}
users={supervisors}
isAdmin={isAdmin}
mainAdminId={adminId}
isLoaded={supervisors.length === group.supervisors.length}
/>
</Box>
</Col>
</Row>
</div>
);
</div>;

GroupDetail.propTypes = {
group: PropTypes.shape({
Expand Down
19 changes: 13 additions & 6 deletions src/components/Users/SupervisorsList/SupervisorsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ import SupervisorsListItem, {
LoadingSupervisorsListItem
} from '../SupervisorsListItem';

const SupervisorsList = ({ groupId, users, isLoaded = true, isAdmin }) => (
const SupervisorsList = ({
groupId,
users,
isLoaded = true,
isAdmin,
mainAdminId
}) =>
<Table hover>
<tbody>
{users.map(user => (
{users.map(user =>
<SupervisorsListItem
key={user.id}
{...user}
groupId={groupId}
isAdmin={isAdmin}
mainAdminId={mainAdminId}
/>
))}
)}

{users.length === 0 &&
isLoaded &&
Expand All @@ -31,14 +38,14 @@ const SupervisorsList = ({ groupId, users, isLoaded = true, isAdmin }) => (

{!isLoaded && <LoadingSupervisorsListItem isAdmin={isAdmin} />}
</tbody>
</Table>
);
</Table>;

SupervisorsList.propTypes = {
users: PropTypes.array.isRequired,
groupId: PropTypes.string.isRequired,
isLoaded: PropTypes.bool,
isAdmin: PropTypes.bool
isAdmin: PropTypes.bool,
mainAdminId: PropTypes.string
};

export default SupervisorsList;
19 changes: 8 additions & 11 deletions src/components/Users/SupervisorsListItem/SupervisorsListItem.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
import MakeRemoveSupervisorButtonContainer
from '../../../containers/MakeRemoveSupervisorButtonContainer';
import MakeRemoveSupervisorButtonContainer from '../../../containers/MakeRemoveSupervisorButtonContainer';
import MakeGroupAdminButton from '../../Groups/MakeGroupAdminButton';
import { makeAdmin } from '../../../redux/modules/groups';
import { adminsOfGroup } from '../../../redux/selectors/groups';
Expand All @@ -15,33 +13,32 @@ const SupervisorsListItem = ({
fullName,
avatarUrl,
groupId,
groupAdmins,
makeAdmin
}) => (
makeAdmin,
mainAdminId
}) =>
<tr>
<td>
<UsersNameContainer userId={id} />
</td>
{isAdmin &&
<td>
<MakeRemoveSupervisorButtonContainer userId={id} groupId={groupId} />
{groupAdmins.indexOf(id) < 0 &&
{id !== mainAdminId &&
<MakeGroupAdminButton
onClick={() => makeAdmin(groupId, id)}
bsSize="xs"
/>}
</td>}
</tr>
);
</tr>;

SupervisorsListItem.propTypes = {
id: PropTypes.string.isRequired,
isAdmin: PropTypes.bool.isRequired,
groupId: PropTypes.string.isRequired,
fullName: PropTypes.string.isRequired,
avatarUrl: PropTypes.string.isRequired,
groupAdmins: ImmutablePropTypes.list.isRequired,
makeAdmin: PropTypes.func.isRequired
makeAdmin: PropTypes.func.isRequired,
mainAdminId: PropTypes.string.isRequired
};

const mapStateToProps = (state, { groupId }) => ({
Expand Down
24 changes: 15 additions & 9 deletions src/components/forms/Confirm/Confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ class Confirm extends Component {
id,
yes = (
<span>
<SuccessIcon />
{' '}
<SuccessIcon />{' '}
<FormattedMessage id="app.confirm.yes" defaultMessage="Yes" />
</span>
),
no = (
<span>
<CloseIcon />
{' '}
<CloseIcon />{' '}
<FormattedMessage id="app.confirm.no" defaultMessage="No" />
</span>
)
Expand All @@ -52,8 +50,12 @@ class Confirm extends Component {
<Popover id={id} title={question}>
<div className="text-center">
<ButtonGroup bsSize="sm">
<Button onClick={e => this.confirm(e)}>{yes}</Button>
<Button onClick={e => this.dismiss(e)}>{no}</Button>
<Button onClick={e => this.confirm(e)}>
{yes}
</Button>
<Button onClick={e => this.dismiss(e)}>
{no}
</Button>
</ButtonGroup>
</div>
</Popover>
Expand All @@ -62,9 +64,12 @@ class Confirm extends Component {
}

render() {
const { children } = this.props;
const { children, className = '' } = this.props;
return (
<span style={{ display: 'inline-block', position: 'relative' }}>
<span
style={{ display: 'inline-block', position: 'relative' }}
className={className}
>
{React.cloneElement(children, {
onClick: e => this.askForConfirmation(e)
})}
Expand All @@ -87,7 +92,8 @@ Confirm.propTypes = {
question: stringOrFormattedMessage.isRequired,
yes: stringOrFormattedMessage,
no: stringOrFormattedMessage,
children: PropTypes.element.isRequired
children: PropTypes.element.isRequired,
className: PropTypes.string
};

export default Confirm;
25 changes: 15 additions & 10 deletions src/pages/Assignment/Assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,15 @@ class Assignment extends Component {
isOpen={submitting}
runtimeEnvironments={runtimes}
/>

<SubmissionsTableContainer
userId={userId}
assignmentId={assignment.id}
/>
</div>}

{(isStudentOf(assignment.groupId) ||
isSupervisorOf(assignment.groupId) ||
isSuperAdmin) &&
<SubmissionsTableContainer
userId={userId}
assignmentId={assignment.id}
/>}
</Col>}
</ResourceRenderer>
</Row>
Expand Down Expand Up @@ -336,18 +339,20 @@ export default withLinks(
const environments = runtimeEnvironmentsSelector(assignmentId)(
state
).toJS();
userId = userId || loggedInUserIdSelector(state);
const loggedInUserId = loggedInUserIdSelector(state);
userId = userId || loggedInUserId;
return {
assignment: assignmentSelector(state),
submitting: isSubmitting(state),
runtimeEnvironments: environments.map(i =>
runtimeEnvironmentSelector(i)(state)
),
userId,
loggeInUserId: loggedInUserIdSelector(state),
isSuperAdmin: isSuperAdmin(userId)(state),
isStudentOf: groupId => isStudentOf(userId, groupId)(state),
isSupervisorOf: groupId => isSupervisorOf(userId, groupId)(state),
loggedInUserId,
isSuperAdmin: isSuperAdmin(loggedInUserId)(state),
isStudentOf: groupId => isStudentOf(loggedInUserId, groupId)(state),
isSupervisorOf: groupId =>
isSupervisorOf(loggedInUserId, groupId)(state),
canSubmit: canSubmitSolution(assignmentId)(state)
};
},
Expand Down
Loading

0 comments on commit 6a1e97f

Please sign in to comment.