Skip to content

Commit 5666396

Browse files
committed
Refactor leaderboard export button to escape code fields and update column names for clarity; enhance data handling in CSV export.
1 parent dcab05c commit 5666396

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/commons/sagas/RequestsSaga.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ export const getPaginatedTotalXp = async (
496496
pageSize: number,
497497
tokens: Tokens
498498
): Promise<{ rows: LeaderboardRow[]; userCount: number } | null> => {
499-
const offset = (page - 1) * pageSize
500-
const params = new URLSearchParams({'offset': `${offset}`, 'page_size': `${pageSize}`});
499+
const offset = (page - 1) * pageSize;
500+
const params = new URLSearchParams({ offset: `${offset}`, page_size: `${pageSize}` });
501501
const resp = await request(`${courseId()}/get_paginated_display?${params.toString()}`, 'GET', {
502502
...tokens
503503
});
@@ -530,7 +530,7 @@ export const getContestScoreLeaderboard = async (
530530
visibleEntries: number,
531531
tokens: Tokens
532532
): Promise<ContestLeaderboardRow[] | null> => {
533-
const params = new URLSearchParams({'visible_entries': `${visibleEntries}`})
533+
const params = new URLSearchParams({ visible_entries: `${visibleEntries}` });
534534
const resp = await request(
535535
`${courseId()}/assessments/${assessmentId}/scoreLeaderboard?${params.toString()}`,
536536
'GET',
@@ -567,7 +567,7 @@ export const getContestPopularVoteLeaderboard = async (
567567
visibleEntries: number,
568568
tokens: Tokens
569569
): Promise<ContestLeaderboardRow[] | null> => {
570-
const params = new URLSearchParams({'visible_entries': `${visibleEntries}`})
570+
const params = new URLSearchParams({ visible_entries: `${visibleEntries}` });
571571
const resp = await request(
572572
`${courseId()}/assessments/${assessmentId}/popularVoteLeaderboard?${params.toString()}`,
573573
'GET',
@@ -1343,7 +1343,7 @@ export const getScoreLeaderboard = async (
13431343
visibleEntries: number | undefined,
13441344
tokens: Tokens
13451345
): Promise<ContestEntry[] | null> => {
1346-
const params = new URLSearchParams({'visible_entries': `${visibleEntries}`})
1346+
const params = new URLSearchParams({ visible_entries: `${visibleEntries}` });
13471347
const resp = await request(
13481348
`${courseId()}/admin/assessments/${assessmentId}/scoreLeaderboard?${params.toString()}`,
13491349
'GET',
@@ -1375,7 +1375,7 @@ export const getPopularVoteLeaderboard = async (
13751375
visibleEntries: number | undefined,
13761376
tokens: Tokens
13771377
): Promise<ContestEntry[] | null> => {
1378-
const params = new URLSearchParams({'visible_entries': `${visibleEntries}`})
1378+
const params = new URLSearchParams({ visible_entries: `${visibleEntries}` });
13791379
const resp = await request(
13801380
`${courseId()}/admin/assessments/${assessmentId}/popularVoteLeaderboard?${params.toString()}`,
13811381
'GET',

src/pages/leaderboard/subcomponents/LeaderboardExportButton.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ const LeaderboardExportButton: React.FC<Props> = ({ type, contest, contestID })
5353
}
5454
}, [data]);
5555

56+
const escapeCodeField = (value: any) => {
57+
const str = value?.toString() ?? '';
58+
const escaped = str.replace(/"/g, '""');
59+
return `"${escaped}"`;
60+
};
61+
5662
const role = useTypedSelector(store => store.session.role);
5763
const exportCSV = () => {
5864
const headers = [
5965
'Rank',
6066
'Name',
6167
'Username',
6268
type === 'overall' ? 'XP' : 'Score',
63-
type === 'overall' ? 'Achievements' : 'Submission Id'
69+
type === 'overall' ? 'Achievements' : 'Code'
6470
];
6571
const rows = data?.map(
6672
(player: {
@@ -83,7 +89,7 @@ const LeaderboardExportButton: React.FC<Props> = ({ type, contest, contestID })
8389
: (player as ContestLeaderboardRow).score,
8490
type === 'overall'
8591
? (player as LeaderboardRow).achievements
86-
: (player as ContestLeaderboardRow).submissionId
92+
: escapeCodeField((player as ContestLeaderboardRow).code)
8793
]
8894
);
8995

0 commit comments

Comments
 (0)