From 849bf6c0f2a58200ba38658691b796517c220289 Mon Sep 17 00:00:00 2001 From: Martin Krulis Date: Thu, 8 Jun 2023 16:54:52 +0200 Subject: [PATCH] Adding attempt index column to assignment solutions page. --- src/pages/AssignmentStats/AssignmentStats.js | 51 ++++++++++++++++++-- src/redux/selectors/solutions.js | 5 ++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/pages/AssignmentStats/AssignmentStats.js b/src/pages/AssignmentStats/AssignmentStats.js index 43d768c53..8438e1419 100644 --- a/src/pages/AssignmentStats/AssignmentStats.js +++ b/src/pages/AssignmentStats/AssignmentStats.js @@ -63,6 +63,7 @@ import { fetchManyAssignmentSolutionsStatus, isAssignmentSolversLoading, getAssignmentSolverSelector, + getOneAssignmentSolvers, } from '../../redux/selectors/solutions'; import { isReady, getJsData, getId } from '../../redux/helpers/resourceManager'; @@ -70,7 +71,7 @@ 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); @@ -103,6 +104,34 @@ const prepareTableColumnDescriptors = defaultMemoize((loggedUserId, assignmentId } ), + new SortableTableColumnDescriptor('attempt', '#', { + className: 'text-center', + cellRenderer: ({ attemptIndex, lastAttemptIndex }) => ( + + {!lastAttemptIndex ? ( + + ) : onlyBest && lastAttemptIndex && lastAttemptIndex === attemptIndex ? ( + attemptIndex + ) : ( + + )} + + ), + }), + new SortableTableColumnDescriptor('user', , { className: 'text-left', comparator: ({ user: u1, date: d1 }, { user: u2, date: d2 }) => nameComparator(u1, u2) || d2 - d1, // dates are implicitly in reversed order @@ -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() @@ -226,6 +256,7 @@ const prepareTableData = defaultMemoize( lastSubmission, authorId, createdAt, + attemptIndex, runtimeEnvironmentId, note, maxPoints, @@ -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), @@ -354,6 +386,7 @@ class AssignmentStats extends Component { fetchManyStatus, assignmentSolversLoading, assignmentSolverSelector, + assignmentSolvers, intl: { locale }, links, } = this.props; @@ -550,11 +583,19 @@ class AssignmentStats extends Component { noPadding> (assignmentId, userId) => assignmentSolvers && assignmentSolvers.getIn([assignmentId, userId]) ); + +export const getOneAssignmentSolvers = createSelector( + [getAssignmentSolvers, getParam], + (assignmentSolvers, assignmentId) => assignmentSolvers && assignmentSolvers.get(assignmentId) +);