Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Ensure Slot/Fills render in editor (#8111)
Browse files Browse the repository at this point in the history
* Wrap Checkout Edit in SlotFillProvider

Required to render Slot/Fills in the editor

* Remove editor check when rendering ExperimentalOrderShippingPackages

We want to render it in the editor and on the front end, so checking is no longer necessary

* Wrap Cart in SlotFillProvider when in editor

This is so Slot/Fills can be rendered in the preview
  • Loading branch information
opr authored Jan 6, 2023
1 parent d682079 commit 3600165
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getShippingRatesPackageCount,
getShippingRatesRateCount,
} from '@woocommerce/base-utils';
import { useStoreCart, useEditorContext } from '@woocommerce/base-context';
import { useStoreCart } from '@woocommerce/base-context';
import { CartResponseShippingRate } from '@woocommerce/types';
import { ReactElement } from 'react';

Expand Down Expand Up @@ -166,8 +166,6 @@ const ShippingRatesControl = ( {
},
context,
};
const { isEditor } = useEditorContext();

return (
<LoadingMask
isLoading={ isLoadingRates }
Expand All @@ -177,26 +175,14 @@ const ShippingRatesControl = ( {
) }
showSpinner={ true }
>
{ isEditor ? (
<ExperimentalOrderShippingPackages.Slot { ...slotFillProps } />
<ExperimentalOrderShippingPackages>
<Packages
packages={ shippingRates }
noResultsMessage={ noResultsMessage }
renderOption={ renderOption }
/>
) : (
<>
<ExperimentalOrderShippingPackages.Slot
{ ...slotFillProps }
/>
<ExperimentalOrderShippingPackages>
<Packages
packages={ shippingRates }
noResultsMessage={ noResultsMessage }
renderOption={ renderOption }
/>
</ExperimentalOrderShippingPackages>
</>
) }
</ExperimentalOrderShippingPackages>
</LoadingMask>
);
};
Expand Down
17 changes: 10 additions & 7 deletions assets/js/blocks/cart/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
import { EditorProvider, CartProvider } from '@woocommerce/base-context';
import { previewCart } from '@woocommerce/resource-previews';
import { SlotFillProvider } from '@woocommerce/blocks-checkout';

/**
* Internal dependencies
Expand Down Expand Up @@ -86,13 +87,15 @@ export const Edit = ( { className, attributes, setAttributes, clientId } ) => {
hasDarkControls,
} }
>
<CartProvider>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ defaultTemplate }
templateLock={ false }
/>
</CartProvider>
<SlotFillProvider>
<CartProvider>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ defaultTemplate }
templateLock={ false }
/>
</CartProvider>
</SlotFillProvider>
</CartBlockContext.Provider>
</EditorProvider>
</BlockErrorBoundary>
Expand Down
63 changes: 33 additions & 30 deletions assets/js/blocks/checkout/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ToggleControl,
CheckboxControl,
} from '@wordpress/components';
import { SlotFillProvider } from '@woocommerce/blocks-checkout';
import type { TemplateArray } from '@wordpress/blocks';
import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt';

Expand Down Expand Up @@ -147,38 +148,40 @@ export const Edit = ( {
<EditorProvider
previewData={ { previewCart, previewSavedPaymentMethods } }
>
<CheckoutProvider>
<SidebarLayout
className={ classnames( 'wc-block-checkout', {
'has-dark-controls': attributes.hasDarkControls,
} ) }
>
<CheckoutBlockControlsContext.Provider
value={ { addressFieldControls } }
<SlotFillProvider>
<CheckoutProvider>
<SidebarLayout
className={ classnames( 'wc-block-checkout', {
'has-dark-controls': attributes.hasDarkControls,
} ) }
>
<CheckoutBlockContext.Provider
value={ {
showCompanyField,
requireCompanyField,
showApartmentField,
showPhoneField,
requirePhoneField,
showOrderNotes,
showPolicyLinks,
showReturnToCart,
cartPageId,
showRateAfterTaxName,
} }
<CheckoutBlockControlsContext.Provider
value={ { addressFieldControls } }
>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ defaultTemplate }
templateLock="insert"
/>
</CheckoutBlockContext.Provider>
</CheckoutBlockControlsContext.Provider>
</SidebarLayout>
</CheckoutProvider>
<CheckoutBlockContext.Provider
value={ {
showCompanyField,
requireCompanyField,
showApartmentField,
showPhoneField,
requirePhoneField,
showOrderNotes,
showPolicyLinks,
showReturnToCart,
cartPageId,
showRateAfterTaxName,
} }
>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ defaultTemplate }
templateLock="insert"
/>
</CheckoutBlockContext.Provider>
</CheckoutBlockControlsContext.Provider>
</SidebarLayout>
</CheckoutProvider>
</SlotFillProvider>
</EditorProvider>
</div>
);
Expand Down

0 comments on commit 3600165

Please sign in to comment.