rebase on oct-10-2023
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import PropTypes from 'prop-types';
|
||||
import { createContext, useContext } from '@wordpress/element';
|
||||
|
||||
/**
|
||||
@@ -20,14 +19,23 @@ const InnerBlockLayoutContext = createContext( {
|
||||
export const useInnerBlockLayoutContext = () =>
|
||||
useContext( InnerBlockLayoutContext );
|
||||
|
||||
interface InnerBlockLayoutContextProviderProps {
|
||||
parentName?: string;
|
||||
parentClassName?: string;
|
||||
isLoading?: boolean;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const InnerBlockLayoutContextProvider = ( {
|
||||
parentName = '',
|
||||
parentClassName = '',
|
||||
isLoading = false,
|
||||
children,
|
||||
} ) => {
|
||||
}: InnerBlockLayoutContextProviderProps ) => {
|
||||
const contextValue = {
|
||||
parentName,
|
||||
parentClassName,
|
||||
isLoading,
|
||||
};
|
||||
return (
|
||||
<InnerBlockLayoutContext.Provider value={ contextValue }>
|
||||
@@ -35,9 +43,3 @@ export const InnerBlockLayoutContextProvider = ( {
|
||||
</InnerBlockLayoutContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
InnerBlockLayoutContextProvider.propTypes = {
|
||||
children: PropTypes.node,
|
||||
parentName: PropTypes.string,
|
||||
parentClassName: PropTypes.string,
|
||||
};
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
useProductDataContext,
|
||||
} from '@woocommerce/shared-context';
|
||||
|
||||
const getProductById = ( products, id ) =>
|
||||
products.find( ( product ) => product.id === id );
|
||||
|
||||
/**
|
||||
* Loads the product from the API and adds to the context provider.
|
||||
*
|
||||
@@ -22,7 +25,10 @@ const OriginalComponentWithContext = ( props ) => {
|
||||
} );
|
||||
|
||||
const productFromAPI = {
|
||||
product: id > 0 && products.length > 0 ? products[ 0 ] : null,
|
||||
product:
|
||||
id > 0 && products.length > 0
|
||||
? getProductById( products, id )
|
||||
: null,
|
||||
isLoading: productsLoading,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user