Skip to content

Commit b72b813

Browse files
committed
Set filename for Contests and Overall Leaderboard csv
1 parent 7f65d1c commit b72b813

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/pages/leaderboard/subcomponents/ContestLeaderboard.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const ContestLeaderboard: React.FC<Props> = ({ type, contestID }) => {
3333
// TODO: Only display rows when contest voting counterpart has voting published
3434

3535
// Retrieve Contest Score Data from store
36-
console.log(contestID);
37-
console.log(useTypedSelector(store => store.session.assessmentOverviews));
3836
const rankedLeaderboard: ContestLeaderboardRow[] = useTypedSelector(store =>
3937
type === 'score' ? store.leaderboard.contestScore : store.leaderboard.contestPopularVote
4038
);
@@ -58,6 +56,7 @@ const ContestLeaderboard: React.FC<Props> = ({ type, contestID }) => {
5856
published: contest.isPublished,
5957
voting: contest.hasVotingFeatures
6058
}));
59+
const contestName = contestDetails.find(contest => contest.contest_id === contestID)?.title;
6160

6261
// Temporary loading of leaderboard background
6362
useEffect(() => {
@@ -154,7 +153,7 @@ const ContestLeaderboard: React.FC<Props> = ({ type, contestID }) => {
154153
<LeaderboardDropdown contests={contestDetails} />
155154

156155
{/* Export Button */}
157-
<LeaderboardExportButton type="contest" data={rankedLeaderboard}/>
156+
<LeaderboardExportButton type="contest" contest={contestName} data={rankedLeaderboard}/>
158157
</div>
159158

160159
{/* Leaderboard Table (Top 3) */}

src/pages/leaderboard/subcomponents/LeaderboardExportButton.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import { ContestLeaderboardRow, LeaderboardRow } from 'src/features/leaderboard/
77
import { Role } from '../../../commons/application/ApplicationTypes';
88

99
type Props =
10-
| { type: "contest"; data: ContestLeaderboardRow[] }
11-
| { type: "overall"; data: LeaderboardRow[] };
10+
| { type: "contest"; contest: string | undefined; data: ContestLeaderboardRow[] }
11+
| { type: "overall"; contest: string | undefined; data: LeaderboardRow[] };
1212

13-
const LeaderboardExportButton: React.FC<Props> = ({ type, data }) => {
13+
const LeaderboardExportButton: React.FC<Props> = ({ type, contest, data }) => {
1414
const role = useTypedSelector(store => store.session.role);
1515
const exportCSV = () => {
16-
const headers = ['Rank', 'Name', 'Username', (type == "overall" ? 'XP' : 'Score'), (type == "overall" ? 'Achievements' : 'Submission Id')];
16+
const headers = ['Rank', 'Name', 'Username', (type === "overall" ? 'XP' : 'Score'), (type === "overall" ? 'Achievements' : 'Submission Id')];
1717
const rows = data?.map(player => [
1818
player.rank,
1919
player.name,
2020
player.username,
21-
type == "overall" ? (player as LeaderboardRow).xp : (player as ContestLeaderboardRow).score,
22-
type == "overall" ? (player as LeaderboardRow).achievements : (player as ContestLeaderboardRow).submissionId
21+
type === "overall" ? (player as LeaderboardRow).xp : (player as ContestLeaderboardRow).score,
22+
type === "overall" ? (player as LeaderboardRow).achievements : (player as ContestLeaderboardRow).submissionId
2323
]);
2424

2525
// Combine headers and rows
@@ -28,7 +28,7 @@ const LeaderboardExportButton: React.FC<Props> = ({ type, data }) => {
2828
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
2929
const link = document.createElement('a');
3030
link.href = URL.createObjectURL(blob);
31-
link.download = 'leaderboard.csv'; // Filename for download
31+
link.download = type === "overall" ? 'Overall Leaderboard.csv' : `${contest} Leaderboard.csv`; // Filename for download
3232
link.click();
3333
};
3434

src/pages/leaderboard/subcomponents/OverallLeaderboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const OverallLeaderboard: React.FC = () => {
108108
<LeaderboardDropdown contests={contestDetails} />
109109

110110
{/* Export Button */}
111-
<LeaderboardExportButton type="overall" data={rankedLeaderboard} />
111+
<LeaderboardExportButton type="overall" contest={undefined} data={rankedLeaderboard} />
112112
</div>
113113

114114
{/* Leaderboard Table (Replaced with ag-Grid) */}

0 commit comments

Comments
 (0)