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

Editor: Unify the sidebar between the post and site editors #61507

Merged
merged 9 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 53 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { store as preferencesStore } from '@wordpress/preferences';
import { privateApis as commandsPrivateApis } from '@wordpress/commands';
import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands';
import { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
Expand Down Expand Up @@ -273,6 +274,57 @@ function Layout( { initialPost } ) {
);
}

const { createSuccessNotice } = useDispatch( noticesStore );

const onActionPerformed = useCallback(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This callback is specific per editor at the moment. So I moved it into a prop to the "Sidebar" component. Ideally this should be the same between editors to be honest.

( actionId, items ) => {
switch ( actionId ) {
case 'move-to-trash':
{
const postType = items[ 0 ].type;
document.location.href = addQueryArgs( 'edit.php', {
post_type: postType,
} );
}
break;
Comment on lines +282 to +289
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: The move-to-trash action doesn't display a notice in the post table list view after trashing the post. We'll need to match the main "Move to Trash" button behavior.

Screenshot

CleanShot 2024-05-13 at 13 37 12

case 'duplicate-post':
{
const newItem = items[ 0 ];
const title =
typeof newItem.title === 'string'
? newItem.title
: newItem.title?.rendered;
createSuccessNotice(
sprintf(
// translators: %s: Title of the created post e.g: "Post 1".
__( '"%s" successfully created.' ),
title
),
{
type: 'snackbar',
id: 'duplicate-post-action',
actions: [
{
label: __( 'Edit' ),
onClick: () => {
const postId = newItem.id;
document.location.href =
addQueryArgs( 'post.php', {
post: postId,
action: 'edit',
} );
},
},
],
}
);
}
break;
}
},
[ createSuccessNotice ]
);

