Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse and unify post and page actions, accross the different use cases. #60486

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ $z-layers: (
".block-editor-block-rename-modal": 1000001,
".edit-site-list__rename-modal": 1000001,
".dataviews-action-modal": 1000001,
".editor-action-modal": 1000001,
".editor-post-template__swap-template-modal": 1000001,
".edit-site-template-panel__replace-template-modal": 1000001,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
PostTaxonomiesPanel,
privateApis as editorPrivateApis,
} from '@wordpress/editor';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
Expand All @@ -39,7 +40,7 @@ import { store as editPostStore } from '../../../store';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { unlock } from '../../../lock-unlock';

const { PostCardPanel } = unlock( editorPrivateApis );
const { PostCardPanel, PostActions } = unlock( editorPrivateApis );

const { Tabs } = unlock( componentsPrivateApis );
const { PatternOverridesPanel } = unlock( editorPrivateApis );
Expand All @@ -53,6 +54,15 @@ export const sidebars = {
block: 'edit-post/block',
};

function onActionPerformed( actionId, items ) {
if ( actionId === 'move-to-trash' ) {
const postType = items[ 0 ].type;
document.location.href = addQueryArgs( 'edit.php', {
post_type: postType,
} );
}
}

const SidebarContent = ( {
sidebarName,
keyboardShortcut,
Expand Down Expand Up @@ -113,7 +123,13 @@ const SidebarContent = ( {
>
<Tabs.Context.Provider value={ tabsContextValue }>
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
<PostCardPanel />
<PostCardPanel
actions={
<PostActions
onActionPerformed={ onActionPerformed }
/>
}
/>
{ ! isEditingTemplate && (
<>
<PostStatus />
Expand Down
40 changes: 0 additions & 40 deletions packages/edit-site/src/components/page-actions/index.js

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,58 @@ import {
privateApis as editorPrivateApis,
} from '@wordpress/editor';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../../store';
import PageActions from '../../page-actions';
import PageContent from './page-content';
import PageSummary from './page-summary';

import { unlock } from '../../../lock-unlock';

const { PostCardPanel } = unlock( editorPrivateApis );
const { PostCardPanel, PostActions } = unlock( editorPrivateApis );
const { useHistory } = unlock( routerPrivateApis );

export default function PagePanels() {
const { hasResolved, page, 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 ];
return {
hasResolved: hasFinishedResolution(
'getEditedEntityRecord',
queryArgs
),
page: getEditedEntityRecord( ...queryArgs ),
renderingMode: getRenderingMode(),
};
}, [] );
const history = useHistory();
const { id, type, hasResolved, status, date, password, 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
),
id: page?.id,
type: page?.type,
status: page?.status,
date: page?.date,
password: page?.password,
renderingMode: getRenderingMode(),
};
}, [] );

const { id, type, status, date, password } = page;
const history = useHistory();
const onActionPerformed = useCallback(
( actionId, items ) => {
if ( actionId === 'move-to-trash' ) {
history.push( {
path: '/' + items[ 0 ].type,
postId: undefined,
postType: undefined,
canvas: 'view',
} );
}
},
[ history ]
);

if ( ! hasResolved ) {
return null;
Expand All @@ -59,16 +77,7 @@ export default function PagePanels() {
<>
<PostCardPanel
actions={
<PageActions
page={ page }
className="edit-site-page-card__actions"
toggleProps={ { size: 'small' } }
onRemove={ () => {
history.push( {
path: '/page',
} );
} }
/>
<PostActions onActionPerformed={ onActionPerformed } />
}
/>
<PanelBody title={ __( 'Summary' ) }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import { pencil } from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { escapeAttribute } from '@wordpress/escape-html';
import { safeDecodeURIComponent, filterURLForDisplay } from '@wordpress/url';
import { useEffect } from '@wordpress/element';
import { useEffect, useCallback } from '@wordpress/element';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { privateApis as editorPrivateApis } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -26,17 +27,16 @@ import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';
import PageDetails from './page-details';
import PageActions from '../page-actions';
import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-details-footer';

const { useHistory } = unlock( routerPrivateApis );
const { PostActions } = unlock( editorPrivateApis );

export default function SidebarNavigationScreenPage( { backPath } ) {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const history = useHistory();
const {
params: { postId },
goTo,
} = useNavigator();
const { record, hasResolved } = useEntityRecord(
'postType',
Expand Down Expand Up @@ -82,6 +82,20 @@ export default function SidebarNavigationScreenPage( { backPath } ) {
}
}, [ hasResolved, history ] );

const onActionPerformed = useCallback(
( actionId, items ) => {
if ( actionId === 'move-to-trash' ) {
history.push( {
path: '/' + items[ 0 ].type,
postId: undefined,
postType: undefined,
canvas: 'view',
} );
}
},
[ history ]
);

const featureImageAltText = featuredMediaAltText
? decodeEntities( featuredMediaAltText )
: decodeEntities( record?.title?.rendered || __( 'Featured image' ) );
Expand All @@ -94,13 +108,7 @@ export default function SidebarNavigationScreenPage( { backPath } ) {
) }
actions={
<>
<PageActions
page={ record }
toggleProps={ { as: SidebarButton } }
onRemove={ () => {
goTo( '/page' );
} }
/>
<PostActions onActionPerformed={ onActionPerformed } />
<SidebarButton
onClick={ () => setCanvasMode( 'edit' ) }
label={ __( 'Edit' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@
fill: $alert-green;
}
}

.edit-site-sidebar-navigation-screen__actions .editor-all-actions-button {
color: inherit;
}
Loading
Loading