* Fix null values in CSV columns export

* Check if value is null or undefined to avoid falsey for 0 values

* Add null value to CSV tests

* Improve changelog message
This commit is contained in:
Joshua T Flowers 2019-02-22 10:02:38 +08:00 committed by GitHub
parent 9c95a62f3b
commit 88c2973e2a
4 changed files with 9 additions and 3 deletions

View File

@ -2,4 +2,4 @@
export default `Date,Orders,Gross Revenue,Refunds,Taxes,Shipping,Net Revenue
2018-10-01 00:00:00,1,411,0,0,0,411
2018-10-02 00:00:00,0,0,0,0,0,0`;
2018-10-02 00:00:00,0,0,,0,0,0`;

View File

@ -50,7 +50,7 @@ export default [
},
{
display: '€0.00',
value: 0,
value: null,
},
{
display: '€0.00',

View File

@ -1,3 +1,7 @@
# 1.1.0
- Fix error in `getCSVRows` when there is a null or undefined column value
# 1.0.0
- Released package

View File

@ -13,7 +13,9 @@ function getCSVRows( rows ) {
return Array.isArray( rows )
? rows
.map( row =>
row.map( rowItem => rowItem.value.toString().replace( /,/g, '' ) ).join( ',' )
row.map( rowItem =>
rowItem.value !== undefined && rowItem.value !== null ? rowItem.value.toString().replace( /,/g, ''
) : '' ).join( ',' )
)
.join( '\n' )
: [];