From fc4cb129bc722121785070f9fc17e305f72ac222 Mon Sep 17 00:00:00 2001 From: Josh Thoo Jen Sen <110712708+josh1248@users.noreply.github.com> Date: Sat, 16 Nov 2024 20:01:16 +0800 Subject: [PATCH] Fix export CSV to retrieve all assessement entries (#3076) * Connect to backend endpoint * Apply suggestions from code review --------- Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> --- src/commons/sagas/RequestsSaga.ts | 101 +++++++++++++++----------- src/pages/academy/grading/Grading.tsx | 11 ++- 2 files changed, 70 insertions(+), 42 deletions(-) diff --git a/src/commons/sagas/RequestsSaga.ts b/src/commons/sagas/RequestsSaga.ts index 7cca18b608..29f88df173 100644 --- a/src/commons/sagas/RequestsSaga.ts +++ b/src/commons/sagas/RequestsSaga.ts @@ -640,47 +640,22 @@ export const getGradingOverviews = async ( } const gradingOverviews = await resp.json(); - return { - count: gradingOverviews.count, - data: gradingOverviews.data.map((overview: any) => { - const gradingOverview: GradingOverview = { - assessmentId: overview.assessment.id, - assessmentNumber: overview.assessment.assessmentNumber, - assessmentName: overview.assessment.title, - assessmentType: overview.assessment.type, - studentId: overview.student ? overview.student.id : -1, - studentName: overview.student ? overview.student.name : undefined, - studentNames: overview.team - ? overview.team.team_members.map((member: { name: any }) => member.name) - : undefined, - studentUsername: overview.student ? overview.student.username : undefined, - studentUsernames: overview.team - ? overview.team.team_members.map((member: { username: any }) => member.username) - : undefined, - submissionId: overview.id, - submissionStatus: overview.status, - groupName: overview.student ? overview.student.groupName : '-', - groupLeaderId: overview.student ? overview.student.groupLeaderId : undefined, - isGradingPublished: overview.isGradingPublished, - progress: backendParamsToProgressStatus( - overview.assessment.isManuallyGraded, - overview.isGradingPublished, - overview.status, - overview.gradedCount, - overview.assessment.questionCount - ), - questionCount: overview.assessment.questionCount, - gradedCount: overview.gradedCount, - // XP - initialXp: overview.xp, - xpAdjustment: overview.xpAdjustment, - currentXp: overview.xp + overview.xpAdjustment, - maxXp: overview.assessment.maxXp, - xpBonus: overview.xpBonus - }; - return gradingOverview; - }) - }; + return respToGradingOverviews(gradingOverviews); +}; + +/* + * GET /courses/{courseId}/admin/grading/all_submissions + */ +export const getAllGradingOverviews = async (tokens: Tokens): Promise => { + const resp = await request(`${courseId()}/admin/grading/all_submissions`, 'GET', { + ...tokens + }); + if (!resp) { + return null; // invalid accessToken _and_ refreshToken + } + const gradingOverviews = await resp.json(); + + return respToGradingOverviews(gradingOverviews); }; /* @@ -1556,6 +1531,50 @@ export function* handleResponseError(resp: Response | null): any { yield call(showWarningMessage, respText); } +const respToGradingOverviews = (gradingOverviews: any): GradingOverviews => { + return { + count: gradingOverviews.count, + data: gradingOverviews.data.map((overview: any) => { + const gradingOverview: GradingOverview = { + assessmentId: overview.assessment.id, + assessmentNumber: overview.assessment.assessmentNumber, + assessmentName: overview.assessment.title, + assessmentType: overview.assessment.type, + studentId: overview.student ? overview.student.id : -1, + studentName: overview.student ? overview.student.name : undefined, + studentNames: overview.team + ? overview.team.team_members.map((member: { name: any }) => member.name) + : undefined, + studentUsername: overview.student ? overview.student.username : undefined, + studentUsernames: overview.team + ? overview.team.team_members.map((member: { username: any }) => member.username) + : undefined, + submissionId: overview.id, + submissionStatus: overview.status, + groupName: overview.student ? overview.student.groupName : '-', + groupLeaderId: overview.student ? overview.student.groupLeaderId : undefined, + isGradingPublished: overview.isGradingPublished, + progress: backendParamsToProgressStatus( + overview.assessment.isManuallyGraded, + overview.isGradingPublished, + overview.status, + overview.gradedCount, + overview.assessment.questionCount + ), + questionCount: overview.assessment.questionCount, + gradedCount: overview.gradedCount, + // XP + initialXp: overview.xp, + xpAdjustment: overview.xpAdjustment, + currentXp: overview.xp + overview.xpAdjustment, + maxXp: overview.assessment.maxXp, + xpBonus: overview.xpBonus + }; + return gradingOverview; + }) + }; +}; + const courseId: () => string = () => { const id = store.getState().session.courseId; if (id) { diff --git a/src/pages/academy/grading/Grading.tsx b/src/pages/academy/grading/Grading.tsx index 5a821e367b..60a8b3d6ad 100644 --- a/src/pages/academy/grading/Grading.tsx +++ b/src/pages/academy/grading/Grading.tsx @@ -7,6 +7,7 @@ import SessionActions from 'src/commons/application/actions/SessionActions'; import { Role } from 'src/commons/application/ApplicationTypes'; import GradingFlex from 'src/commons/grading/GradingFlex'; import GradingText from 'src/commons/grading/GradingText'; +import { getAllGradingOverviews } from 'src/commons/sagas/RequestsSaga'; import SimpleDropdown from 'src/commons/SimpleDropdown'; import { useSession, useTypedSelector } from 'src/commons/utils/Hooks'; import WorkspaceActions from 'src/commons/workspace/WorkspaceActions'; @@ -58,6 +59,8 @@ const Grading: React.FC = () => { const allColsSortStates = useTypedSelector(state => state.workspaces.grading.allColsSortStates); const hasLoadedBefore = useTypedSelector(state => state.workspaces.grading.hasLoadedBefore); const requestCounter = useTypedSelector(state => state.workspaces.grading.requestCounter); + const accessToken = useTypedSelector(state => state.session.accessToken); + const refreshToken = useTypedSelector(state => state.session.refreshToken); const isLoading = useMemo(() => requestCounter > 0, [requestCounter]); @@ -165,7 +168,13 @@ const Grading: React.FC = () => {