return (
<>
<FullscreenMode isActive={ isFullscreenActive } />
Expand Down Expand Up @@ -363,6 +415,7 @@ function Layout( { initialPost } ) {
<PluginArea onError={ onPluginAreaError } />
{ ! isDistractionFree && (
<Sidebar
onActionPerformed={ onActionPerformed }
extraPanels={
! isEditingTemplate && <MetaBoxes location="side" />
}
Expand Down
86 changes: 74 additions & 12 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
BlockBreadcrumb,
BlockToolbar,
store as blockEditorStore,
BlockInspector,
} from '@wordpress/block-editor';
import {
EditorKeyboardShortcutsRegister,
Expand All @@ -36,14 +35,12 @@ import { __, sprintf } from '@wordpress/i18n';
import { store as coreDataStore } from '@wordpress/core-data';
import { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library';
import { useState, useCallback } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
*/
import {
SidebarComplementaryAreaFills,
SidebarInspectorFill,
} from '../sidebar-edit-mode';
import CodeEditor from '../code-editor';
import Header from '../header-edit-mode';
import WelcomeGuide from '../welcome-guide';
Expand All @@ -59,6 +56,8 @@ import { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../utils/constants';
import SiteEditorCanvas from '../block-editor/site-editor-canvas';
import TemplatePartConverter from '../template-part-converter';
import { useSpecificEditorSettings } from '../block-editor/use-site-editor-settings';
import PluginTemplateSettingPanel from '../plugin-template-setting-panel';
import GlobalStylesSidebar from '../global-styles-sidebar';

const {
ExperimentalEditorProvider: EditorProvider,
Expand All @@ -68,8 +67,9 @@ const {
ComplementaryArea,
interfaceStore,
SavePublishPanels,
Sidebar,
} = unlock( editorPrivateApis );

const { useHistory } = unlock( routerPrivateApis );
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );

const interfaceLabels = {
Expand Down Expand Up @@ -112,14 +112,16 @@ export default function Editor( { isLoading, onClick } ) {
showIconLabels,
showBlockBreadcrumbs,
postTypeLabel,
isEditingPage,
supportsGlobalStyles,
} = useSelect( ( select ) => {
const { get } = select( preferencesStore );
const { getEditedPostContext, getCanvasMode } = unlock(
const { getEditedPostContext, getCanvasMode, isPage } = unlock(
select( editSiteStore )
);
const { __unstableGetEditorMode } = select( blockEditorStore );
const { getActiveComplementaryArea } = select( interfaceStore );
const { getEntityRecord } = select( coreDataStore );
const { getEntityRecord, getCurrentTheme } = select( coreDataStore );
const {
isInserterOpened,
isListViewOpened,
Expand Down Expand Up @@ -149,6 +151,8 @@ export default function Editor( { isLoading, onClick } ) {
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
showIconLabels: get( 'core', 'showIconLabels' ),
postTypeLabel: getPostTypeLabel(),
isEditingPage: isPage(),
supportsGlobalStyles: getCurrentTheme()?.is_block_theme,
};
}, [] );

Expand Down Expand Up @@ -207,6 +211,59 @@ export default function Editor( { isLoading, onClick } ) {
[ entitiesSavedStatesCallback ]
);

const { createSuccessNotice } = useDispatch( noticesStore );
const history = useHistory();
const onActionPerformed = useCallback(
( actionId, items ) => {
switch ( actionId ) {
case 'move-to-trash':
{
history.push( {
path: '/' + items[ 0 ].type,
postId: undefined,
postType: undefined,
canvas: 'view',
} );
}
break;
case 'duplicate-post':
{
const newItem = items[ 0 ];
const _title =
typeof newItem.title === 'string'
? newItem.title
: newItem.title?.rendered;
createSuccessNotice(
sprintf(
// translators: %s: Title of the created post e.g: "Post 1".
__( '"%s" successfully created.' ),
_title
),
{
type: 'snackbar',
id: 'duplicate-post-action',
actions: [
{
label: __( 'Edit' ),
onClick: () => {
history.push( {
path: undefined,
postId: newItem.id,
postType: newItem.type,
canvas: 'edit',
} );
},
},
],
}
);
}
break;
}
},
[ history, createSuccessNotice ]
);

const isReady =
! isLoading &&
( ( postWithTemplate && !! contextPost && !! editedPost ) ||
Expand All @@ -232,7 +289,6 @@ export default function Editor( { isLoading, onClick } ) {
settings={ settings }
useSubRegistry={ false }
>
<SidebarComplementaryAreaFills />
{ isEditMode && <StartTemplateOptions /> }
<InterfaceSkeleton
isDistractionFree={ isDistractionFree }
Expand Down Expand Up @@ -299,9 +355,6 @@ export default function Editor( { isLoading, onClick } ) {
{ showVisualEditor && (
<>
<TemplatePartConverter />
<SidebarInspectorFill>
<BlockInspector />
</SidebarInspectorFill>
{ ! isLargeViewport && (
<BlockToolbar hideDragHandle />
) }
Expand Down Expand Up @@ -349,6 +402,15 @@ export default function Editor( { isLoading, onClick } ) {
secondarySidebar: secondarySidebarLabel,
} }
/>
<Sidebar
onActionPerformed={ onActionPerformed }
extraPanels={
! isEditingPage && (
<PluginTemplateSettingPanel.Slot />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position of this slot has changed in the DOM. This slot is also deprecated, so I'm not sure we should make the effort to keep the previous position or not.

)
}
/>
{ supportsGlobalStyles && <GlobalStylesSidebar /> }
</EditorProvider>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {
/**
* Internal dependencies
*/
import DefaultSidebar from './default-sidebar';
import { GlobalStylesUI } from '../global-styles';
import { store as editSiteStore } from '../../store';
import { GlobalStylesMenuSlot } from '../global-styles/ui';
import { unlock } from '../../lock-unlock';
import { store as coreStore } from '@wordpress/core-data';
import DefaultSidebar from './default-sidebar';

const { interfaceStore } = unlock( editorPrivateApis );

Expand Down
Loading
Loading