Fix product task redirect to support grouped and external products (#43051)

* Rearrange product redirection logic to better accept grouped and external produc types

* Add changelog
This commit is contained in:
louwie17 2023-12-21 14:09:00 -04:00 committed by GitHub
parent a67a1c6efc
commit 9182efaaf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 26 deletions

View File

@ -24,32 +24,19 @@ export const useCreateProductByType = () => {
const isNewExperienceEnabled = const isNewExperienceEnabled =
window.wcAdminFeatures[ 'new-product-management-experience' ]; window.wcAdminFeatures[ 'new-product-management-experience' ];
const createProductByType = async ( type: ProductTypeKey ) => { const getProductEditPageLink = async (
setIsRequesting( true ); type: ProductTypeKey,
classicEditor: boolean
) => {
if ( if (
type === 'physical' || type === 'physical' ||
type === 'variable' || type === 'variable' ||
type === 'digital' || type === 'digital'
type === 'grouped' ||
type === 'external'
) { ) {
if ( isNewExperienceEnabled ) { return classicEditor
navigateTo( { url: getNewPath( {}, '/add-product', {} ) } ); ? getAdminLink( 'post-new.php?post_type=product' )
return; : getNewPath( {}, '/add-product', {} );
}
const assignment = await loadExperimentAssignment(
EXPERIMENT_NAME
);
if ( assignment.variationName === 'treatment' ) {
const _feature_nonce = getAdminSetting( '_feature_nonce' );
window.location.href = getAdminLink(
`post-new.php?post_type=product&product_block_editor=1&_feature_nonce=${ _feature_nonce }`
);
return;
}
} }
try { try {
const data: { const data: {
id?: number; id?: number;
@ -61,16 +48,52 @@ export const useCreateProductByType = () => {
{ _fields: [ 'id' ] } { _fields: [ 'id' ] }
); );
if ( data && data.id ) { if ( data && data.id ) {
const link = getAdminLink( return classicEditor
`post.php?post=${ data.id }&action=edit&wc_onboarding_active_task=products&tutorial=true` ? getAdminLink(
); `post.php?post=${ data.id }&action=edit&wc_onboarding_active_task=products&tutorial=true`
window.location.href = link; )
return; : getNewPath( {}, '/product/' + data.id, {} );
} }
throw new Error( 'Unexpected empty data response from server' ); throw new Error( 'Unexpected empty data response from server' );
} catch ( error ) { } catch ( error ) {
createNoticesFromResponse( error ); createNoticesFromResponse( error );
} }
};
const createProductByType = async ( type: ProductTypeKey ) => {
setIsRequesting( true );
if (
type === 'physical' ||
type === 'variable' ||
type === 'digital' ||
type === 'grouped' ||
type === 'external'
) {
if ( isNewExperienceEnabled ) {
const url = await getProductEditPageLink( type, false );
if ( url ) {
navigateTo( { url } );
}
return;
}
const assignment = await loadExperimentAssignment(
EXPERIMENT_NAME
);
if ( assignment.variationName === 'treatment' ) {
const url = await getProductEditPageLink( type, true );
const _feature_nonce = getAdminSetting( '_feature_nonce' );
window.location.href =
url +
`&product_block_editor=1&_feature_nonce=${ _feature_nonce }`;
return;
}
}
const url = await getProductEditPageLink( type, true );
if ( url ) {
navigateTo( { url } );
}
setIsRequesting( false ); setIsRequesting( false );
}; };

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix product task redirection to allow use for external and grouped products with the new product editor.