Skip to content

Commit

Permalink
[Editor]: Move Post Status to editor package
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Mar 14, 2024
1 parent 08f14e9 commit 3c0436e
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PostURLPanel,
PostTemplatePanel,
PostFeaturedImagePanel,
PostStatus as PostStatusPanel,
store as editorStore,
} from '@wordpress/editor';

Expand Down Expand Up @@ -62,6 +63,7 @@ export default function PostStatus() {
{ ( fills ) => (
<>
<PostFeaturedImagePanel withPanelBody={ false } />
<PostStatusPanel />
<PostVisibility />
<PostSchedulePanel />
<PostTemplatePanel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,27 @@ import PageContent from './page-content';
import PageSummary from './page-summary';

export default function PagePanels() {
const {
id,
type,
hasResolved,
status,
date,
password,
title,
modified,
renderingMode,
} = useSelect( ( select ) => {
const { getEditedPostContext } = select( editSiteStore );
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getRenderingMode } = select( editorStore );
const context = getEditedPostContext();
const queryArgs = [ 'postType', context.postType, context.postId ];
const page = getEditedEntityRecord( ...queryArgs );
return {
hasResolved: hasFinishedResolution(
'getEditedEntityRecord',
queryArgs
),
title: page?.title,
id: page?.id,
type: page?.type,
status: page?.status,
date: page?.date,
password: page?.password,
modified: page?.modified,
renderingMode: getRenderingMode(),
};
}, [] );
const { hasResolved, title, modified, renderingMode } = useSelect(
( select ) => {
const { getEditedPostContext } = select( editSiteStore );
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getRenderingMode } = select( editorStore );
const context = getEditedPostContext();
const queryArgs = [ 'postType', context.postType, context.postId ];
const page = getEditedEntityRecord( ...queryArgs );
return {
hasResolved: hasFinishedResolution(
'getEditedEntityRecord',
queryArgs
),
title: page?.title,
modified: page?.modified,
renderingMode: getRenderingMode(),
};
},
[]
);

if ( ! hasResolved ) {
return null;
Expand All @@ -88,13 +76,7 @@ export default function PagePanels() {
/>
</PanelBody>
<PanelBody title={ __( 'Summary' ) }>
<PageSummary
status={ status }
date={ date }
password={ password }
postId={ id }
postType={ type }
/>
<PageSummary />
</PanelBody>
{ renderingMode !== 'post-only' && (
<PanelBody title={ __( 'Content' ) }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,14 @@ import {
PostSchedulePanel,
PostTemplatePanel,
PostFeaturedImagePanel,
PostStatus,
} from '@wordpress/editor';

/**
* Internal dependencies
*/
import PageStatus from './page-status';

export default function PageSummary( {
status,
date,
password,
postId,
postType,
} ) {
export default function PageSummary() {
return (
<VStack spacing={ 0 }>
<PostFeaturedImagePanel withPanelBody={ false } />
<PageStatus
status={ status }
date={ date }
password={ password }
postId={ postId }
postType={ postType }
/>
<PostStatus />
<PostSchedulePanel />
<PostTemplatePanel />
<PostURLPanel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,3 @@
.edit-site-page-panels__swap-template__confirm-modal__actions {
margin-top: $grid-unit-30;
}

.edit-site-change-status__content {
.components-popover__content {
min-width: 320px;
padding: $grid-unit-20;
}

.edit-site-change-status__options {
.components-base-control__field > .components-v-stack {
gap: $grid-unit-10;
}

label {
.components-text {
display: block;
}
}
}

.edit-site-change-status__password-legend {
padding: 0;
margin-bottom: $grid-unit-10;
}
}

.edit-site-summary-field__trigger {
max-width: 100%;

// Truncate
display: block;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
import { store as coreStore, useEntityRecord } from '@wordpress/core-data';
import { safeDecodeURIComponent } from '@wordpress/url';
import { PostStatusLabel } from '@wordpress/editor';

/**
* Internal dependencies
*/
import StatusLabel from './status-label';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import {
Expand All @@ -35,7 +35,7 @@ function getPageDetails( page ) {
{
label: __( 'Status' ),
value: (
<StatusLabel
<PostStatusLabel
status={ page?.password ? 'protected' : page.status }
date={ page?.date }
short
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export {
} from './post-schedule/label';
export { default as PostSchedulePanel } from './post-schedule/panel';
export { default as PostSlug } from './post-slug';
export { default as PostStatus, PostStatusLabel } from './post-status';
export { default as PostSlugCheck } from './post-slug/check';
export { default as PostSticky } from './post-sticky';
export { default as PostStickyCheck } from './post-sticky/check';
Expand Down
23 changes: 4 additions & 19 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export class PostPublishButton extends Component {
render() {
const {
forceIsDirty,
hasPublishAction,
isBeingScheduled,
isOpen,
isPostSavingLocked,
Expand All @@ -116,9 +115,9 @@ export class PostPublishButton extends Component {
onStatusChange,
onSubmit = noop,
onToggle,
visibility,
hasNonPostEntityChanges,
isSavingNonPostEntityChanges,
status,
} = this.props;

const isButtonDisabled =
Expand All @@ -135,23 +134,12 @@ export class PostPublishButton extends Component {
( ! isPublishable && ! forceIsDirty ) ) &&
( ! hasNonPostEntityChanges || isSavingNonPostEntityChanges );

let publishStatus;
if ( ! hasPublishAction ) {
publishStatus = 'pending';
} else if ( visibility === 'private' ) {
publishStatus = 'private';
} else if ( isBeingScheduled ) {
publishStatus = 'future';
} else {
publishStatus = 'publish';
}

const onClickButton = () => {
if ( isButtonDisabled ) {
return;
}
onSubmit();
onStatusChange( publishStatus );
onStatusChange( status );
onSave();
};

Expand Down Expand Up @@ -218,32 +206,29 @@ export default compose( [
isSavingPost,
isAutosavingPost,
isEditedPostBeingScheduled,
getEditedPostVisibility,
isCurrentPostPublished,
isEditedPostSaveable,
isEditedPostPublishable,
isPostSavingLocked,
getCurrentPost,
getCurrentPostType,
getCurrentPostId,
getEditedPostAttribute,
hasNonPostEntityChanges,
isSavingNonPostEntityChanges,
} = select( editorStore );
return {
isSaving: isSavingPost(),
isAutoSaving: isAutosavingPost(),
isBeingScheduled: isEditedPostBeingScheduled(),
visibility: getEditedPostVisibility(),
isSaveable: isEditedPostSaveable(),
isPostSavingLocked: isPostSavingLocked(),
isPublishable: isEditedPostPublishable(),
isPublished: isCurrentPostPublished(),
hasPublishAction:
getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
postType: getCurrentPostType(),
postId: getCurrentPostId(),
hasNonPostEntityChanges: hasNonPostEntityChanges(),
isSavingNonPostEntityChanges: isSavingNonPostEntityChanges(),
status: getEditedPostAttribute( 'status' ),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
Loading

0 comments on commit 3c0436e

Please sign in to comment.