-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from all commits
1f54593
29fb78a
07385d8
3e6ebfe
9e72ea9
9b68638
949f6a1
22e2ed0
12d2b9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -273,6 +274,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; | ||
Comment on lines
+282
to
+289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 } /> | ||
|
@@ -363,6 +415,7 @@ function Layout( { initialPost } ) { | |
<PluginArea onError={ onPluginAreaError } /> | ||
{ ! isDistractionFree && ( | ||
<Sidebar | ||
onActionPerformed={ onActionPerformed } | ||
extraPanels={ | ||
! isEditingTemplate && <MetaBoxes location="side" /> | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ import { | |
BlockBreadcrumb, | ||
BlockToolbar, | ||
store as blockEditorStore, | ||
BlockInspector, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
EditorKeyboardShortcutsRegister, | ||
|
@@ -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'; | ||
|
@@ -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, | ||
|
@@ -68,8 +67,9 @@ const { | |
ComplementaryArea, | ||
interfaceStore, | ||
SavePublishPanels, | ||
Sidebar, | ||
} = unlock( editorPrivateApis ); | ||
|
||
const { useHistory } = unlock( routerPrivateApis ); | ||
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis ); | ||
|
||
const interfaceLabels = { | ||
|
@@ -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, | ||
|
@@ -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, | ||
}; | ||
}, [] ); | ||
|
||
|
@@ -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 ) || | ||
|
@@ -232,7 +289,6 @@ export default function Editor( { isLoading, onClick } ) { | |
settings={ settings } | ||
useSubRegistry={ false } | ||
> | ||
<SidebarComplementaryAreaFills /> | ||
{ isEditMode && <StartTemplateOptions /> } | ||
<InterfaceSkeleton | ||
isDistractionFree={ isDistractionFree } | ||
|
@@ -299,9 +355,6 @@ export default function Editor( { isLoading, onClick } ) { | |
{ showVisualEditor && ( | ||
<> | ||
<TemplatePartConverter /> | ||
<SidebarInspectorFill> | ||
<BlockInspector /> | ||
</SidebarInspectorFill> | ||
{ ! isLargeViewport && ( | ||
<BlockToolbar hideDragHandle /> | ||
) } | ||
|
@@ -349,6 +402,15 @@ export default function Editor( { isLoading, onClick } ) { | |
secondarySidebar: secondarySidebarLabel, | ||
} } | ||
/> | ||
<Sidebar | ||
onActionPerformed={ onActionPerformed } | ||
extraPanels={ | ||
! isEditingPage && ( | ||
<PluginTemplateSettingPanel.Slot /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
) } | ||
</> | ||
|
There was a problem hiding this comment.
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.