Skip to content

Commit

Permalink
take into account post type support on labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 13, 2024
1 parent 4bbb078 commit 0fae69b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 19 additions & 3 deletions packages/editor/src/components/post-discussion/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { useSelect } from '@wordpress/data';
import { useState, useMemo } from '@wordpress/element';
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -51,18 +52,33 @@ function ModalContents( { onClose } ) {
}

function PostDiscussionToggle( { isOpen, onClick } ) {
const { commentStatus, pingStatus } = useSelect( ( select ) => {
const {
commentStatus,
pingStatus,
commentsSupported,
trackbacksSupported,
} = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
const { getPostType } = select( coreStore );
const postType = getPostType( getEditedPostAttribute( 'type' ) );
return {
commentStatus: getEditedPostAttribute( 'comment_status' ) ?? 'open',
pingStatus: getEditedPostAttribute( 'ping_status' ) ?? 'open',
commentsSupported: !! postType.supports.comments,
trackbacksSupported: !! postType.supports.trackbacks,
};
}, [] );
let label;
if ( commentStatus === 'open' ) {
label = pingStatus === 'open' ? __( 'Open' ) : __( 'Comments only' );
if ( pingStatus === 'open' ) {
label = __( 'Open' );
} else {
label = trackbacksSupported ? __( 'Comments only' ) : __( 'Open' );
}
} else if ( pingStatus === 'open' ) {
label = commentsSupported ? __( 'Pings only' ) : __( 'Pings enabled' );
} else {
label = pingStatus === 'open' ? __( 'Pings only' ) : __( 'Closed' );
label = __( 'Closed' );
}
return (
<Button
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
import PluginSidebar from '../plugin-sidebar';
import PostActions from '../post-actions';
import PostCardPanel from '../post-card-panel';
import PostDiscussionPanel from '../post-discussion/panel';
import PostLastRevisionPanel from '../post-last-revision/panel';
import PostSummary from './post-summary';
import PostTaxonomiesPanel from '../post-taxonomies/panel';
Expand Down

0 comments on commit 0fae69b

Please sign in to comment.