Skip to content

Commit

Permalink
Remove forceIsSaving and forcePreviewLink props: isSavingPost returns…
Browse files Browse the repository at this point in the history
… complete info
  • Loading branch information
jsnajdr committed Oct 19, 2022
1 parent 42c8ce6 commit 1b8dcb3
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) }
Expand Down
35 changes: 15 additions & 20 deletions packages/edit-post/src/components/device-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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' ) }
Expand Down
34 changes: 12 additions & 22 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down Expand Up @@ -87,18 +82,13 @@ function Header( { setEntitiesSavedStatesCallback, isDistractionFree } ) {
// when the publish sidebar has been closed.
<PostSavedState
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
showIconLabels={ showIconLabels }
/>
) }
<DevicePreview />
<PostPreviewButton
forceIsAutosaveable={ hasActiveMetaboxes }
forcePreviewLink={ isSaving ? null : undefined }
/>
<PostPreviewButton forceIsAutosaveable={ hasActiveMetaboxes } />
<PostPublishButtonOrToggle
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
setEntitiesSavedStatesCallback={
setEntitiesSavedStatesCallback
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { store as editPostStore } from '../../store';

export function PostPublishButtonOrToggle( {
forceIsDirty,
forceIsSaving,
hasPublishAction,
isBeingScheduled,
isPending,
Expand Down Expand Up @@ -72,7 +71,6 @@ export function PostPublishButtonOrToggle( {
return (
<PostPublishButton
forceIsDirty={ forceIsDirty }
forceIsSaving={ forceIsSaving }
isOpen={ isPublishSidebarOpened }
isToggle={ component === IS_TOGGLE }
onToggle={ togglePublishSidebar }
Expand Down
12 changes: 5 additions & 7 deletions packages/edit-post/src/components/layout/actions-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ export default function ActionsPanel( {
const {
publishSidebarOpened,
hasActiveMetaboxes,
isSavingMetaBoxes,
hasNonPostEntityChanges,
} = useSelect( ( select ) => {
return {
} = useSelect(
( select ) => ( {
publishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
isSavingMetaBoxes: select( editPostStore ).isSavingMetaBoxes(),
hasNonPostEntityChanges:
select( editorStore ).hasNonPostEntityChanges(),
};
}, [] );
} ),
[]
);

const openEntitiesSavedStates = useCallback(
() => setEntitiesSavedStatesCallback( true ),
Expand All @@ -57,7 +56,6 @@ export default function ActionsPanel( {
<PostPublishPanel
onClose={ closePublishSidebar }
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSavingMetaBoxes }
PrePublishExtension={ PluginPrePublishPanel.Slot }
PostPublishExtension={ PluginPostPublishPanel.Slot }
/>
Expand Down
44 changes: 17 additions & 27 deletions packages/editor/src/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -157,10 +150,7 @@ function PostPreviewButton( {

writeInterstitialMessage( previewWindow.document );

const link = await __unstableSaveForPreview( {
forcePreviewLink,
forceIsAutosaveable,
} );
const link = await __unstableSaveForPreview( { forceIsAutosaveable } );

previewWindow.location = link;

Expand Down
9 changes: 2 additions & 7 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export class PostPublishButton extends Component {
render() {
const {
forceIsDirty,
forceIsSaving,
hasPublishAction,
isBeingScheduled,
isOpen,
Expand All @@ -116,7 +115,6 @@ export class PostPublishButton extends Component {

const isButtonDisabled =
( isSaving ||
forceIsSaving ||
! isSaveable ||
isPostSavingLocked ||
( ! isPublishable && ! forceIsDirty ) ) &&
Expand All @@ -125,7 +123,6 @@ export class PostPublishButton extends Component {
const isToggleDisabled =
( isPublished ||
isSaving ||
forceIsSaving ||
! isSaveable ||
( ! isPublishable && ! forceIsDirty ) ) &&
( ! hasNonPostEntityChanges || isSavingNonPostEntityChanges );
Expand Down Expand Up @@ -179,7 +176,6 @@ export class PostPublishButton extends Component {
: __( 'Publish' );
const buttonChildren = (
<PublishButtonLabel
forceIsSaving={ forceIsSaving }
hasNonPostEntityChanges={ hasNonPostEntityChanges }
/>
);
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/post-publish-button/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function PublishButtonLabel( {
}

export default compose( [
withSelect( ( select, { forceIsSaving } ) => {
withSelect( ( select ) => {
const {
isCurrentPostPublished,
isEditedPostBeingScheduled,
Expand All @@ -62,7 +62,7 @@ export default compose( [
return {
isPublished: isCurrentPostPublished(),
isBeingScheduled: isEditedPostBeingScheduled(),
isSaving: forceIsSaving || isSavingPost(),
isSaving: isSavingPost(),
isPublishing: isPublishingPost(),
hasPublishAction: get(
getCurrentPost(),
Expand Down
10 changes: 0 additions & 10 deletions packages/editor/src/components/post-publish-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ describe( 'PostPublishButton', () => {
).toHaveAttribute( 'aria-disabled', 'true' );
} );

it( 'should be true if forceIsSaving is true', () => {
render(
<PostPublishButton isPublishable isSaveable forceIsSaving />
);

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(
<PostPublishButton
Expand Down
4 changes: 1 addition & 3 deletions packages/editor/src/components/post-publish-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class PostPublishPanel extends Component {
render() {
const {
forceIsDirty,
forceIsSaving,
isBeingScheduled,
isPublished,
isPublishSidebarEnabled,
Expand Down Expand Up @@ -92,10 +91,9 @@ export class PostPublishPanel extends Component {
<>
<div className="editor-post-publish-panel__header-publish-button">
<PostPublishButton
focusOnMount={ true }
focusOnMount
onSubmit={ this.onSubmit }
forceIsDirty={ forceIsDirty }
forceIsSaving={ forceIsSaving }
/>
</div>
<div className="editor-post-publish-panel__header-cancel-button">
Expand Down
7 changes: 2 additions & 5 deletions packages/editor/src/components/post-saved-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export const autosave =
};

export const __unstableSaveForPreview =
( { forceIsAutosaveable, forcePreviewLink } ) =>
( { forceIsAutosaveable } ) =>
async ( { select, dispatch } ) => {
if (
( forceIsAutosaveable || select.isEditedPostAutosaveable() ) &&
Expand All @@ -317,7 +317,7 @@ export const __unstableSaveForPreview =
}
}

return forcePreviewLink ?? select.getEditedPostPreviewLink();
return select.getEditedPostPreviewLink();
};

/**
Expand Down

0 comments on commit 1b8dcb3

Please sign in to comment.