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

Refactor getPostLink props #57745

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c4b9b1d
Use the new `getPostLinkProps` setting to push the template into the …
glendaviesnz Jan 8, 2024
4e25ee3
Remove use of `template-only` from post editor
glendaviesnz Jan 9, 2024
70bfde7
Remove some of the editor package template-only references
glendaviesnz Jan 9, 2024
3ca6d90
Remove remaining instances of template-only in editor package
glendaviesnz Jan 9, 2024
e269650
Put back some template checks as probably not relevant to pattern edi…
glendaviesnz Jan 9, 2024
25e036a
remove test code
glendaviesnz Jan 9, 2024
02cfbd3
Remove template-only from site editor
glendaviesnz Jan 10, 2024
f03992a
Get the new template id when creating a template in site editor
glendaviesnz Jan 10, 2024
c491f36
Fix broken string
glendaviesnz Jan 10, 2024
f07971d
Fix breadcrumb label
glendaviesnz Jan 10, 2024
81d503d
Fix issue with template check
glendaviesnz Jan 10, 2024
c5c9f3a
Remove unused class
glendaviesnz Jan 10, 2024
037f1d8
Fix issue where we should have been checking for history rather than …
glendaviesnz Jan 10, 2024
c5d8e80
Use the router in the site editor instead of getPostLinkProps
glendaviesnz Jan 10, 2024
1d92373
Set the default rendering mode in the post editor
glendaviesnz Jan 10, 2024
edf7352
Change getPostLinkProps to useChangeEntity to better reflect the wide…
glendaviesnz Jan 11, 2024
8e27b15
Remove the history from site editor, don't think it matters that back…
glendaviesnz Jan 11, 2024
47fb8e6
Change name to be more router centric
glendaviesnz Jan 12, 2024
80d7fe3
revert back to hasHistory setting name
glendaviesnz Jan 13, 2024
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
3 changes: 1 addition & 2 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,13 +1404,12 @@ _Returns_
Returns an action used to set the rendering mode of the post editor. We support multiple rendering modes:

- `all`: This is the default mode. It renders the post editor with all the features available. If a template is provided, it's preferred over the post.
- `template-only`: This mode renders the editor with only the template blocks visible.
- `post-only`: This mode extracts the post blocks from the template and renders only those. The idea is to allow the user to edit the post/page in isolation without the wrapping template.
- `template-locked`: This mode renders both the template and the post blocks but the template blocks are locked and can't be edited. The post blocks are editable.

_Parameters_

- _mode_ `string`: Mode (one of 'template-only', 'post-only', 'template-locked' or 'all').
- _mode_ `string`: Mode (one of 'post-only', 'template-locked' or 'all').

### setTemplateValidity

