Skip to content
Merged
Changes from all 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
40 changes: 39 additions & 1 deletion packages/core-commands/src/admin-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { useCommand, useCommandLoader } from '@wordpress/commands';
import { __ } from '@wordpress/i18n';
import { plus } from '@wordpress/icons';
import { plus, dashboard } from '@wordpress/icons';
import { getPath } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect, useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -137,6 +137,39 @@ const getAdminBasicNavigationCommands = () =>
};
};

const getDashboardCommand = () =>
function useDashboardCommand() {
const currentPath = getPath( window.location.href );

const isEditorScreen =
currentPath?.includes( 'site-editor.php' ) ||
currentPath?.includes( 'post.php' ) ||
currentPath?.includes( 'post-new.php' ) ||
currentPath?.includes( 'widgets.php' ) ||
currentPath?.includes( 'customize.php' );

const commands = useMemo( () => {
if ( isEditorScreen ) {
return [
{
name: 'core/dashboard',
label: __( 'Dashboard' ),
icon: dashboard,
callback: () => {
document.location.assign( 'index.php' );
},
},
];
}
return [];
}, [ isEditorScreen ] );

return {
isLoading: false,
commands,
};
};

export function useAdminNavigationCommands() {
useCommand( {
name: 'core/add-new-post',
Expand All @@ -148,6 +181,11 @@ export function useAdminNavigationCommands() {
keywords: [ __( 'post' ), __( 'new' ), __( 'add' ), __( 'create' ) ],
} );

useCommandLoader( {
name: 'core/dashboard',
hook: getDashboardCommand(),
} );

useCommandLoader( {
name: 'core/add-new-page',
hook: getAddNewPageCommand(),
Expand Down
Loading