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

DataViews: display published date for pages/posts with published status #64049

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
28 changes: 14 additions & 14 deletions packages/edit-site/src/components/post-fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,13 @@ function usePostFields( viewType ) {
);
}

// Pending & Published posts show the modified date if it's newer.
const dateToDisplay =
getDate( item.modified ) > getDate( item.date )
? item.modified
: item.date;

const isPending = item.status === 'pending';
if ( isPending ) {
const isPublished = item.status === 'publish';
if ( isPublished ) {
return createInterpolateElement(
sprintf(
/* translators: %s: the newest of created or modified date for the page */
__( '<span>Modified: <time>%s</time></span>' ),
getFormattedDate( dateToDisplay )
/* translators: %s: page creation time */
__( '<span>Published: <time>%s</time></span>' ),
getFormattedDate( item.date )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core change (dateToDisplay becomes item.date). The rest is due to moving isPublished logic before isPending.

),
{
span: <span />,
Expand All @@ -313,12 +307,18 @@ function usePostFields( viewType ) {
);
}

const isPublished = item.status === 'publish';
if ( isPublished ) {
// Pending posts show the modified date if it's newer.
const dateToDisplay =
getDate( item.modified ) > getDate( item.date )
? item.modified
: item.date;

const isPending = item.status === 'pending';
if ( isPending ) {
return createInterpolateElement(
sprintf(
/* translators: %s: the newest of created or modified date for the page */
__( '<span>Published: <time>%s</time></span>' ),
__( '<span>Modified: <time>%s</time></span>' ),
getFormattedDate( dateToDisplay )
),
{
Expand Down
Loading