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

Command tool: Add searchLabel property to commands #50663

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/commands/src/components/command-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function CommandMenuLoader( { name, search, hook, setLoader, close } ) {
{ commands.map( ( command ) => (
<Command.Item
key={ command.name }
value={ command.name }
value={ command.searchLabel ?? command.label }
onSelect={ () => command.callback( { close } ) }
>
<HStack
Expand Down Expand Up @@ -110,7 +110,7 @@ export function CommandMenuGroup( { isContextual, search, setLoader, close } ) {
{ commands.map( ( command ) => (
<Command.Item
key={ command.name }
value={ command.name }
value={ command.searchLabel ?? command.label }
onSelect={ () => command.callback( { close } ) }
>
<HStack
Expand Down
2 changes: 2 additions & 0 deletions packages/commands/src/hooks/use-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function useCommand( command ) {
name: command.name,
context: command.context,
label: command.label,
searchLabel: command.searchLabel,
icon: command.icon,
callback: currentCallback.current,
} );
Expand All @@ -35,6 +36,7 @@ export default function useCommand( command ) {
}, [
command.name,
command.label,
command.searchLabel,
command.icon,
command.context,
registerCommand,
Expand Down
11 changes: 6 additions & 5 deletions packages/commands/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*
* @typedef {Object} WPCommandConfig
*
* @property {string} name Command name.
* @property {string} label Command label.
* @property {string=} context Command context.
* @property {JSX.Element} icon Command icon.
* @property {Function} callback Command callback.
* @property {string} name Command name.
* @property {string} label Command label.
* @property {string=} searchLabel Command search label.
* @property {string=} context Command context.
* @property {JSX.Element} icon Command icon.
* @property {Function} callback Command callback.
*/

/**
Expand Down
1 change: 1 addition & 0 deletions packages/commands/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function commands( state = {}, action ) {
[ action.name ]: {
name: action.name,
label: action.label,
searchLabel: action.searchLabel,
context: action.context,
callback: action.callback,
icon: action.icon,
Expand Down
4 changes: 2 additions & 2 deletions packages/core-commands/src/add-post-type-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const { useCommand } = unlock( privateApis );

export function useAddPostTypeCommands() {
useCommand( {
name: 'add new post',
name: 'core/add-new-post',
label: __( 'Add new post' ),
icon: plus,
callback: () => {
document.location.href = 'post-new.php';
},
} );
useCommand( {
name: 'add new page',
name: 'core/add-new-page',
label: __( 'Add new page' ),
icon: plus,
callback: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
? { canvas: getQueryArg( window.location.href, 'canvas' ) }
: {};
return {
name: record.title?.rendered + ' ' + record.id,
name: postType + '-' + record.id,
searchLabel: record.title?.rendered + ' ' + record.id,
label: record.title?.rendered
? record.title?.rendered
: __( '(no title)' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function useEditModeCommandLoader() {
? __( 'Delete template' )
: __( 'Delete template part' );
commands.push( {
name: label,
name: 'core/remove-template',
label,
icon: trash,
context: 'site-editor-edit',
Expand All @@ -55,7 +55,7 @@ function useEditModeCommandLoader() {
? __( 'Reset template' )
: __( 'Reset template part' );
commands.push( {
name: label,
name: 'core/reset-template',
label,
icon: backup,
callback: ( { close } ) => {
Expand Down