From 3ec1ced865757f6568c42c126acb3478b25fe2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:43:15 +0200 Subject: [PATCH] Add `status` to quick edit (#64398) Co-authored-by: oandregal Co-authored-by: youknowriad Co-authored-by: ntsekouras --- .../src/components/post-edit/index.js | 29 +++++++++++++- .../src/components/post-fields/index.js | 40 +++++++++++++++---- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/packages/edit-site/src/components/post-edit/index.js b/packages/edit-site/src/components/post-edit/index.js index 80304f16503705..0ec63589d97673 100644 --- a/packages/edit-site/src/components/post-edit/index.js +++ b/packages/edit-site/src/components/post-edit/index.js @@ -42,13 +42,38 @@ function PostEditForm( { postType, postId } ) { ); const [ multiEdits, setMultiEdits ] = useState( {} ); const { editEntityRecord } = useDispatch( coreDataStore ); - const { fields } = usePostFields(); + const { fields: _fields } = usePostFields(); + const fields = useMemo( + () => + _fields?.map( ( field ) => { + if ( field.id === 'status' ) { + return { + ...field, + elements: field.elements.filter( + ( element ) => element.value !== 'trash' + ), + }; + } + return field; + } ), + [ _fields ] + ); const form = { type: 'panel', - fields: [ 'title', 'author', 'date', 'comment_status' ], + fields: [ 'title', 'status', 'date', 'author', 'comment_status' ], }; const onChange = ( edits ) => { for ( const id of ids ) { + if ( + edits.status !== 'future' && + record.status === 'future' && + new Date( record.date ) > new Date() + ) { + edits.date = null; + } + if ( edits.status === 'private' && record.password ) { + edits.password = ''; + } editEntityRecord( 'postType', postType, id, edits ); if ( ids.length > 1 ) { setMultiEdits( ( prev ) => ( { diff --git a/packages/edit-site/src/components/post-fields/index.js b/packages/edit-site/src/components/post-fields/index.js index b03b2c6f5be3c4..9e59b23d61922d 100644 --- a/packages/edit-site/src/components/post-fields/index.js +++ b/packages/edit-site/src/components/post-fields/index.js @@ -42,11 +42,36 @@ import Media from '../media'; // See https://github.com/WordPress/gutenberg/issues/55886 // We do not support custom statutes at the moment. const STATUSES = [ - { value: 'draft', label: __( 'Draft' ), icon: drafts }, - { value: 'future', label: __( 'Scheduled' ), icon: scheduled }, - { value: 'pending', label: __( 'Pending Review' ), icon: pending }, - { value: 'private', label: __( 'Private' ), icon: notAllowed }, - { value: 'publish', label: __( 'Published' ), icon: published }, + { + value: 'draft', + label: __( 'Draft' ), + icon: drafts, + description: __( 'Not ready to publish.' ), + }, + { + value: 'future', + label: __( 'Scheduled' ), + icon: scheduled, + description: __( 'Publish automatically on a chosen date.' ), + }, + { + value: 'pending', + label: __( 'Pending Review' ), + icon: pending, + description: __( 'Waiting for review before publishing.' ), + }, + { + value: 'private', + label: __( 'Private' ), + icon: notAllowed, + description: __( 'Only visible to site admins and editors.' ), + }, + { + value: 'publish', + label: __( 'Published' ), + icon: published, + description: __( 'Visible to everyone.' ), + }, { value: 'trash', label: __( 'Trash' ), icon: trash }, ]; @@ -258,11 +283,10 @@ function usePostFields( viewType ) { { label: __( 'Status' ), id: 'status', - getValue: ( { item } ) => - STATUSES.find( ( { value } ) => value === item.status ) - ?.label ?? item.status, + type: 'text', elements: STATUSES, render: PostStatusField, + Edit: 'radio', enableSorting: false, filterBy: { operators: [ OPERATOR_IS_ANY ],