From 114069a06e4db215dda810e7cba77f5a0cb4ce32 Mon Sep 17 00:00:00 2001 From: louwie17 Date: Thu, 23 Sep 2021 16:14:45 -0300 Subject: [PATCH] Add old option back with depreciated notice for backwards compatibility (https://github.com/woocommerce/woocommerce-admin/pull/7688) * Add old option back with depreciated notice for backwards compatibility * Add changelog * Update depreciation message --- plugins/woocommerce-admin/package-lock.json | 24 ++++++++++++++++++ .../packages/data/CHANGELOG.md | 1 + .../packages/data/package.json | 1 + .../packages/data/src/reports/utils.js | 25 +++++++++++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-admin/package-lock.json b/plugins/woocommerce-admin/package-lock.json index f6bad016c7f..698919332c3 100644 --- a/plugins/woocommerce-admin/package-lock.json +++ b/plugins/woocommerce-admin/package-lock.json @@ -10901,12 +10901,36 @@ "@wordpress/core-data": "3.0.0", "@wordpress/data": "5.0.0", "@wordpress/data-controls": "2.0.0", + "@wordpress/deprecated": "^3.1.1", "@wordpress/element": "2.19.0", "@wordpress/hooks": "2.11.0", "@wordpress/i18n": "3.17.0", "@wordpress/url": "2.21.0", "md5": "^2.3.0", "rememo": "^3.0.0" + }, + "dependencies": { + "@wordpress/deprecated": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@wordpress/deprecated/-/deprecated-3.2.1.tgz", + "integrity": "sha512-+mSpxeu0za9cNw30x9n0kZY/IUhmd9vhEzjZzLfT92lY3dDPXCEaE4IOSdPevcLpWTcKd7RhRMj2zXmaU5MA2g==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/hooks": "^3.2.0" + }, + "dependencies": { + "@wordpress/hooks": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@wordpress/hooks/-/hooks-3.2.0.tgz", + "integrity": "sha512-nVR6V9kPxl8+aYQzQJdoDt+aKBKHHD0zplcYZbu2MHxjmHMvppAeL9mjzVhQZj/3n10NR2Ftk94mHQzHWfhCCg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + } + } + } } }, "@woocommerce/date": { diff --git a/plugins/woocommerce-admin/packages/data/CHANGELOG.md b/plugins/woocommerce-admin/packages/data/CHANGELOG.md index ab713efa842..60c34f29070 100644 --- a/plugins/woocommerce-admin/packages/data/CHANGELOG.md +++ b/plugins/woocommerce-admin/packages/data/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - Fix the batch fetch logic for the options data store. #7587 +- Add backwards compability for old function format. #7688 # 1.4.0 diff --git a/plugins/woocommerce-admin/packages/data/package.json b/plugins/woocommerce-admin/packages/data/package.json index 1deba640705..9caa732026f 100644 --- a/plugins/woocommerce-admin/packages/data/package.json +++ b/plugins/woocommerce-admin/packages/data/package.json @@ -30,6 +30,7 @@ "@wordpress/hooks": "2.11.0", "@wordpress/data": "5.0.0", "@wordpress/data-controls": "2.0.0", + "@wordpress/deprecated": "^3.1.1", "@wordpress/i18n": "3.17.0", "@wordpress/url": "2.21.0", "md5": "^2.3.0", diff --git a/plugins/woocommerce-admin/packages/data/src/reports/utils.js b/plugins/woocommerce-admin/packages/data/src/reports/utils.js index 1092c022043..102c9be8ca3 100644 --- a/plugins/woocommerce-admin/packages/data/src/reports/utils.js +++ b/plugins/woocommerce-admin/packages/data/src/reports/utils.js @@ -13,6 +13,7 @@ import { getActiveFiltersFromQuery, getQueryFromActiveFilters, } from '@woocommerce/navigation'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -343,17 +344,27 @@ const getReportChartDataResponse = memoize( * @param {string} options.dataType 'primary' or 'secondary' * @param {Object} options.query Query parameters in the url * @param {Object} options.selector Instance of @wordpress/select response + * @param {Object} options.select (Depreciated) Instance of @wordpress/select * @param {Array} options.limitBy Properties used to limit the results. It will be used in the API call to send the IDs. * @param {string} options.defaultDateRange User specified default date range. * @return {Object} Object containing API request information (response, fetching, and error details) */ export function getReportChartData( options ) { const { endpoint } = options; + let reportSelectors = options.selector; + if ( options.select && ! options.selector ) { + deprecated( 'option.select', { + version: '1.7.0', + hint: + 'You can pass the report selectors through option.selector now.', + } ); + reportSelectors = options.select( STORE_NAME ); + } const { getReportStats, getReportStatsError, isResolving, - } = options.selector; + } = reportSelectors; const requestQuery = getRequestQuery( options ); // Disable eslint rule requiring `stats` to be defined below because the next two if statements @@ -492,17 +503,27 @@ export function getReportTableQuery( options ) { * @param {string} options.endpoint Report API Endpoint * @param {Object} options.query Query parameters in the url * @param {Object} options.selector Instance of @wordpress/select response + * @param {Object} options.select (depreciated) Instance of @wordpress/select * @param {Object} options.tableQuery Query parameters specific for that endpoint * @param {string} options.defaultDateRange User specified default date range. * @return {Object} Object Table data response */ export function getReportTableData( options ) { const { endpoint } = options; + let reportSelectors = options.selector; + if ( options.select && ! options.selector ) { + deprecated( 'option.select', { + version: '1.7.0', + hint: + 'You can pass the report selectors through option.selector now.', + } ); + reportSelectors = options.select( STORE_NAME ); + } const { getReportItems, getReportItemsError, hasFinishedResolution, - } = options.selector; + } = reportSelectors; const tableQuery = reportsUtils.getReportTableQuery( options ); const response = {