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 14, 2024
1 parent caa11dc commit fe0aaa5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 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 @@ -26,7 +26,6 @@ import PageAttributesPanel from '../page-attributes/panel';
import PatternOverridesPanel from '../pattern-overrides-panel';
import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
import PluginSidebar from '../plugin-sidebar';
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
2 changes: 1 addition & 1 deletion packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function PostSummary( { onActionPerformed } ) {
<PostSchedulePanel />
<PostTemplatePanel />
<PostURLPanel />
<PostDiscussionPanel />
<PostDiscussionPanel />
<PostSyncStatus />
</VStack>
<PostStickyPanel />
Expand Down

0 comments on commit fe0aaa5

Please sign in to comment.