Skip to content
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
25 changes: 15 additions & 10 deletions packages/block-library/src/post-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@ import { __, _x, sprintf } from '@wordpress/i18n';
import { pencil } from '@wordpress/icons';
import { DOWN } from '@wordpress/keycodes';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

export default function PostDateEdit( {
attributes: { datetime, textAlign, format, isLink, metadata },
attributes,
context: { postType: postTypeSlug, queryId },
setAttributes,
name,
} ) {
const displayType =
metadata?.bindings?.datetime?.source === 'core/post-data' &&
metadata?.bindings?.datetime?.args?.field;

const { datetime, textAlign, format, isLink } = attributes;
const blockProps = useBlockProps( {
className: clsx( {
[ `has-text-align-${ textAlign }` ]: textAlign,
Expand Down Expand Up @@ -90,7 +89,6 @@ export default function PostDateEdit( {
( select ) => {
const { getPostType, getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );

return {
siteFormat: siteSettings?.date_format,
siteTimeFormat: siteSettings?.time_format,
Expand All @@ -99,6 +97,12 @@ export default function PostDateEdit( {
},
[ postTypeSlug ]
);
const activeBlockVariationName = useSelect(
( select ) =>
select( blocksStore ).getActiveBlockVariation( name, attributes )
?.name,
[ name, attributes ]
);

const blockEditingMode = useBlockEditingMode();

Expand All @@ -120,7 +124,6 @@ export default function PostDateEdit( {
</a>
);
}

return (
<>
{ ( blockEditingMode === 'default' ||
Expand All @@ -133,15 +136,17 @@ export default function PostDateEdit( {
} }
/>

{ displayType !== 'modified' &&
! isDescendentOfQueryLoop && (
{ activeBlockVariationName !== 'post-date-modified' &&
( ! isDescendentOfQueryLoop ||
! activeBlockVariationName ) && (
<ToolbarGroup>
<Dropdown
popoverProps={ popoverProps }
renderContent={ ( { onClose } ) => (
<PublishDateTimePicker
title={
displayType === 'date'
activeBlockVariationName ===
'post-date'
? __( 'Publish Date' )
: __( 'Date' )
}
Expand Down
7 changes: 2 additions & 5 deletions packages/block-library/src/post-date/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { postDate } from '@wordpress/icons';

const variations = [
{
Expand All @@ -19,13 +18,12 @@ const variations = [
},
},
},
scope: [ 'block', 'inserter', 'transform' ],
scope: [ 'inserter', 'transform' ],
isActive: ( blockAttributes ) =>
blockAttributes?.metadata?.bindings?.datetime?.source ===
'core/post-data' &&
blockAttributes?.metadata?.bindings?.datetime?.args?.field ===
'date',
icon: postDate,
},
{
name: 'post-date-modified',
Expand All @@ -42,13 +40,12 @@ const variations = [
},
className: 'wp-block-post-date__modified-date',
},
scope: [ 'block', 'inserter', 'transform' ],
scope: [ 'inserter', 'transform' ],
isActive: ( blockAttributes ) =>
blockAttributes?.metadata?.bindings?.datetime?.source ===
'core/post-data' &&
blockAttributes?.metadata?.bindings?.datetime?.args?.field ===
'modified',
icon: postDate,
},
];

Expand Down
Loading