Skip to content

Commit 86621f4

Browse files
authored
Merge pull request #1219 from david-roper/add-group-column
feat: add subjectID as page name for excel download
2 parents 47b7479 + b4afa29 commit 86621f4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

apps/web/src/hooks/useInstrumentVisualization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
160160
}
161161
case 'Excel': {
162162
const rows = makeWideRows();
163-
downloadSubjectTableExcel(`${baseFilename}.xlsx`, rows);
163+
downloadSubjectTableExcel(`${baseFilename}.xlsx`, rows, removeSubjectIdScope(params.subjectId));
164164
break;
165165
}
166166
case 'Excel Long': {
167167
const rows = makeLongRows();
168-
downloadSubjectTableExcel(`${baseFilename}.xlsx`, rows);
168+
downloadSubjectTableExcel(`${baseFilename}.xlsx`, rows, removeSubjectIdScope(params.subjectId));
169169
break;
170170
}
171171
case 'JSON': {

apps/web/src/utils/excel.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export function downloadExcel(filename: string, recordsExport: InstrumentRecords
77
writeFileXLSX(workbook, filename);
88
}
99

10-
export function downloadSubjectTableExcel(filename: string, records: { [key: string]: any }[]) {
10+
export function downloadSubjectTableExcel(filename: string, records: { [key: string]: any }[], name: string) {
11+
const sanitizedName =
12+
name
13+
.replace(/[\\/?*[\]:]/g, '_') // Replace invalid chars
14+
.slice(0, 31) // Max 31 chars
15+
.replace(/^'|'$/g, '') // Remove leading/trailing apostrophes
16+
.trim() || 'Subject'; // Fallback if empty
1117
const workbook = utils.book_new();
12-
utils.book_append_sheet(workbook, utils.json_to_sheet(records), 'ULTRA_LONG');
18+
utils.book_append_sheet(workbook, utils.json_to_sheet(records), sanitizedName);
19+
utils.book_append_sheet(workbook, utils.json_to_sheet(records), name);
1320
writeFileXLSX(workbook, filename);
1421
}

0 commit comments

Comments
 (0)