Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: update the Manage all my patterns command to redirect to site editor patterns list #52817

Merged
merged 8 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core-commands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.16.0",
"@wordpress/block-editor": "file:../block-editor",
"@wordpress/commands": "file:../commands",
"@wordpress/core-data": "file:../core-data",
"@wordpress/data": "file:../data",
Expand Down
44 changes: 40 additions & 4 deletions packages/core-commands/src/admin-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
*/
import { useCommand } from '@wordpress/commands';
import { __ } from '@wordpress/i18n';
import { external, plus } from '@wordpress/icons';
import { external, plus, symbol } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { addQueryArgs, getPath } from '@wordpress/url';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
*/
import { unlock } from './lock-unlock';

const { useHistory } = unlock( routerPrivateApis );

export function useAdminNavigationCommands() {
const history = useHistory();
const getSettings = useSelect(
( select ) => select( blockEditorStore ).getSettings
);
const settings = getSettings();
const isBlockTheme = settings.__unstableIsBlockBasedTheme;
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
const isSiteEditor = getPath( window.location.href )?.includes(
'site-editor.php'
);

useCommand( {
name: 'core/add-new-post',
label: __( 'Add new post' ),
Expand All @@ -25,9 +46,24 @@ export function useAdminNavigationCommands() {
useCommand( {
name: 'core/manage-reusable-blocks',
label: __( 'Manage all of my patterns' ),
callback: () => {
document.location.href = 'edit.php?post_type=wp_block';
callback: ( { close } ) => {
// __unstableIsBlockBasedTheme is not defined in the site editor so we need to check the context.
// If not the site editor and not a block based theme then redirect to the old wp-admin patterns page.
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
if ( ! isSiteEditor && ! isBlockTheme ) {
document.location.href = 'edit.php?post_type=wp_block';
} else {
const args = {
path: '/patterns',
};
const targetUrl = addQueryArgs( 'site-editor.php', args );
if ( isSiteEditor ) {
history.push( args );
} else {
document.location = targetUrl;
}
close();
}
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
},
icon: external,
icon: isSiteEditor ? symbol : external,
} );
}