Skip to content

Commit

Permalink
Adding command to site editor
Browse files Browse the repository at this point in the history
  • Loading branch information
karthick-murugan committed Nov 5, 2024
1 parent 39191c8 commit 66fafc7
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
drawerLeft,
drawerRight,
edit,
page,
formatListBullets,
listView,
external,
Expand Down Expand Up @@ -254,18 +255,6 @@ function useEditorCommandLoader() {
} );
}

commands.push( {
name: 'core/drafts',
label: __( 'Pages/Drafts' ),
keywords: [ 'drafts' ],
icon: edit,
callback: ( { close } ) => {
close();
window.location.href =
'/wp-admin/site-editor.php?postType=page&layout=list&activeView=drafts';
},
} );

return {
commands,
isLoading: false,
Expand Down Expand Up @@ -306,6 +295,26 @@ function useEditedEntityContextualCommands() {
return { isLoading: false, commands };
}

function useSiteEditorCommandLoader() {
const commands = [];
commands.push( {
name: 'core/drafts',
label: __( 'Pages/Drafts' ),
keywords: [ 'drafts' ],
icon: page,
callback: ( { close } ) => {
close();
window.location.href =
'/wp-admin/site-editor.php?postType=page&layout=list&activeView=drafts';
},
} );

return {
commands,
isLoading: false,
};
}

export default function useCommands() {
useCommandLoader( {
name: 'core/editor/edit-ui',
Expand All @@ -317,4 +326,10 @@ export default function useCommands() {
hook: useEditedEntityContextualCommands,
context: 'entity-edit',
} );

useCommandLoader( {
name: 'core/editor/site-editor',
hook: useSiteEditorCommandLoader,
context: 'site-editor',
} );
}

0 comments on commit 66fafc7

Please sign in to comment.