-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing loading and visualization of group-exam locks.
- Loading branch information
1 parent
416675e
commit 52199d6
Showing
10 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Table } from 'react-bootstrap'; | ||
import { defaultMemoize } from 'reselect'; | ||
|
||
import UsersNameContainer from '../../../containers/UsersNameContainer'; | ||
import DateTime from '../../widgets/DateTime'; | ||
import { LockIcon, UnlockIcon } from '../../icons'; | ||
|
||
const sortLocks = defaultMemoize(locks => [...locks].sort(({ createdAt: c1 }, { createdAt: c2 }) => c1 - c2)); | ||
|
||
const LocksTable = ({ locks }) => | ||
locks.length > 0 ? ( | ||
<Table className="m-0" hover> | ||
<tbody> | ||
{sortLocks(locks).map(lock => ( | ||
<tr key={lock.id}> | ||
<td> | ||
<UsersNameContainer userId={lock.studentId} showEmail="icon" showExternalIdentifiers /> | ||
</td> | ||
<td> | ||
<LockIcon className="text-muted" gapRight /> | ||
<DateTime unixts={lock.createdAt} showSeconds /> | ||
</td> | ||
<td> | ||
{lock.unlockedAt && ( | ||
<> | ||
<UnlockIcon className="text-warning" gapRight /> | ||
<DateTime unixts={lock.unlockedAt} showSeconds /> | ||
</> | ||
)} | ||
</td> | ||
<td className="shrink-col text-nowrap"> | ||
<code>{lock.remoteAddr}</code> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
) : ( | ||
<div className="text-center text-muted p-4"> | ||
<em> | ||
<FormattedMessage | ||
id="app.locksTable.noLockedStudents" | ||
defaultMessage="There are no lock records for the selected exam." | ||
/> | ||
</em> | ||
</div> | ||
); | ||
|
||
LocksTable.propTypes = { | ||
locks: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default LocksTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import LocksTable from './LocksTable'; | ||
export default LocksTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { handleActions } from 'redux-actions'; | ||
import factory, { initialState } from '../helpers/resourceManager'; | ||
|
||
/** | ||
* Create actions & reducer | ||
*/ | ||
|
||
const resourceName = 'groupExamLocks'; | ||
const { actions, reduceActions } = factory({ | ||
resourceName, | ||
apiEndpointFactory: id => `/groups/${id}`, // its a hack, id is expected to be <groupId>/exam/<examId> | ||
}); | ||
|
||
export const fetchGroupExamLocksIfNeeded = (groupId, examId) => actions.fetchOneIfNeeded(`${groupId}/exam/${examId}`); | ||
|
||
const reducer = handleActions(Object.assign({}, reduceActions, {}), initialState); | ||
|
||
export default reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
const getGroupExamLocks = state => state.groupExamLocks; | ||
const getGroupExamLocksResources = state => getGroupExamLocks(state).get('resources'); | ||
const getParams = (_, groupId, examId) => `${groupId}/exam/${examId}`; | ||
|
||
export const groupExamLocksSelector = createSelector([getGroupExamLocksResources, getParams], (locks, id) => | ||
locks.get(id) | ||
); |