-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
130 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { createInterpolateElement } from '@wordpress/element'; | ||
import { dateI18n, getDate, getSettings } from '@wordpress/date'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
|
||
const getFormattedDate = ( dateToDisplay: string | null ) => | ||
dateI18n( | ||
getSettings().formats.datetimeAbbreviated, | ||
getDate( dateToDisplay ), | ||
undefined | ||
); | ||
|
||
const DateView = ( { item }: { item: BasePost } ) => { | ||
const isDraftOrPrivate = [ 'draft', 'private' ].includes( | ||
item.status ?? '' | ||
); | ||
if ( isDraftOrPrivate ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: %s: page creation or modification date. */ | ||
__( '<span>Modified: <time>%s</time></span>' ), | ||
getFormattedDate( item.date ?? null ) | ||
), | ||
{ | ||
span: <span />, | ||
time: <time />, | ||
} | ||
); | ||
} | ||
|
||
const isScheduled = item.status === 'future'; | ||
if ( isScheduled ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: %s: page creation date */ | ||
__( '<span>Scheduled: <time>%s</time></span>' ), | ||
getFormattedDate( item.date ?? null ) | ||
), | ||
{ | ||
span: <span />, | ||
time: <time />, | ||
} | ||
); | ||
} | ||
|
||
const isPublished = item.status === 'publish'; | ||
if ( isPublished ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: %s: page creation time */ | ||
__( '<span>Published: <time>%s</time></span>' ), | ||
getFormattedDate( item.date ?? null ) | ||
), | ||
{ | ||
span: <span />, | ||
time: <time />, | ||
} | ||
); | ||
} | ||
|
||
// Pending posts show the modified date if it's newer. | ||
const dateToDisplay = | ||
getDate( item.modified ?? null ) > getDate( item.date ?? null ) | ||
? item.modified | ||
: item.date; | ||
|
||
const isPending = item.status === 'pending'; | ||
if ( isPending ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: %s: page creation or modification date. */ | ||
__( '<span>Modified: <time>%s</time></span>' ), | ||
getFormattedDate( dateToDisplay ?? null ) | ||
), | ||
{ | ||
span: <span />, | ||
time: <time />, | ||
} | ||
); | ||
} | ||
|
||
// Unknow status. | ||
return <time>{ getFormattedDate( item.date ?? null ) }</time>; | ||
}; | ||
|
||
export default DateView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import type { Field } from '@wordpress/dataviews'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
import DateView from './date-view'; | ||
|
||
const dateField: Field< BasePost > = { | ||
id: 'date', | ||
type: 'datetime', | ||
label: __( 'Date' ), | ||
render: DateView, | ||
}; | ||
|
||
/** | ||
* Date field for BasePost. | ||
*/ | ||
export default dateField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters