From af0a577c0fe07f5b7f346cf194a0d500fd9a2564 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 12 Jan 2021 10:38:22 +0100 Subject: [PATCH 1/2] Fix floating date status inferred for posts where the status has been edited --- .../src/components/post-schedule/label.js | 1 - packages/editor/src/store/selectors.js | 7 ++++++- packages/editor/src/store/test/selectors.js | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/post-schedule/label.js b/packages/editor/src/components/post-schedule/label.js index 5f4c2cf7c5c777..45d1e59e7b8e53 100644 --- a/packages/editor/src/components/post-schedule/label.js +++ b/packages/editor/src/components/post-schedule/label.js @@ -7,7 +7,6 @@ import { withSelect } from '@wordpress/data'; export function PostScheduleLabel( { date, isFloating } ) { const settings = __experimentalGetSettings(); - return date && ! isFloating ? format( `${ settings.formats.date } ${ settings.formats.time }`, diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 40136136cbf5aa..b578f5274c8f0a 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -757,7 +757,12 @@ export function isEditedPostBeingScheduled( state ) { export function isEditedPostDateFloating( state ) { const date = getEditedPostAttribute( state, 'date' ); const modified = getEditedPostAttribute( state, 'modified' ); - const status = getEditedPostAttribute( state, 'status' ); + + // This should be the status of the persitedd post + // It shouldn't use the "edited" status otherwise it breaks the + // infered post data floating status + // See https://github.com/WordPress/gutenberg/issues/28083 + const status = getCurrentPost( state ).status; if ( status === 'draft' || status === 'auto-draft' || diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index 8c0397bc5d4581..b1f37856d861fb 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -2010,6 +2010,26 @@ describe( 'selectors', () => { expect( isEditedPostDateFloating( state ) ).toBe( true ); } ); + + it( 'should return false for private posts even if the edited status is "draft"', () => { + const state = { + currentPost: { + date: '2018-09-27T01:23:45.678Z', + modified: '2018-09-27T01:23:45.678Z', + status: 'private', + }, + editor: { + present: { + edits: { + status: 'draft', + }, + }, + }, + initialEdits: {}, + }; + + expect( isEditedPostDateFloating( state ) ).toBe( false ); + } ); } ); describe( 'isSavingPost', () => { From 11948856029154b6715459f54b56fbe872ea93c6 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 13 Jan 2021 14:12:23 +0100 Subject: [PATCH 2/2] Fix typo Co-authored-by: Bernie Reiter --- packages/editor/src/store/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index b578f5274c8f0a..b3bf751286809f 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -758,7 +758,7 @@ export function isEditedPostDateFloating( state ) { const date = getEditedPostAttribute( state, 'date' ); const modified = getEditedPostAttribute( state, 'modified' ); - // This should be the status of the persitedd post + // This should be the status of the persisted post // It shouldn't use the "edited" status otherwise it breaks the // infered post data floating status // See https://github.com/WordPress/gutenberg/issues/28083