Skip to content

Commit

Permalink
Changes after rebase and resolving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
benazeer-ben committed Dec 18, 2024
1 parent bef5db3 commit abebc4f
Showing 1 changed file with 48 additions and 52 deletions.
100 changes: 48 additions & 52 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,6 @@ const getEditorCommandLoader = () =>
},
} );

function useEditedEntityContextualCommands() {
const { postType, isViewable, status, link } = useSelect( ( select ) => {
const {
getCurrentPostType,
getEditedPostAttribute,
getEditedPostPreviewLink,
} = select( editorStore );
const { getPostType } = select( coreStore );
const isPublished = getEditedPostAttribute( 'status' ) === 'publish';
const _postType = getCurrentPostType();
return {
postType: _postType,
isViewable: getPostType( _postType )?.viewable ?? false,
status: getEditedPostAttribute( 'status' ),
link: isPublished
? getEditedPostAttribute( 'link' )
: getEditedPostPreviewLink?.() ?? '',
};
}, [] );
const { openModal } = useDispatch( interfaceStore );
const commands = [];
commands.push( {
name: 'core/open-settings-sidebar',
label: __( 'Show or hide the Settings panel.' ),
Expand Down Expand Up @@ -292,31 +271,6 @@ function useEditedEntityContextualCommands() {
);
},
} );
}
if ( isViewable ) {
if ( postType === 'post' || postType === 'page' ) {
const isPage = postType === 'page';
let label;

if ( status === 'publish' ) {
label = isPage ? __( 'View page' ) : __( 'View post' );
} else {
label = isPage ? __( 'Preview page' ) : __( 'Preview post' );
}

commands.push( {
name: 'core/view-link',
label,
icon: external,
callback: ( { close } ) => {
close();
if ( link ) {
window.open( link, '_blank' );
}
},
} );
}
}

if ( isViewable ) {
commands.push( {
Expand Down Expand Up @@ -355,12 +309,28 @@ function useEditedEntityContextualCommands() {

const getEditedEntityContextualCommands = () =>
function useEditedEntityContextualCommands() {
const { postType } = useSelect( ( select ) => {
const { getCurrentPostType } = select( editorStore );
return {
postType: getCurrentPostType(),
};
}, [] );
const { postType, isViewable, status, link } = useSelect(
( select ) => {
const {
getCurrentPostType,
getEditedPostAttribute,
getEditedPostPreviewLink,
} = select( editorStore );
const { getPostType } = select( coreStore );
const isPublished =
getEditedPostAttribute( 'status' ) === 'publish';
const _postType = getCurrentPostType();
return {
postType: _postType,
isViewable: getPostType( _postType )?.viewable ?? false,
status: getEditedPostAttribute( 'status' ),
link: isPublished
? getEditedPostAttribute( 'link' )
: getEditedPostPreviewLink?.() ?? '',
};
},
[]
);
const { openModal } = useDispatch( interfaceStore );
const commands = [];

Expand All @@ -384,6 +354,32 @@ const getEditedEntityContextualCommands = () =>
},
} );
}
if ( isViewable ) {
if ( postType === 'post' || postType === 'page' ) {
const isPage = postType === 'page';
let label;

if ( status === 'publish' ) {
label = isPage ? __( 'View page' ) : __( 'View post' );
} else {
label = isPage
? __( 'Preview page' )
: __( 'Preview post' );
}

commands.push( {
name: 'core/view-link',
label,
icon: external,
callback: ( { close } ) => {
close();
if ( link ) {
window.open( link, '_blank' );
}
},
} );
}
}

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

0 comments on commit abebc4f

Please sign in to comment.