From 88c2973e2a27cfc2265cc32526cd392c3d913b19 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Fri, 22 Feb 2019 10:02:38 +0800 Subject: [PATCH] Fix null values in CSV columns export (https://github.com/woocommerce/woocommerce-admin/pull/1652) * 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 --- .../packages/components/src/table/__mocks__/table-mock-csv.js | 2 +- .../components/src/table/__mocks__/table-mock-data.js | 2 +- plugins/woocommerce-admin/packages/csv-export/CHANGELOG.md | 4 ++++ plugins/woocommerce-admin/packages/csv-export/src/index.js | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-csv.js b/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-csv.js index 835bd78fcbc..18571ad3a39 100644 --- a/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-csv.js +++ b/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-csv.js @@ -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`; diff --git a/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-data.js b/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-data.js index 433c9825df5..f2049852b89 100644 --- a/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-data.js +++ b/plugins/woocommerce-admin/packages/components/src/table/__mocks__/table-mock-data.js @@ -50,7 +50,7 @@ export default [ }, { display: '€0.00', - value: 0, + value: null, }, { display: '€0.00', diff --git a/plugins/woocommerce-admin/packages/csv-export/CHANGELOG.md b/plugins/woocommerce-admin/packages/csv-export/CHANGELOG.md index d08159f1aab..11cb67e21df 100644 --- a/plugins/woocommerce-admin/packages/csv-export/CHANGELOG.md +++ b/plugins/woocommerce-admin/packages/csv-export/CHANGELOG.md @@ -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 diff --git a/plugins/woocommerce-admin/packages/csv-export/src/index.js b/plugins/woocommerce-admin/packages/csv-export/src/index.js index 80f4f977a84..1a146e26599 100644 --- a/plugins/woocommerce-admin/packages/csv-export/src/index.js +++ b/plugins/woocommerce-admin/packages/csv-export/src/index.js @@ -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' ) : [];