From a4332833a8e6f3612ac5ce66fa09cf78a4269f40 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 19 Oct 2022 12:56:28 +0200 Subject: [PATCH] Remove forceIsSaving and forcePreviewLink props: isSavingPost returns complete info --- .../src/components/preview-options/README.md | 1 - .../src/components/device-preview/index.js | 35 +++++++-------- .../edit-post/src/components/header/index.js | 34 +++++--------- .../header/post-publish-button-or-toggle.js | 2 - .../src/components/layout/actions-panel.js | 12 +++-- .../components/post-preview-button/index.js | 44 +++++++------------ .../components/post-publish-button/index.js | 9 +--- .../components/post-publish-button/label.js | 4 +- .../post-publish-button/test/index.js | 10 ----- .../components/post-publish-panel/index.js | 4 +- .../src/components/post-saved-state/index.js | 7 +-- packages/editor/src/store/actions.js | 4 +- 12 files changed, 58 insertions(+), 108 deletions(-) diff --git a/packages/block-editor/src/components/preview-options/README.md b/packages/block-editor/src/components/preview-options/README.md index cdb0a4775e3b0..6e9a029fa83a5 100644 --- a/packages/block-editor/src/components/preview-options/README.md +++ b/packages/block-editor/src/components/preview-options/README.md @@ -35,7 +35,6 @@ const MyPreviewOptions = () => ( className="edit-post-header-preview__button-external" role="menuitem" forceIsAutosaveable={ hasActiveMetaboxes } - forcePreviewLink={ isSaving ? null : undefined } textContent={ <> { __( 'Preview in new tab' ) } diff --git a/packages/edit-post/src/components/device-preview/index.js b/packages/edit-post/src/components/device-preview/index.js index 26af74cbd10c1..3a47484bc0957 100644 --- a/packages/edit-post/src/components/device-preview/index.js +++ b/packages/edit-post/src/components/device-preview/index.js @@ -15,26 +15,22 @@ import { store as coreStore } from '@wordpress/core-data'; import { store as editPostStore } from '../../store'; export default function DevicePreview() { - const { - hasActiveMetaboxes, - isPostSaveable, - isSaving, - isViewable, - deviceType, - } = useSelect( ( select ) => { - const { getEditedPostAttribute } = select( editorStore ); - const { getPostType } = select( coreStore ); - const postType = getPostType( getEditedPostAttribute( 'type' ) ); + const { hasActiveMetaboxes, isPostSaveable, isViewable, deviceType } = + useSelect( ( select ) => { + const { getEditedPostAttribute } = select( editorStore ); + const { getPostType } = select( coreStore ); + const postType = getPostType( getEditedPostAttribute( 'type' ) ); - return { - hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), - isSaving: select( editPostStore ).isSavingMetaBoxes(), - isPostSaveable: select( editorStore ).isEditedPostSaveable(), - isViewable: postType?.viewable ?? false, - deviceType: - select( editPostStore ).__experimentalGetPreviewDeviceType(), - }; - }, [] ); + return { + hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), + isPostSaveable: select( editorStore ).isEditedPostSaveable(), + isViewable: postType?.viewable ?? false, + deviceType: + select( + editPostStore + ).__experimentalGetPreviewDeviceType(), + }; + }, [] ); const { __experimentalSetPreviewDeviceType: setPreviewDeviceType } = useDispatch( editPostStore ); @@ -55,7 +51,6 @@ export default function DevicePreview() { className="edit-post-header-preview__button-external" role="menuitem" forceIsAutosaveable={ hasActiveMetaboxes } - forcePreviewLink={ isSaving ? null : undefined } textContent={ <> { __( 'Preview in new tab' ) } diff --git a/packages/edit-post/src/components/header/index.js b/packages/edit-post/src/components/header/index.js index 6a7e72f4b1fd2..aeff1781cc967 100644 --- a/packages/edit-post/src/components/header/index.js +++ b/packages/edit-post/src/components/header/index.js @@ -25,22 +25,17 @@ import { store as editPostStore } from '../../store'; import TemplateTitle from './template-title'; function Header( { setEntitiesSavedStatesCallback, isDistractionFree } ) { - const { - hasActiveMetaboxes, - isPublishSidebarOpened, - isSaving, - showIconLabels, - } = useSelect( - ( select ) => ( { - hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), - isPublishSidebarOpened: - select( editPostStore ).isPublishSidebarOpened(), - isSaving: select( editPostStore ).isSavingMetaBoxes(), - showIconLabels: - select( editPostStore ).isFeatureActive( 'showIconLabels' ), - } ), - [] - ); + const { hasActiveMetaboxes, isPublishSidebarOpened, showIconLabels } = + useSelect( + ( select ) => ( { + hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), + isPublishSidebarOpened: + select( editPostStore ).isPublishSidebarOpened(), + showIconLabels: + select( editPostStore ).isFeatureActive( 'showIconLabels' ), + } ), + [] + ); const isLargeViewport = useViewportMatch( 'large' ); @@ -87,18 +82,13 @@ function Header( { setEntitiesSavedStatesCallback, isDistractionFree } ) { // when the publish sidebar has been closed. ) } - + { - return { + } = useSelect( + ( select ) => ( { publishSidebarOpened: select( editPostStore ).isPublishSidebarOpened(), hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), - isSavingMetaBoxes: select( editPostStore ).isSavingMetaBoxes(), hasNonPostEntityChanges: select( editorStore ).hasNonPostEntityChanges(), - }; - }, [] ); + } ), + [] + ); const openEntitiesSavedStates = useCallback( () => setEntitiesSavedStatesCallback( true ), @@ -57,7 +56,6 @@ export default function ActionsPanel( { diff --git a/packages/editor/src/components/post-preview-button/index.js b/packages/editor/src/components/post-preview-button/index.js index 136e7fb840d17..109f28a0d5a7d 100644 --- a/packages/editor/src/components/post-preview-button/index.js +++ b/packages/editor/src/components/post-preview-button/index.js @@ -103,33 +103,26 @@ function PostPreviewButton( { className, textContent, forceIsAutosaveable, - forcePreviewLink, role, onPreview, } ) { const { postId, currentPostLink, previewLink, isSaveable, isViewable } = - useSelect( - ( select ) => { - const editor = select( editorStore ); - const core = select( coreStore ); - - const postType = core.getPostType( - editor.getEditedPostAttribute( 'type' ) - ); - - return { - postId: editor.getCurrentPostId(), - currentPostLink: editor.getCurrentPostAttribute( 'link' ), - previewLink: - forcePreviewLink !== undefined - ? forcePreviewLink - : editor.getEditedPostPreviewLink(), - isSaveable: editor.isEditedPostSaveable(), - isViewable: postType?.viewable ?? false, - }; - }, - [ forcePreviewLink ] - ); + useSelect( ( select ) => { + const editor = select( editorStore ); + const core = select( coreStore ); + + const postType = core.getPostType( + editor.getEditedPostAttribute( 'type' ) + ); + + return { + postId: editor.getCurrentPostId(), + currentPostLink: editor.getCurrentPostAttribute( 'link' ), + previewLink: editor.getEditedPostPreviewLink(), + isSaveable: editor.isEditedPostSaveable(), + isViewable: postType?.viewable ?? false, + }; + }, [] ); const { __unstableSaveForPreview } = useDispatch( editorStore ); @@ -157,10 +150,7 @@ function PostPreviewButton( { writeInterstitialMessage( previewWindow.document ); - const link = await __unstableSaveForPreview( { - forcePreviewLink, - forceIsAutosaveable, - } ); + const link = await __unstableSaveForPreview( { forceIsAutosaveable } ); previewWindow.location = link; diff --git a/packages/editor/src/components/post-publish-button/index.js b/packages/editor/src/components/post-publish-button/index.js index d7f0ab33bdff9..8cca62ea00403 100644 --- a/packages/editor/src/components/post-publish-button/index.js +++ b/packages/editor/src/components/post-publish-button/index.js @@ -94,7 +94,6 @@ export class PostPublishButton extends Component { render() { const { forceIsDirty, - forceIsSaving, hasPublishAction, isBeingScheduled, isOpen, @@ -116,7 +115,6 @@ export class PostPublishButton extends Component { const isButtonDisabled = ( isSaving || - forceIsSaving || ! isSaveable || isPostSavingLocked || ( ! isPublishable && ! forceIsDirty ) ) && @@ -125,7 +123,6 @@ export class PostPublishButton extends Component { const isToggleDisabled = ( isPublished || isSaving || - forceIsSaving || ! isSaveable || ( ! isPublishable && ! forceIsDirty ) ) && ( ! hasNonPostEntityChanges || isSavingNonPostEntityChanges ); @@ -179,7 +176,6 @@ export class PostPublishButton extends Component { : __( 'Publish' ); const buttonChildren = ( ); @@ -223,10 +219,9 @@ export default compose( [ hasNonPostEntityChanges, isSavingNonPostEntityChanges, } = select( editorStore ); - const _isAutoSaving = isAutosavingPost(); return { - isSaving: isSavingPost() || _isAutoSaving, - isAutoSaving: _isAutoSaving, + isSaving: isSavingPost(), + isAutoSaving: isAutosavingPost(), isBeingScheduled: isEditedPostBeingScheduled(), visibility: getEditedPostVisibility(), isSaveable: isEditedPostSaveable(), diff --git a/packages/editor/src/components/post-publish-button/label.js b/packages/editor/src/components/post-publish-button/label.js index db26da73037bb..b491b3870e30b 100644 --- a/packages/editor/src/components/post-publish-button/label.js +++ b/packages/editor/src/components/post-publish-button/label.js @@ -49,7 +49,7 @@ export function PublishButtonLabel( { } export default compose( [ - withSelect( ( select, { forceIsSaving } ) => { + withSelect( ( select ) => { const { isCurrentPostPublished, isEditedPostBeingScheduled, @@ -62,7 +62,7 @@ export default compose( [ return { isPublished: isCurrentPostPublished(), isBeingScheduled: isEditedPostBeingScheduled(), - isSaving: forceIsSaving || isSavingPost(), + isSaving: isSavingPost(), isPublishing: isPublishingPost(), hasPublishAction: get( getCurrentPost(), diff --git a/packages/editor/src/components/post-publish-button/test/index.js b/packages/editor/src/components/post-publish-button/test/index.js index 299b6b0568699..8ca28ea2a8171 100644 --- a/packages/editor/src/components/post-publish-button/test/index.js +++ b/packages/editor/src/components/post-publish-button/test/index.js @@ -19,16 +19,6 @@ describe( 'PostPublishButton', () => { ).toHaveAttribute( 'aria-disabled', 'true' ); } ); - it( 'should be true if forceIsSaving is true', () => { - render( - - ); - - expect( - screen.getByRole( 'button', { name: 'Submit for Review' } ) - ).toHaveAttribute( 'aria-disabled', 'true' ); - } ); - it( 'should be true if post is not publishable and not forceIsDirty', () => { render(
diff --git a/packages/editor/src/components/post-saved-state/index.js b/packages/editor/src/components/post-saved-state/index.js index 1dc3f348e1e04..8ebc792d1e84c 100644 --- a/packages/editor/src/components/post-saved-state/index.js +++ b/packages/editor/src/components/post-saved-state/index.js @@ -30,14 +30,11 @@ import { store as editorStore } from '../../store'; * @param {Object} props Component props. * @param {?boolean} props.forceIsDirty Whether to force the post to be marked * as dirty. - * @param {?boolean} props.forceIsSaving Whether to force the post to be marked - * as being saved. * @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons * @return {import('@wordpress/element').WPComponent} The component. */ export default function PostSavedState( { forceIsDirty, - forceIsSaving, showIconLabels = false, } ) { const [ forceSavedMessage, setForceSavedMessage ] = useState( false ); @@ -73,14 +70,14 @@ export default function PostSavedState( { isNew: isEditedPostNew(), isPending: 'pending' === getEditedPostAttribute( 'status' ), isPublished: isCurrentPostPublished(), - isSaving: forceIsSaving || isSavingPost(), + isSaving: isSavingPost(), isSaveable: isEditedPostSaveable(), isScheduled: isCurrentPostScheduled(), hasPublishAction: getCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false, }; }, - [ forceIsDirty, forceIsSaving ] + [ forceIsDirty ] ); const { savePost } = useDispatch( editorStore ); diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index 24ab728b1668a..b040229d46cff 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -302,7 +302,7 @@ export const autosave = }; export const __unstableSaveForPreview = - ( { forceIsAutosaveable, forcePreviewLink } ) => + ( { forceIsAutosaveable } ) => async ( { select, dispatch } ) => { if ( ( forceIsAutosaveable || select.isEditedPostAutosaveable() ) && @@ -318,7 +318,7 @@ export const __unstableSaveForPreview = } } - return forcePreviewLink ?? select.getEditedPostPreviewLink(); + return select.getEditedPostPreviewLink(); }; /**