Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion serverless/app/handlers/__tests__/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('../../../lib/StorageClient', () => ({
jest.mock('xlsx', () => ({
utils: {
book_new: jest.fn(),
json_to_sheet: jest.fn(),
json_to_sheet: jest.fn().mockReturnValue({}),
book_append_sheet: jest.fn(),
},
write: jest.fn().mockReturnValue(Buffer.from('mock-excel-content')),
Expand Down
17 changes: 17 additions & 0 deletions serverless/app/handlers/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ export const handler: APIGatewayProxyHandler = async event => {
// Create workbook and worksheet
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(rows);

// Auto-fit columns
if (rows.length > 0) {
const headers = Object.keys(rows[0]);
const colWidths = headers.map(key => {
let maxLength = key.length;
rows.forEach(row => {
const val = row[key as keyof ExportRow];
const len = val ? String(val).length : 0;
if (len > maxLength) maxLength = len;
});
// Cap the width at 50 to prevent massive columns, but ensure at least 10
return { wch: Math.min(Math.max(maxLength + 2, 10), 50) };
});
ws['!cols'] = colWidths;
}

XLSX.utils.book_append_sheet(wb, ws, 'Cases');

// Generate buffer
Expand Down
99 changes: 4 additions & 95 deletions serverless/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"cheerio": "^1.0.0",
"humanparser": "^2.7.0",
"tough-cookie": "^5.1.2",
"xlsx": "^0.18.5"
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
},
"scripts": {
"test": "jest",
Expand Down
Loading