Remove Shipping calculator settings and link to the WooCommerce admin settings (https://github.com/woocommerce/woocommerce-blocks/pull/11184)

* Remove block level options in favour of settings

* Remove calculator toggle test

* Update assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.tsx

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Remove unused attributes

---------

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
This commit is contained in:
Mike Jolley 2023-10-11 15:09:43 +01:00 committed by GitHub
parent cffea366a5
commit 2044798af6
18 changed files with 55 additions and 190 deletions

View File

@ -1,18 +0,0 @@
/**
* External dependencies
*/
import { getSetting } from '@woocommerce/settings';
export default {
isShippingCalculatorEnabled: {
type: 'boolean',
default: getSetting( 'isShippingCalculatorEnabled', true ),
},
lock: {
type: 'object',
default: {
move: false,
remove: true,
},
},
};

View File

@ -5,14 +5,9 @@ import { TotalsShipping } from '@woocommerce/base-components/cart-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';
import { TotalsWrapper } from '@woocommerce/blocks-checkout';
import { getSetting } from '@woocommerce/settings';
const Block = ( {
className,
isShippingCalculatorEnabled,
}: {
className: string;
isShippingCalculatorEnabled: boolean;
} ): JSX.Element | null => {
const Block = ( { className }: { className: string } ): JSX.Element | null => {
const { cartTotals, cartNeedsShipping } = useStoreCart();
if ( ! cartNeedsShipping ) {
@ -24,7 +19,10 @@ const Block = ( {
return (
<TotalsWrapper className={ className }>
<TotalsShipping
showCalculator={ isShippingCalculatorEnabled }
showCalculator={ getSetting< boolean >(
'isShippingCalculatorEnabled',
true
) }
showRateSelector={ true }
values={ cartTotals }
currency={ totalsCurrency }

View File

@ -3,8 +3,8 @@
*/
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, ToggleControl } from '@wordpress/components';
import { getSetting } from '@woocommerce/settings';
import { PanelBody, ExternalLink } from '@wordpress/components';
import { ADMIN_URL, getSetting } from '@woocommerce/settings';
import Noninteractive from '@woocommerce/base-components/noninteractive';
/**
@ -14,19 +14,16 @@ import Block from './block';
export const Edit = ( {
attributes,
setAttributes,
}: {
attributes: {
isShippingCalculatorEnabled: boolean;
className: string;
lock: {
move: boolean;
remove: boolean;
};
};
setAttributes: ( attributes: Record< string, unknown > ) => void;
} ): JSX.Element => {
const { isShippingCalculatorEnabled, className } = attributes;
const { className } = attributes;
const shippingEnabled = getSetting( 'shippingEnabled', true );
const blockProps = useBlockProps();
@ -36,35 +33,29 @@ export const Edit = ( {
{ !! shippingEnabled && (
<PanelBody
title={ __(
'Shipping rates',
'Shipping Calculations',
'woo-gutenberg-products-block'
) }
>
<ToggleControl
label={ __(
'Shipping calculator',
<p className="wc-block-checkout__controls-text">
{ __(
'Options that control shipping can be managed in your store settings.',
'woo-gutenberg-products-block'
) }
help={ __(
'Allow customers to estimate shipping by entering their address.',
</p>
<ExternalLink
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=options` }
>
{ __(
'Manage shipping options',
'woo-gutenberg-products-block'
) }
checked={ isShippingCalculatorEnabled }
onChange={ () =>
setAttributes( {
isShippingCalculatorEnabled:
! isShippingCalculatorEnabled,
} )
}
/>
</ExternalLink>{ ' ' }
</PanelBody>
) }
</InspectorControls>
<Noninteractive>
<Block
className={ className }
isShippingCalculatorEnabled={ isShippingCalculatorEnabled }
/>
<Block className={ className } />
</Noninteractive>
</div>
);

View File

@ -1,12 +1,6 @@
/**
* External dependencies
*/
import { withFilteredAttributes } from '@woocommerce/shared-hocs';
/**
* Internal dependencies
*/
import Block from './block';
import attributes from './attributes';
export default withFilteredAttributes( attributes )( Block );
export default Block;

View File

@ -9,7 +9,6 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import attributes from './attributes';
registerBlockType( 'woocommerce/cart-order-summary-shipping-block', {
icon: {
@ -20,7 +19,6 @@ registerBlockType( 'woocommerce/cart-order-summary-shipping-block', {
/>
),
},
attributes,
edit: Edit,
save: Save,
} );

View File

@ -40,15 +40,10 @@ jest.mock( '@wordpress/compose', () => ( {
const CartBlock = ( {
attributes = {
showRateAfterTaxName: false,
isShippingCalculatorEnabled: false,
checkoutPageId: 0,
},
} ) => {
const {
showRateAfterTaxName,
isShippingCalculatorEnabled,
checkoutPageId,
} = attributes;
const { showRateAfterTaxName, checkoutPageId } = attributes;
return (
<Cart attributes={ attributes }>
<FilledCart>
@ -59,11 +54,7 @@ const CartBlock = ( {
<OrderSummaryBlock>
<OrderSummaryHeadingBlock />
<OrderSummarySubtotalBlock />
<OrderSummaryShippingBlock
isShippingCalculatorEnabled={
isShippingCalculatorEnabled
}
/>
<OrderSummaryShippingBlock />
<OrderSummaryTaxesBlock
showRateAfterTaxName={ showRateAfterTaxName }
/>

View File

@ -49,7 +49,7 @@ export const Edit = ( {
>
<p className="wc-block-checkout__controls-text">
{ __(
'Account creation and guest checkout settings can be managed in the WooCommerce settings.',
'Account creation and guest checkout settings can be managed in your store settings.',
'woo-gutenberg-products-block'
) }
</p>

View File

@ -44,8 +44,4 @@ export default {
remove: true,
},
},
shippingCostRequiresAddress: {
type: 'boolean',
default: false,
},
};

View File

@ -19,10 +19,6 @@
"remove": true,
"move": true
}
},
"shippingCostRequiresAddress": {
"type": "boolean",
"default": false
}
},
"parent": [ "woocommerce/checkout-fields-block" ],

View File

@ -13,6 +13,7 @@ import { useEffect } from '@wordpress/element';
import { CART_STORE_KEY, VALIDATION_STORE_KEY } from '@woocommerce/block-data';
import { useDispatch, useSelect } from '@wordpress/data';
import { isPackageRateCollectable } from '@woocommerce/base-utils';
import { getSetting } from '@woocommerce/settings';
/**
* Internal dependencies
@ -164,17 +165,19 @@ const Block = ( {
showIcon,
localPickupText,
shippingText,
shippingCostRequiresAddress = false,
}: {
checked: string;
onChange: ( value: string ) => void;
showPrice: boolean;
showIcon: boolean;
shippingCostRequiresAddress: boolean;
localPickupText: string;
shippingText: string;
} ): JSX.Element | null => {
const { shippingRates } = useShippingData();
const shippingCostRequiresAddress = getSetting< boolean >(
'shippingCostRequiresAddress',
false
);
return (
<RadioGroup

View File

@ -23,8 +23,6 @@ import { innerBlockAreas } from '@woocommerce/blocks-checkout';
import { useDispatch, useSelect } from '@wordpress/data';
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
import ExternalLinkCard from '@woocommerce/editor-components/external-link-card';
import { Attributes } from '@woocommerce/blocks/checkout/types';
import { updateAttributeInSiblingBlock } from '@woocommerce/utils';
/**
* Internal dependencies
@ -154,9 +152,7 @@ const ShippingSelector = ( {
export const Edit = ( {
attributes,
setAttributes,
clientId,
}: {
clientId: string;
attributes: {
title: string;
description: string;
@ -167,16 +163,9 @@ export const Edit = ( {
showPrice: boolean;
showIcon: boolean;
className: string;
shippingCostRequiresAddress: boolean;
};
setAttributes: ( attributes: Record< string, unknown > ) => void;
} ): JSX.Element | null => {
const toggleAttribute = ( key: keyof Attributes ): void => {
const newAttributes = {} as Partial< Attributes >;
newAttributes[ key ] = ! ( attributes[ key ] as boolean );
setAttributes( newAttributes );
};
const { setPrefersCollection } = useDispatch( CHECKOUT_STORE_KEY );
const { prefersCollection } = useSelect( ( select ) => {
const checkoutStore = select( CHECKOUT_STORE_KEY );
@ -221,30 +210,6 @@ export const Edit = ( {
) }
>
<InspectorControls>
<PanelBody
title={ __(
'Calculations',
'woo-gutenberg-products-block'
) }
>
<ToggleControl
label={ __(
'Hide shipping costs until an address is entered',
'woo-gutenberg-products-block'
) }
checked={ attributes.shippingCostRequiresAddress }
onChange={ ( selected ) => {
updateAttributeInSiblingBlock(
clientId,
'shippingCostRequiresAddress',
selected,
'woocommerce/checkout-shipping-methods-block'
);
toggleAttribute( 'shippingCostRequiresAddress' );
} }
/>
</PanelBody>
<PanelBody
title={ __( 'Appearance', 'woo-gutenberg-products-block' ) }
>

View File

@ -25,12 +25,10 @@ const FrontendBlock = ( {
showIcon,
shippingText,
localPickupText,
shippingCostRequiresAddress,
}: {
title: string;
description: string;
showStepNumber: boolean;
shippingCostRequiresAddress: boolean;
children: JSX.Element;
className?: string;
showPrice: boolean;
@ -92,7 +90,6 @@ const FrontendBlock = ( {
showIcon={ showIcon }
localPickupText={ localPickupText }
shippingText={ shippingText }
shippingCostRequiresAddress={ shippingCostRequiresAddress }
/>
{ children }
</FormStep>

View File

@ -24,8 +24,4 @@ export default {
remove: true,
},
},
shippingCostRequiresAddress: {
type: 'boolean',
default: false,
},
};

View File

@ -19,10 +19,6 @@
"remove": true,
"move": true
}
},
"shippingCostRequiresAddress": {
"type": "boolean",
"default": false
}
},
"parent": [ "woocommerce/checkout-fields-block" ],

View File

@ -4,14 +4,12 @@
import classnames from 'classnames';
import { __ } from '@wordpress/i18n';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, ExternalLink, ToggleControl } from '@wordpress/components';
import { PanelBody, ExternalLink } from '@wordpress/components';
import { ADMIN_URL, getSetting } from '@woocommerce/settings';
import ExternalLinkCard from '@woocommerce/editor-components/external-link-card';
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
import { useCheckoutAddress } from '@woocommerce/base-context/hooks';
import Noninteractive from '@woocommerce/base-components/noninteractive';
import { Attributes } from '@woocommerce/blocks/checkout/types';
import { updateAttributeInSiblingBlock } from '@woocommerce/utils';
/**
* Internal dependencies
@ -34,15 +32,12 @@ type shippingAdminLink = {
export const Edit = ( {
attributes,
setAttributes,
clientId,
}: {
clientId: string;
attributes: {
title: string;
description: string;
showStepNumber: boolean;
className: string;
shippingCostRequiresAddress: boolean;
};
setAttributes: ( attributes: Record< string, unknown > ) => void;
} ): JSX.Element | null => {
@ -59,12 +54,6 @@ export const Edit = ( {
return null;
}
const toggleAttribute = ( key: keyof Attributes ): void => {
const newAttributes = {} as Partial< Attributes >;
newAttributes[ key ] = ! ( attributes[ key ] as boolean );
setAttributes( newAttributes );
};
return (
<FormStepBlock
attributes={ attributes }
@ -77,26 +66,24 @@ export const Edit = ( {
<InspectorControls>
<PanelBody
title={ __(
'Calculations',
'Shipping Calculations',
'woo-gutenberg-products-block'
) }
>
<ToggleControl
label={ __(
'Hide shipping costs until an address is entered',
<p className="wc-block-checkout__controls-text">
{ __(
'Options that control shipping can be managed in your store settings.',
'woo-gutenberg-products-block'
) }
checked={ attributes.shippingCostRequiresAddress }
onChange={ ( selected ) => {
updateAttributeInSiblingBlock(
clientId,
'shippingCostRequiresAddress',
selected,
'woocommerce/checkout-shipping-method-block'
);
toggleAttribute( 'shippingCostRequiresAddress' );
} }
/>
</p>
<ExternalLink
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=options` }
>
{ __(
'Manage shipping options',
'woo-gutenberg-products-block'
) }
</ExternalLink>{ ' ' }
</PanelBody>
{ globalShippingMethods.length > 0 && (
<PanelBody
@ -133,11 +120,14 @@ export const Edit = ( {
) }
{ activeShippingZones.length && (
<PanelBody
title={ __( 'Zones', 'woo-gutenberg-products-block' ) }
title={ __(
'Shipping Zones',
'woo-gutenberg-products-block'
) }
>
<p className="wc-block-checkout__controls-text">
{ __(
'You currently have the following shipping zones active.',
'Shipping Zones can be made managed in your store settings.',
'woo-gutenberg-products-block'
) }
</p>
@ -151,24 +141,11 @@ export const Edit = ( {
/>
);
} ) }
<ExternalLink
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }
>
{ __(
'Manage shipping zones',
'woo-gutenberg-products-block'
) }
</ExternalLink>
</PanelBody>
) }
</InspectorControls>
<Noninteractive>
<Block
noShippingPlaceholder={ <NoShippingPlaceholder /> }
shippingCostRequiresAddress={
attributes.shippingCostRequiresAddress
}
/>
<Block noShippingPlaceholder={ <NoShippingPlaceholder /> } />
</Noninteractive>
<AdditionalFields block={ innerBlockAreas.SHIPPING_METHODS } />
</FormStepBlock>

View File

@ -9,6 +9,9 @@
+ .wc-block-editor-components-external-link-card {
margin-top: -($gap-large - $gap);
}
&:last-child {
margin-bottom: 0;
}
.wc-block-editor-components-external-link-card__content {
flex: 1 1 0;
padding-right: $gap;

View File

@ -1 +1 @@
{"title":"Checkout Block","pageContent":"<!-- wp:woocommerce/checkout -->\n<div class=\"wp-block-woocommerce-checkout wc-block-checkout is-loading\"><!-- wp:woocommerce/checkout-fields-block -->\n<div class=\"wp-block-woocommerce-checkout-fields-block\"><!-- wp:woocommerce/checkout-express-payment-block -->\n<div class=\"wp-block-woocommerce-checkout-express-payment-block\"></div>\n<!-- /wp:woocommerce/checkout-express-payment-block -->\n\n<!-- wp:woocommerce/checkout-contact-information-block -->\n<div class=\"wp-block-woocommerce-checkout-contact-information-block\"></div>\n<!-- /wp:woocommerce/checkout-contact-information-block -->\n\n<!-- wp:woocommerce/checkout-shipping-address-block -->\n<div class=\"wp-block-woocommerce-checkout-shipping-address-block\"></div>\n<!-- /wp:woocommerce/checkout-shipping-address-block -->\n\n<!-- wp:woocommerce/checkout-billing-address-block -->\n<div class=\"wp-block-woocommerce-checkout-billing-address-block\"></div>\n<!-- /wp:woocommerce/checkout-billing-address-block -->\n\n<!-- wp:woocommerce/checkout-shipping-methods-block {\"shippingCostRequiresAddress\":false} -->\n<div class=\"wp-block-woocommerce-checkout-shipping-methods-block\"></div>\n<!-- /wp:woocommerce/checkout-shipping-methods-block -->\n\n<!-- wp:woocommerce/checkout-payment-block -->\n<div class=\"wp-block-woocommerce-checkout-payment-block\"></div>\n<!-- /wp:woocommerce/checkout-payment-block -->\n\n<!-- wp:woocommerce/checkout-order-note-block -->\n<div class=\"wp-block-woocommerce-checkout-order-note-block\"></div>\n<!-- /wp:woocommerce/checkout-order-note-block -->\n\n<!-- wp:woocommerce/checkout-terms-block -->\n<div class=\"wp-block-woocommerce-checkout-terms-block\"></div>\n<!-- /wp:woocommerce/checkout-terms-block -->\n\n<!-- wp:woocommerce/checkout-actions-block -->\n<div class=\"wp-block-woocommerce-checkout-actions-block\"></div>\n<!-- /wp:woocommerce/checkout-actions-block --></div>\n<!-- /wp:woocommerce/checkout-fields-block -->\n\n<!-- wp:woocommerce/checkout-totals-block -->\n<div class=\"wp-block-woocommerce-checkout-totals-block\"><!-- wp:woocommerce/checkout-order-summary-block -->\n<div class=\"wp-block-woocommerce-checkout-order-summary-block\"></div>\n<!-- /wp:woocommerce/checkout-order-summary-block --></div>\n<!-- /wp:woocommerce/checkout-totals-block --></div>\n<!-- /wp:woocommerce/checkout -->"}
{"title":"Checkout Block","pageContent":"<!-- wp:woocommerce/checkout -->\n<div class=\"wp-block-woocommerce-checkout wc-block-checkout is-loading\"><!-- wp:woocommerce/checkout-fields-block -->\n<div class=\"wp-block-woocommerce-checkout-fields-block\"><!-- wp:woocommerce/checkout-express-payment-block -->\n<div class=\"wp-block-woocommerce-checkout-express-payment-block\"></div>\n<!-- /wp:woocommerce/checkout-express-payment-block -->\n\n<!-- wp:woocommerce/checkout-contact-information-block -->\n<div class=\"wp-block-woocommerce-checkout-contact-information-block\"></div>\n<!-- /wp:woocommerce/checkout-contact-information-block -->\n\n<!-- wp:woocommerce/checkout-shipping-address-block -->\n<div class=\"wp-block-woocommerce-checkout-shipping-address-block\"></div>\n<!-- /wp:woocommerce/checkout-shipping-address-block -->\n\n<!-- wp:woocommerce/checkout-billing-address-block -->\n<div class=\"wp-block-woocommerce-checkout-billing-address-block\"></div>\n<!-- /wp:woocommerce/checkout-billing-address-block -->\n\n<!-- wp:woocommerce/checkout-shipping-methods-block -->\n<div class=\"wp-block-woocommerce-checkout-shipping-methods-block\"></div>\n<!-- /wp:woocommerce/checkout-shipping-methods-block -->\n\n<!-- wp:woocommerce/checkout-payment-block -->\n<div class=\"wp-block-woocommerce-checkout-payment-block\"></div>\n<!-- /wp:woocommerce/checkout-payment-block -->\n\n<!-- wp:woocommerce/checkout-order-note-block -->\n<div class=\"wp-block-woocommerce-checkout-order-note-block\"></div>\n<!-- /wp:woocommerce/checkout-order-note-block -->\n\n<!-- wp:woocommerce/checkout-terms-block -->\n<div class=\"wp-block-woocommerce-checkout-terms-block\"></div>\n<!-- /wp:woocommerce/checkout-terms-block -->\n\n<!-- wp:woocommerce/checkout-actions-block -->\n<div class=\"wp-block-woocommerce-checkout-actions-block\"></div>\n<!-- /wp:woocommerce/checkout-actions-block --></div>\n<!-- /wp:woocommerce/checkout-fields-block -->\n\n<!-- wp:woocommerce/checkout-totals-block -->\n<div class=\"wp-block-woocommerce-checkout-totals-block\"><!-- wp:woocommerce/checkout-order-summary-block -->\n<div class=\"wp-block-woocommerce-checkout-order-summary-block\"></div>\n<!-- /wp:woocommerce/checkout-order-summary-block --></div>\n<!-- /wp:woocommerce/checkout-totals-block --></div>\n<!-- /wp:woocommerce/checkout -->"}

View File

@ -143,7 +143,7 @@ test.describe( 'Merchant → Cart', () => {
await expect( filledCartAudioButton ).toBeHidden();
} );
test( 'shows empty cart when changing the view and allows toggling of shipping calculator', async ( {
test( 'shows empty cart when changing the view', async ( {
page,
editor,
editorUtils,
@ -188,24 +188,6 @@ test.describe( 'Merchant → Cart', () => {
' [data-type="woocommerce/empty-cart-block"]'
)
).toBeHidden();
await editor.selectBlocks(
await editorUtils.getBlockByName(
'woocommerce/cart-order-summary-shipping-block'
)
);
await editor.openDocumentSettingsSidebar();
const shippingLabel = editorUtils.page.getByLabel(
'Shipping calculator'
);
await shippingLabel.check();
await expect(
editor.canvas.getByText( 'Change address' )
).toBeVisible();
await shippingLabel.uncheck();
await expect(
editor.canvas.getByText( 'Change address' )
).toBeHidden();
} );
} );
} );