Expand Down
16 changes: 8 additions & 8 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default function ReusableBlockEdit( {
} = useDispatch( blockEditorStore );
const { syncDerivedUpdates } = unlock( useDispatch( blockEditorStore ) );

const { innerBlocks, userCanEdit, getBlockEditingMode, getPostLinkProps } =
const { innerBlocks, userCanEdit, getBlockEditingMode, getPostNavigation } =
useSelect(
( select ) => {
const { canUser } = select( coreStore );
Expand All @@ -183,19 +183,19 @@ export default function ReusableBlockEdit( {
innerBlocks: blocks,
userCanEdit: canEdit,
getBlockEditingMode: editingMode,
getPostLinkProps: getSettings().getPostLinkProps,
getPostNavigation: getSettings().getPostNavigation,
};
},
[ patternClientId, ref ]
);

const editOriginalProps = getPostLinkProps
? getPostLinkProps( {
const originalPatternNavigation = getPostNavigation
? getPostNavigation( {
postId: ref,
postType: 'wp_block',
canvas: 'edit',
} )
: {};
: undefined;

useEffect(
() => setBlockEditMode( setBlockEditingMode, innerBlocks ),
Expand Down Expand Up @@ -283,7 +283,7 @@ export default function ReusableBlockEdit( {

const handleEditOriginal = ( event ) => {
setBlockEditMode( setBlockEditingMode, innerBlocks, 'default' );
editOriginalProps.onClick( event );
originalPatternNavigation?.goTo( event );
};

let children = null;
Expand Down Expand Up @@ -314,11 +314,11 @@ export default function ReusableBlockEdit( {

return (
<RecursionProvider uniqueId={ ref }>
{ userCanEdit && editOriginalProps && (
{ userCanEdit && originalPatternNavigation && (
<BlockControls>
<ToolbarGroup>
<ToolbarButton
href={ editOriginalProps.href }
href={ originalPatternNavigation.link }
onClick={ handleEditOriginal }
>
{ __( 'Edit original' ) }
Expand Down
14 changes: 5 additions & 9 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function Header( { setEntitiesSavedStatesCallback } ) {
hasBlockSelection,
hasActiveMetaboxes,
hasFixedToolbar,
isEditingTemplate,
isPublishSidebarOpened,
showIconLabels,
hasHistory,
Expand All @@ -77,9 +76,7 @@ function Header( { setEntitiesSavedStatesCallback } ) {
hasBlockSelection:
!! select( blockEditorStore ).getBlockSelectionStart(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
hasHistory: !! select( editorStore ).getEditorSettings().goBack,
isEditingTemplate:
select( editorStore ).getRenderingMode() === 'template-only',
hasHistory: select( editorStore ).getEditorSettings().hasHistory,
isPublishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ),
Expand Down Expand Up @@ -120,8 +117,7 @@ function Header( { setEntitiesSavedStatesCallback } ) {
'selected-block-tools-wrapper',
{
'is-collapsed':
isEditingTemplate &&
isBlockToolsCollapsed,
hasHistory && isBlockToolsCollapsed,
}
) }
>
Expand All @@ -131,7 +127,7 @@ function Header( { setEntitiesSavedStatesCallback } ) {
ref={ blockToolbarRef }
name="block-toolbar"
/>
{ isEditingTemplate && hasBlockSelection && (
{ hasHistory && hasBlockSelection && (
<Button
className="edit-post-header__block-tools-toggle"
icon={ isBlockToolsCollapsed ? next : previous }
Expand All @@ -152,14 +148,14 @@ function Header( { setEntitiesSavedStatesCallback } ) {
<div
className={ classnames( 'edit-post-header__center', {
'is-collapsed':
isEditingTemplate &&
hasHistory &&
hasBlockSelection &&
! isBlockToolsCollapsed &&
hasFixedToolbar &&
isLargeViewport,
} ) }
>
{ ( isEditingTemplate || hasHistory ) && <DocumentBar /> }
{ hasHistory && <DocumentBar /> }
</div>
</motion.div>
<motion.div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ModeSwitcher() {
isCodeEditingEnabled:
select( editorStore ).getEditorSettings().codeEditingEnabled,
isEditingTemplate:
select( editorStore ).getRenderingMode() === 'template-only',
select( editorStore ).getCurrentPostType() === 'wp_template',
mode: select( editPostStore ).getEditorMode(),
} ),
[]
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function Layout() {
documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
hasBlockSelected:
!! select( blockEditorStore ).getBlockSelectionStart(),
hasHistory: !! getEditorSettings().goBack,
hasHistory: !! getEditorSettings().hasHistory,
};
}, [] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ import { sidebars } from '../settings-sidebar';
const { Tabs } = unlock( componentsPrivateApis );

const SettingsHeader = () => {
const { documentLabel, isTemplateMode } = useSelect( ( select ) => {
const { getPostTypeLabel, getRenderingMode } = select( editorStore );
const { documentLabel } = useSelect( ( select ) => {
const { getPostTypeLabel } = select( editorStore );

return {
// translators: Default label for the Document sidebar tab, not selected.
documentLabel: getPostTypeLabel() || _x( 'Document', 'noun' ),
isTemplateMode: getRenderingMode() === 'template-only',
};
}, [] );

return (
<Tabs.TabList>
<Tabs.Tab tabId={ sidebars.document }>
{ isTemplateMode ? __( 'Template' ) : documentLabel }
</Tabs.Tab>
<Tabs.Tab tabId={ sidebars.document }>{ documentLabel }</Tabs.Tab>
<Tabs.Tab tabId={ sidebars.block }>
{ /* translators: Text label for the Block Settings Sidebar tab. */ }
{ __( 'Block' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const sidebars = {
const SidebarContent = ( {
sidebarName,
keyboardShortcut,
isTemplateMode,
isEditingTemplate,
} ) => {
// Because `PluginSidebarEditPost` renders a `ComplementaryArea`, we
// need to forward the `Tabs` context so it can be passed through the
Expand Down Expand Up @@ -77,7 +77,7 @@ const SidebarContent = ( {
>
<Tabs.Context.Provider value={ tabsContextValue }>
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
{ ! isTemplateMode && (
{ ! isEditingTemplate && (
<>
<PostStatus />
<PluginDocumentSettingPanel.Slot />
Expand All @@ -90,7 +90,7 @@ const SidebarContent = ( {
<MetaBoxes location="side" />
</>
) }
{ isTemplateMode && <TemplateSummary /> }
{ isEditingTemplate && <TemplateSummary /> }
</Tabs.TabPanel>
<Tabs.TabPanel tabId={ sidebars.block } focusable={ false }>
<BlockInspector />
Expand All @@ -105,7 +105,7 @@ const SettingsSidebar = () => {
sidebarName,
isSettingsSidebarActive,
keyboardShortcut,
isTemplateMode,
isEditingTemplate,
} = useSelect( ( select ) => {
// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
// sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.
Expand All @@ -132,8 +132,8 @@ const SettingsSidebar = () => {
sidebarName: sidebar,
isSettingsSidebarActive: isSettingsSidebar,
keyboardShortcut: shortcut,
isTemplateMode:
select( editorStore ).getRenderingMode() === 'template-only',
isEditingTemplate:
select( editorStore ).getCurrentPostType() === 'wp_template',
};
}, [] );

Expand Down Expand Up @@ -161,7 +161,7 @@ const SettingsSidebar = () => {
<SidebarContent
sidebarName={ sidebarName }
keyboardShortcut={ keyboardShortcut }
isTemplateMode={ isTemplateMode }
isEditingTemplate={ isEditingTemplate }
/>
</Tabs>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import { Icon, layout } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { Flex, FlexItem, FlexBlock, PanelBody } from '@wordpress/components';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
import { store as editorStore } from '@wordpress/editor';

function TemplateSummary() {
const template = useSelect( ( select ) => {
const { getEditedPostTemplate } = select( editPostStore );
return getEditedPostTemplate();
const { getCurrentPost } = select( editorStore );
return getCurrentPost();
}, [] );

if ( ! template ) {
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function VisualEditor( { styles } ) {
renderingMode,
isBlockBasedTheme,
hasV3BlocksOnly,
isEditingTemplate,
} = useSelect( ( select ) => {
const { isFeatureActive } = select( editPostStore );
const { getEditorSettings, getRenderingMode } = select( editorStore );
Expand All @@ -43,6 +44,8 @@ export default function VisualEditor( { styles } ) {
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
return type.apiVersion >= 3;
} ),
isEditingTemplate:
select( editorStore ).getCurrentPostType() === 'wp_template',
};
}, [] );
const hasMetaBoxes = useSelect(
Expand Down Expand Up @@ -74,12 +77,11 @@ export default function VisualEditor( { styles } ) {
const isToBeIframed =
( ( hasV3BlocksOnly || ( isGutenbergPlugin && isBlockBasedTheme ) ) &&
! hasMetaBoxes ) ||
renderingMode === 'template-only';
isEditingTemplate;

return (
<div
className={ classnames( 'edit-post-visual-editor', {
'is-template-mode': renderingMode === 'template-only',
'has-inline-canvas': ! isToBeIframed,
} ) }
>
Expand Down
17 changes: 11 additions & 6 deletions packages/edit-post/src/components/welcome-guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@ import WelcomeGuideTemplate from './template';
import { store as editPostStore } from '../../store';

export default function WelcomeGuide() {
const { isActive, isTemplateMode } = useSelect( ( select ) => {
const { isActive, isEditingTemplate } = useSelect( ( select ) => {
const { isFeatureActive } = select( editPostStore );
const { getRenderingMode } = select( editorStore );
const _isTemplateMode = getRenderingMode() === 'template-only';
const feature = _isTemplateMode
const { getCurrentPostType } = select( editorStore );
const _isEditingTemplate = getCurrentPostType() === 'wp_template';

const feature = _isEditingTemplate
? 'welcomeGuideTemplate'
: 'welcomeGuide';

return {
isActive: isFeatureActive( feature ),
isTemplateMode: _isTemplateMode,
isEditingTemplate: _isEditingTemplate,
};
}, [] );

if ( ! isActive ) {
return null;
}

return isTemplateMode ? <WelcomeGuideTemplate /> : <WelcomeGuideDefault />;
return isEditingTemplate ? (
<WelcomeGuideTemplate />
) : (
<WelcomeGuideDefault />
);
}
Loading
Loading