From ae424e15002332d4cff1bdb465b3bf0e28372fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:41:42 +0100 Subject: [PATCH 1/7] Extract date to fields package --- package-lock.json | 1 + .../src/components/post-fields/index.js | 88 +----------------- packages/fields/README.md | 4 + packages/fields/package.json | 1 + packages/fields/src/fields/date/date-view.tsx | 93 +++++++++++++++++++ packages/fields/src/fields/date/index.tsx | 23 +++++ packages/fields/src/fields/index.ts | 1 + packages/fields/src/types.ts | 4 +- 8 files changed, 129 insertions(+), 86 deletions(-) create mode 100644 packages/fields/src/fields/date/date-view.tsx create mode 100644 packages/fields/src/fields/date/index.tsx diff --git a/package-lock.json b/package-lock.json index 0bb48c55c5326c..3ccca4c5eef52b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54685,6 +54685,7 @@ "@wordpress/core-data": "*", "@wordpress/data": "*", "@wordpress/dataviews": "*", + "@wordpress/date": "5.11.0", "@wordpress/element": "*", "@wordpress/hooks": "*", "@wordpress/html-entities": "*", diff --git a/packages/edit-site/src/components/post-fields/index.js b/packages/edit-site/src/components/post-fields/index.js index 097459ea110039..e4e63839bf3d30 100644 --- a/packages/edit-site/src/components/post-fields/index.js +++ b/packages/edit-site/src/components/post-fields/index.js @@ -6,7 +6,7 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { __, sprintf } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; import { featuredImageField, slugField, @@ -15,23 +15,17 @@ import { statusField, commentStatusField, titleField, + dateField, } from '@wordpress/fields'; import { - createInterpolateElement, useMemo, useState, } from '@wordpress/element'; -import { dateI18n, getDate, getSettings } from '@wordpress/date'; import { commentAuthorAvatar as authorIcon } from '@wordpress/icons'; import { __experimentalHStack as HStack, Icon } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { useEntityRecords, store as coreStore } from '@wordpress/core-data'; -const getFormattedDate = ( dateToDisplay ) => - dateI18n( - getSettings().formats.datetimeAbbreviated, - getDate( dateToDisplay ) - ); function PostAuthorField( { item } ) { const { text, imageUrl } = useSelect( @@ -99,83 +93,7 @@ function usePostFields() { }, }, statusField, - { - label: __( 'Date' ), - id: 'date', - type: 'datetime', - render: ( { item } ) => { - const isDraftOrPrivate = [ 'draft', 'private' ].includes( - item.status - ); - if ( isDraftOrPrivate ) { - return createInterpolateElement( - sprintf( - /* translators: %s: page creation or modification date. */ - __( 'Modified: ' ), - getFormattedDate( item.date ) - ), - { - span: , - time: