Skip to content

Commit

Permalink
Patterns: Open detail view when duplicating pattern (#53214)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Aug 11, 2023
1 parent 84adb3c commit 77708cb
Showing 1 changed file with 18 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,22 @@ export default function DuplicateMenuItem( {
createSuccessNotice(
sprintf(
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
__( '"%s" created.' ),
title
__( '"%s" duplicated.' ),
item.title
),
{
type: 'snackbar',
id: 'edit-site-patterns-success',
actions: [
{
label: __( 'Edit' ),
onClick: () =>
history.push( {
postType: TEMPLATE_PARTS,
postId: result?.id,
categoryType: TEMPLATE_PARTS,
categoryId,
} ),
},
],
}
);

history.push( {
postType: TEMPLATE_PARTS,
postId: result?.id,
categoryType: TEMPLATE_PARTS,
categoryId,
} );

onClose();
} catch ( error ) {
const errorMessage =
Expand Down Expand Up @@ -139,41 +134,25 @@ export default function DuplicateMenuItem( {
{ throwOnError: true }
);

const actionLabel = isThemePattern
? __( 'View my patterns' )
: __( 'Edit' );

const newLocation = isThemePattern
? {
categoryType: USER_PATTERNS,
categoryId: USER_PATTERN_CATEGORY,
path: '/patterns',
}
: {
categoryType: USER_PATTERNS,
categoryId: USER_PATTERN_CATEGORY,
postType: USER_PATTERNS,
postId: result?.id,
};

createSuccessNotice(
sprintf(
// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.
__( '"%s" added to my patterns.' ),
title
__( '"%s" duplicated.' ),
item.title
),
{
type: 'snackbar',
id: 'edit-site-patterns-success',
actions: [
{
label: actionLabel,
onClick: () => history.push( newLocation ),
},
],
}
);

history.push( {
categoryType: USER_PATTERNS,
categoryId: USER_PATTERN_CATEGORY,
postType: USER_PATTERNS,
postId: result?.id,
} );

onClose();
} catch ( error ) {
const errorMessage =
Expand Down

0 comments on commit 77708cb

Please sign in to comment.