Skip to content

Commit

Permalink
Adding attempt index column to assignment solutions page.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Jul 30, 2023
1 parent 33bbe2d commit 849bf6c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
51 changes: 47 additions & 4 deletions src/pages/AssignmentStats/AssignmentStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ import {
fetchManyAssignmentSolutionsStatus,
isAssignmentSolversLoading,
getAssignmentSolverSelector,
getOneAssignmentSolvers,
} from '../../redux/selectors/solutions';
import { isReady, getJsData, getId } from '../../redux/helpers/resourceManager';

import { storageGetItem, storageSetItem } from '../../helpers/localStorage';
import withLinks from '../../helpers/withLinks';
import { safeGet, identity, arrayToObject, toPlainAscii, hasPermissions } from '../../helpers/common';

const prepareTableColumnDescriptors = defaultMemoize((loggedUserId, assignmentId, groupId, locale, links) => {
const prepareTableColumnDescriptors = defaultMemoize((loggedUserId, assignmentId, groupId, onlyBest, locale, links) => {
const { SOLUTION_DETAIL_URI_FACTORY, SOLUTION_SOURCE_CODES_URI_FACTORY, GROUP_USER_SOLUTIONS_URI_FACTORY } = links;
const nameComparator = createUserNameComparator(locale);

Expand Down Expand Up @@ -103,6 +104,34 @@ const prepareTableColumnDescriptors = defaultMemoize((loggedUserId, assignmentId
}
),

new SortableTableColumnDescriptor('attempt', '#', {
className: 'text-center',
cellRenderer: ({ attemptIndex, lastAttemptIndex }) => (
<small
className={
'text-nowrap' +
(onlyBest && lastAttemptIndex && lastAttemptIndex !== attemptIndex
? ' text-bold text-warning'
: ' text-muted')
}>
{!lastAttemptIndex ? (
<LoadingIcon />
) : onlyBest && lastAttemptIndex && lastAttemptIndex === attemptIndex ? (
attemptIndex
) : (
<FormattedMessage
id="app.solution.solutionAttemptValue"
defaultMessage="{index} of {count}"
values={{
index: attemptIndex,
count: lastAttemptIndex,
}}
/>
)}
</small>
),
}),

new SortableTableColumnDescriptor('user', <FormattedMessage id="generic.nameOfPerson" defaultMessage="Name" />, {
className: 'text-left',
comparator: ({ user: u1, date: d1 }, { user: u2, date: d2 }) => nameComparator(u1, u2) || d2 - d1, // dates are implicitly in reversed order
Expand Down Expand Up @@ -209,11 +238,12 @@ const prepareTableColumnDescriptors = defaultMemoize((loggedUserId, assignmentId
}),
];

return columns;
return columns.filter(c => c);
});

const prepareTableData = defaultMemoize(
(assignmentSolutions, users, runtimeEnvironments, onlyBestSolutionsCheckbox) => {
(assignmentSolutions, users, assignmentSolvers, runtimeEnvironments, onlyBestSolutionsCheckbox) => {
const solvers = (assignmentSolvers && assignmentSolvers.toJS()) || {};
const usersIndex = arrayToObject(users);
return assignmentSolutions
.toArray()
Expand All @@ -226,6 +256,7 @@ const prepareTableData = defaultMemoize(
lastSubmission,
authorId,
createdAt,
attemptIndex,
runtimeEnvironmentId,
note,
maxPoints,
Expand All @@ -245,6 +276,7 @@ const prepareTableData = defaultMemoize(
icon: { id, commentsStats, lastSubmission, accepted, review, permissionHints, isBestSolution, plagiarism },
user: usersIndex[authorId],
date: createdAt,
attempt: { attemptIndex, lastAttemptIndex: solvers[authorId] && solvers[authorId].lastAttemptIndex },
validity: statusEvaluated ? safeGet(lastSubmission, ['evaluation', 'score']) : null,
points: statusEvaluated ? { maxPoints, bonusPoints, actualPoints } : { actualPoints: null },
runtimeEnvironment: runtimeEnvironments.find(({ id }) => id === runtimeEnvironmentId),
Expand Down Expand Up @@ -354,6 +386,7 @@ class AssignmentStats extends Component {
fetchManyStatus,
assignmentSolversLoading,
assignmentSolverSelector,
assignmentSolvers,
intl: { locale },
links,
} = this.props;
Expand Down Expand Up @@ -550,11 +583,19 @@ class AssignmentStats extends Component {
noPadding>
<SortableTable
hover
columns={prepareTableColumnDescriptors(loggedUserId, assignmentId, group.id, locale, links)}
columns={prepareTableColumnDescriptors(
loggedUserId,
assignmentId,
group.id,
this.state.onlyBestSolutionsCheckbox,
locale,
links
)}
defaultOrder="date"
data={prepareTableData(
assignmentSolutions,
getStudents(group.id),
assignmentSolversLoading ? null : assignmentSolvers,
runtimes,
this.state.onlyBestSolutionsCheckbox
)}
Expand Down Expand Up @@ -595,6 +636,7 @@ AssignmentStats.propTypes = {
fetchManyStatus: PropTypes.string,
assignmentSolversLoading: PropTypes.bool,
assignmentSolverSelector: PropTypes.func.isRequired,
assignmentSolvers: ImmutablePropTypes.map,
closeReview: PropTypes.func.isRequired,
intl: PropTypes.object,
links: PropTypes.object.isRequired,
Expand Down Expand Up @@ -627,6 +669,7 @@ export default withLinks(
fetchManyStatus: fetchManyAssignmentSolutionsStatus(assignmentId)(state),
assignmentSolversLoading: isAssignmentSolversLoading(state),
assignmentSolverSelector: getAssignmentSolverSelector(state),
assignmentSolvers: getOneAssignmentSolvers(state, assignmentId),
};
},
(
Expand Down
5 changes: 5 additions & 0 deletions src/redux/selectors/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ export const getAssignmentSolverSelector = createSelector(
getAssignmentSolvers,
assignmentSolvers => (assignmentId, userId) => assignmentSolvers && assignmentSolvers.getIn([assignmentId, userId])
);

export const getOneAssignmentSolvers = createSelector(
[getAssignmentSolvers, getParam],
(assignmentSolvers, assignmentId) => assignmentSolvers && assignmentSolvers.get(assignmentId)
);

0 comments on commit 849bf6c

Please sign in to comment.