Product Block Editor: load and create shipping classes optimistically (#47848)
* define ans use shippingClassRequestQuery * do not invalidate getProductShippingClasses * changelog
This commit is contained in:
parent
8cdd549038
commit
6f8bce8bb0
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
|
||||
Product Block Editor: load and create shipping classes optimistically
|
|
@ -51,6 +51,11 @@ function mapShippingClassToSelectOption(
|
|||
} ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Query to fetch shipping classes.
|
||||
*/
|
||||
const shippingClassRequestQuery = {};
|
||||
|
||||
function extractDefaultShippingClassFromProduct(
|
||||
categories?: PartialProduct[ 'categories' ],
|
||||
shippingClasses?: ProductShippingClass[]
|
||||
|
@ -78,7 +83,7 @@ export function Edit( {
|
|||
|
||||
const blockProps = useWooBlockProps( attributes );
|
||||
|
||||
const { createProductShippingClass, invalidateResolution } = useDispatch(
|
||||
const { createProductShippingClass } = useDispatch(
|
||||
EXPERIMENTAL_PRODUCT_SHIPPING_CLASSES_STORE_NAME
|
||||
);
|
||||
|
||||
|
@ -130,9 +135,9 @@ export function Edit( {
|
|||
return {
|
||||
shippingClasses:
|
||||
( isInSelectedTab &&
|
||||
getProductShippingClasses<
|
||||
ProductShippingClass[]
|
||||
>() ) ||
|
||||
getProductShippingClasses< ProductShippingClass[] >(
|
||||
shippingClassRequestQuery
|
||||
) ) ||
|
||||
[],
|
||||
};
|
||||
},
|
||||
|
@ -214,14 +219,13 @@ export function Edit( {
|
|||
onAdd={ ( shippingClassValues ) =>
|
||||
createProductShippingClass<
|
||||
Promise< ProductShippingClass >
|
||||
>( shippingClassValues )
|
||||
>( shippingClassValues, {
|
||||
optimisticQueryUpdate: shippingClassRequestQuery,
|
||||
} )
|
||||
.then( ( value ) => {
|
||||
recordEvent(
|
||||
'product_new_shipping_class_modal_add_button_click'
|
||||
);
|
||||
invalidateResolution(
|
||||
'getProductShippingClasses'
|
||||
);
|
||||
setShippingClass( value.slug );
|
||||
return value;
|
||||
} )
|
||||
|
|
Loading…
Reference in New Issue