Skip to content

Commit

Permalink
fix(csv): Base CSV viewer column count on longest row
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoffan committed Aug 28, 2019
1 parent 6716307 commit b7ed483
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/viewers/text/BoxCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class BoxCSV {
*/
renderCSV() {
const rowCount = this.data.length;
const columnCount = this.data[0].length;
const rowSample = this.data.sort((a, b) => b.length - a.length)[0]; // Find the row with the most columns
const columnCount = rowSample.length;

const maxWidth = this.csvEl.clientWidth;
const maxHeight = this.csvEl.clientHeight;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/viewers/text/__tests__/BoxCSV-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ describe('lib/viewers/text/BoxCSV', () => {
expect(gridComponent.props.rowCount).to.equal(3);
expect(renderStub).to.be.calledWith(gridComponent, csvComponent.csvEl);
});

it('should base its column count based on the longest available row', () => {
const renderStub = sandbox.stub(ReactDOM, 'render');
csvComponent.data = [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2]];
csvComponent.renderCSV();

const gridComponent = renderStub.firstCall.args[0];
expect(gridComponent.props.columnCount).to.equal(4);
});
});
});

0 comments on commit b7ed483

Please sign in to comment.