* OBW: utils, get plugins from dataStore

* better

* add installedPlugins argument
This commit is contained in:
Paul Sealock 2020-05-25 12:26:08 +12:00 committed by GitHub
parent cbc96b0253
commit 96a4856940
4 changed files with 32 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import { decodeEntities } from '@wordpress/html-entities';
*/
import { getSetting } from '@woocommerce/wc-admin-settings';
import { List } from '@woocommerce/components';
import { PLUGINS_STORE_NAME } from '@woocommerce/data';
/**
* Internal dependencies
@ -170,8 +171,14 @@ class CartModal extends Component {
export default compose(
withSelect( ( select ) => {
const { getProfileItems } = select( 'wc-api' );
const { getInstalledPlugins } = select( PLUGINS_STORE_NAME );
const profileItems = getProfileItems();
const productIds = getProductIdsForCart( profileItems );
const installedPlugins = getInstalledPlugins();
const productIds = getProductIdsForCart(
profileItems,
false,
installedPlugins
);
return { profileItems, productIds };
} )

View File

@ -42,11 +42,13 @@ export function getCurrencyRegion( countryState ) {
*
* @param {Object} profileItems Onboarding profile.
* @param {boolean} includeInstalledItems Include installed items in returned product IDs.
* @param {Array} installedPlugins Installed plugins.
* @return {Array} Product Ids.
*/
export function getProductIdsForCart(
profileItems,
includeInstalledItems = false
includeInstalledItems = false,
installedPlugins
) {
const onboarding = getSetting( 'onboarding', {} );
@ -57,7 +59,6 @@ export function getProductIdsForCart(
}
const productIds = [];
const plugins = getSetting( 'plugins', {} );
const productTypes = profileItems.product_types || [];
productTypes.forEach( ( productType ) => {
@ -65,7 +66,7 @@ export function getProductIdsForCart(
onboarding.productTypes[ productType ] &&
onboarding.productTypes[ productType ].product &&
( includeInstalledItems ||
! plugins.installedPlugins.includes(
! installedPlugins.includes(
onboarding.productTypes[ productType ].slug
) )
) {

View File

@ -102,13 +102,19 @@ class TaskDashboard extends Component {
}
getTasks() {
const { profileItems, query, taskListPayments } = this.props;
const {
profileItems,
query,
taskListPayments,
installedPlugins,
} = this.props;
return getAllTasks( {
profileItems,
options: taskListPayments,
query,
toggleCartModal: this.toggleCartModal.bind( this ),
installedPlugins,
} ).filter( ( task ) => task.visible );
}
@ -442,10 +448,12 @@ export default compose(
[ 'woocommerce_task_list_tracked_completed_tasks' ],
[]
);
const installedPlugins = getInstalledPlugins();
const tasks = getAllTasks( {
profileItems,
options: getOptions( [ 'woocommerce_task_list_payments' ] ),
query: props.query,
installedPlugins,
} );
const completedTaskKeys = tasks
.filter( ( task ) => task.completed )
@ -454,7 +462,6 @@ export default compose(
( task ) => task.visible && ! task.completed
);
const activePlugins = getActivePlugins();
const installedPlugins = getInstalledPlugins();
return {
modalDismissed,

View File

@ -28,6 +28,7 @@ export function getAllTasks( {
options,
query,
toggleCartModal,
installedPlugins,
} ) {
const {
hasPhysicalProducts,
@ -43,8 +44,16 @@ export function getAllTasks( {
shippingZonesCount: 0,
} );
const productIds = getProductIdsForCart( profileItems, true );
const remainingProductIds = getProductIdsForCart( profileItems );
const productIds = getProductIdsForCart(
profileItems,
true,
installedPlugins
);
const remainingProductIds = getProductIdsForCart(
profileItems,
false,
installedPlugins
);
const paymentsCompleted = get(
options,