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

Moves "Patterns" command to site editor main navigation #61416

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 1 addition & 42 deletions packages/core-commands/src/admin-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,9 @@
*/
import { useCommand } from '@wordpress/commands';
import { __ } from '@wordpress/i18n';
import { plus, symbol } from '@wordpress/icons';
import { addQueryArgs, getPath } from '@wordpress/url';
import { privateApis as routerPrivateApis } from '@wordpress/router';

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

const { useHistory } = unlock( routerPrivateApis );
import { plus } from '@wordpress/icons';

export function useAdminNavigationCommands() {
const history = useHistory();
const isTemplatesAccessible = useIsTemplatesAccessible();

const isSiteEditor = getPath( window.location.href )?.includes(
'site-editor.php'
);

useCommand( {
name: 'core/add-new-post',
label: __( 'Add new post' ),
Expand All @@ -39,28 +22,4 @@ export function useAdminNavigationCommands() {
document.location.href = 'post-new.php?post_type=page';
},
} );
useCommand( {
name: 'core/manage-reusable-blocks',
label: __( 'Patterns' ),
icon: symbol,
callback: ( { close } ) => {
// The site editor and templates both check whether the user
// can read templates. We can leverage that here and this
// command links to the classic dashboard manage patterns page
// if the user can't access it.
if ( isTemplatesAccessible ) {
const args = {
path: '/patterns',
};
if ( isSiteEditor ) {
history.push( args );
} else {
document.location = addQueryArgs( 'site-editor.php', args );
}
close();
} else {
document.location.href = 'edit.php?post_type=wp_block';
}
},
} );
}
19 changes: 19 additions & 0 deletions packages/core-commands/src/site-editor-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
post,
page,
layout,
symbol,
symbolFilled,
styles,
navigation,
Expand Down Expand Up @@ -338,6 +339,24 @@ function useSiteEditorBasicNavigationCommands() {
},
} );

result.push( {
name: 'core/manage-reusable-blocks',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: 'core/manage-reusable-blocks',
name: 'core/edit-site/open-patterns',

There are no hard and fast rules regarding this property, but it is a good idea to make it consistent with other commands.

label: __( 'Patterns' ),
icon: symbol,
callback: ( { close } ) => {
const args = {
path: '/patterns',
};
const targetUrl = addQueryArgs( 'site-editor.php', args );
if ( isSiteEditor ) {
history.push( args );
} else {
document.location = targetUrl;
}
close();
},
} );

return result;
}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );

Expand Down
Loading