Skip to content

Commit

Permalink
Editor: Unify the sidebar between the post and site editors
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 8, 2024
1 parent 293537d commit 04058d5
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 674 deletions.
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 @@ -287,6 +288,57 @@ function Layout( { initialPost } ) {
);
}

const { createSuccessNotice } = useDispatch( noticesStore );

const onActionPerformed = useCallback(
( actionId, items ) => {
switch ( actionId ) {
case 'move-to-trash':
{
const postType = items[ 0 ].type;
document.location.href = addQueryArgs( 'edit.php', {
post_type: postType,
} );
}
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: () => {
const postId = newItem.id;
document.location.href =
addQueryArgs( 'post.php', {
post: postId,
action: 'edit',
} );
},
},
],
}
);
}
break;
}
},
[ createSuccessNotice ]
);

return (
<>
<FullscreenMode isActive={ isFullscreenActive } />
Expand Down Expand Up @@ -377,6 +429,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 />
)
}
/>
{ 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

0 comments on commit 04058d5

Please sign in to comment.