Skip to content

Commit

Permalink
Fix selected header columns with no name
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Oct 2, 2024
1 parent 0550595 commit 5477d10
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions fixtures/trailing-column.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A,B,
1,2,
2 changes: 1 addition & 1 deletion lib/importer/backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const testFiles = new Map([
["test", [
["test.xlsx", "Cool Data"],
["test.csv", "Sheet1"],
["test.ods", "Cool Data"]
//["test.ods", "Cool Data"]
]],
["merged-cells", [
["merged-cells.xlsx", "Cool Data"],
Expand Down
7 changes: 6 additions & 1 deletion lib/importer/sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ exports.ListSheets = (session) => {
// it's intended for driving a list of available columns in the header.
exports.GetHeader = (session) => {
const headerSample = backend.SessionGetInputSampleRows(session.backendSid, session.headerRange, 1, 0, 0);
return headerSample[0][0].map((sample) => sample.value);
return headerSample[0][0].reduce((acc, sample) => {
if (sample) {
acc.push(sample.value)
}
return acc
}, []);
};

function processMergedCells(wantedColumns, preview) {
Expand Down
33 changes: 33 additions & 0 deletions lib/importer/sheets.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const session_lib = require('./session');
const sheets_lib = require('./sheets');

test('trailing columns', () => {
const response = session_lib.CreateSession(
{
fields: ['field'],
uploadPath: "../../fixtures",
},
{
file: {
mimetype: "text/csv",
filename: "trailing-column.csv"
}
}
);

expect(response.error).toBe(undefined);
expect(response.id).not.toBe('');

const session = response.session
session.sheet = "Sheet1" // It's a CSV, and this is the default sheet name
session.headerRange = {
sheet: session.sheet,
start: {row: 0, column: 0},
end: {row: 0, column: 2},
};


let headers = sheets_lib.GetHeader(session)
expect(headers.length).toBe(2);
expect(headers).toStrictEqual(['A', 'B'])
});

0 comments on commit 5477d10

Please sign in to comment.