Skip to content

Commit

Permalink
Fix export CSV to retrieve all assessement entries (#3076)
Browse files Browse the repository at this point in the history
* Connect to backend endpoint

* Apply suggestions from code review

---------

Co-authored-by: Richard Dominick <[email protected]>
  • Loading branch information
josh1248 and RichDom2185 authored Nov 16, 2024
1 parent 9805da3 commit fc4cb12
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 42 deletions.
101 changes: 60 additions & 41 deletions src/commons/sagas/RequestsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GradingOverviews | null> => {
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);
};

/*
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion src/pages/academy/grading/Grading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -165,7 +168,13 @@ const Grading: React.FC = () => {
<Button
minimal
icon={IconNames.EXPORT}
onClick={() => exportGradingCSV(gradingOverviews.data)}
onClick={() => {
const tokens = {
accessToken: accessToken!,
refreshToken: refreshToken!
};
getAllGradingOverviews(tokens).then(resp => exportGradingCSV(resp?.data));
}}
className="export-csv-btn"
>
Export to CSV
Expand Down

0 comments on commit fc4cb12

Please sign in to comment.