From 995f26250e562479353299742c6af075746f2798 Mon Sep 17 00:00:00 2001 From: Timmy Crawford Date: Fri, 5 Jul 2019 07:12:03 -0700 Subject: [PATCH] Settings: Fix wsod when no actionable statuses are set. (https://github.com/woocommerce/woocommerce-admin/pull/2577) * Fix wsod when no actionable statuses are set. * Updates per feedback. --- .../client/analytics/settings/config.js | 18 +++++++++++++++--- .../includes/class-wc-admin-loader.php | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/settings/config.js b/plugins/woocommerce-admin/client/analytics/settings/config.js index 6ff8212783b..381f62252b0 100644 --- a/plugins/woocommerce-admin/client/analytics/settings/config.js +++ b/plugins/woocommerce-admin/client/analytics/settings/config.js @@ -24,6 +24,19 @@ const defaultOrderStatuses = [ 'pending', 'on-hold', ]; + +const actionableOrderStatuses = Array.isArray( + wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses +) + ? wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses + : []; + +const excludedOrderStatuses = Array.isArray( + wcSettings.wcAdminSettings.woocommerce_excluded_report_order_statuses +) + ? wcSettings.wcAdminSettings.woocommerce_excluded_report_order_statuses + : []; + const orderStatuses = Object.keys( wcSettings.orderStatuses ) .filter( status => status !== 'refunded' ) .map( key => { @@ -63,8 +76,7 @@ export const analyticsSettings = applyFilters( SETTINGS_FILTER, [ strong: , }, } ), - initialValue: - [ ...wcSettings.wcAdminSettings.woocommerce_excluded_report_order_statuses ] || [], + initialValue: [ ...excludedOrderStatuses ], defaultValue: [ 'pending', 'cancelled', 'failed' ], }, { @@ -87,7 +99,7 @@ export const analyticsSettings = applyFilters( SETTINGS_FILTER, [ 'These orders will show up in the Orders tab under the activity panel.', 'woocommerce-admin' ), - initialValue: [ ...wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses ] || [], + initialValue: [ ...actionableOrderStatuses ], defaultValue: DEFAULT_ACTIONABLE_STATUSES, }, { diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php b/plugins/woocommerce-admin/includes/class-wc-admin-loader.php index 7e5b276ecd9..c34308b4f5b 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-loader.php @@ -628,7 +628,7 @@ class WC_Admin_Loader { $settings['wcAdminSettings'] = array(); foreach ( $wc_admin_group_settings as $setting ) { - if ( ! empty( $setting['id'] ) && ! empty( $setting['value'] ) ) { + if ( ! empty( $setting['id'] ) ) { $settings['wcAdminSettings'][ $setting['id'] ] = $setting['value']; } }