Skip to content

Commit

Permalink
Move duplicateTemplatePart action to the @wordpress/fields package (
Browse files Browse the repository at this point in the history
#65390)

Co-authored-by: gigitux <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: oandregal <[email protected]>
  • Loading branch information
4 people authored Dec 3, 2024
1 parent 826c430 commit 5900cf6
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 248 deletions.
2 changes: 1 addition & 1 deletion packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ $z-layers: (
// Should be above the popover (dropdown)
".reusable-blocks-menu-items__convert-modal": 1000001,
".patterns-menu-items__convert-modal": 1000001,
".editor-create-template-part-modal": 1000001,
".fields-create-template-part-modal": 1000001,
".block-editor-block-lock-modal": 1000001,
".block-editor-template-part__selection-modal": 1000001,
".block-editor-block-rename-modal": 1000001,
Expand Down
17 changes: 13 additions & 4 deletions packages/editor/src/components/post-actions/set-as-homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ import {
import { useDispatch, useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as noticesStore } from '@wordpress/notices';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import { getItemTitle } from '../../dataviews/actions/utils';
const getItemTitle = ( item ) => {
if ( typeof item.title === 'string' ) {
return decodeEntities( item.title );
}
if ( item.title && 'rendered' in item.title ) {
return decodeEntities( item.title.rendered );
}
if ( item.title && 'raw' in item.title ) {
return decodeEntities( item.title.raw );
}
return '';
};

const SetAsHomepageModal = ( { items, closeModal } ) => {
const [ item ] = items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { symbolFilled } from '@wordpress/icons';
/**
* Internal dependencies
*/
import CreateTemplatePartModal from '../create-template-part-modal';
import { CreateTemplatePartModal } from '@wordpress/fields';

export default function ConvertToTemplatePart( { clientIds, blocks } ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
Expand Down
64 changes: 0 additions & 64 deletions packages/editor/src/dataviews/actions/utils.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/editor/src/dataviews/store/private-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { doAction } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import type { PostType } from '../types';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import type { PostType } from '@wordpress/fields';
import {
viewPost,
viewPostRevisions,
Expand All @@ -24,6 +24,7 @@ import {
renamePost,
resetPost,
deletePost,
duplicateTemplatePart,
featuredImageField,
dateField,
parentField,
Expand All @@ -34,7 +35,6 @@ import {
authorField,
titleField,
} from '@wordpress/fields';
import duplicateTemplatePart from '../actions/duplicate-template-part';

export function registerEntityAction< Item >(
kind: string,
Expand Down
88 changes: 0 additions & 88 deletions packages/editor/src/dataviews/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { lock } from './lock-unlock';
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
import EditorContentSlotFill from './components/editor-interface/content-slot-fill';
import BackButton from './components/header/back-button';
import CreateTemplatePartModal from './components/create-template-part-modal';
import Editor from './components/editor';
import PluginPostExcerpt from './components/post-excerpt/plugin';
import PostCardPanel from './components/post-card-panel';
Expand All @@ -24,6 +23,7 @@ import {
mergeBaseAndUserConfigs,
GlobalStylesProvider,
} from './components/global-styles-provider';
import { CreateTemplatePartModal } from '@wordpress/fields';
import { registerCoreBlockBindingsSources } from './bindings/api';
import { getTemplateInfo } from './utils/get-template-info';

Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
@import "./components/autocompleters/style.scss";
@import "./components/collab-sidebar/style.scss";
@import "./components/collapsible-block-toolbar/style.scss";
@import "./components/create-template-part-modal/style.scss";
@import "./components/block-settings-menu/style.scss";
@import "./components/blog-title/style.scss";
@import "./components/document-bar/style.scss";
Expand Down
25 changes: 25 additions & 0 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ npm install @wordpress/fields --save

Author field for BasePost.

### BasePostWithEmbeddedAuthor

Undocumented declaration.

### commentStatusField

Comment status field for BasePost.

### CreateTemplatePartModal

A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part. This component should not live in this package, it should be moved to a dedicated package responsible for managing template.

_Parameters_

- _props_ `Object`: The component props.
- _props.modalTitle_ `{ modalTitle: string; } & CreateTemplatePartModalContentsProps[ 'modalTitle' ]`:

### dateField

Date field for BasePost.
Expand All @@ -42,6 +55,14 @@ Undocumented declaration.

Undocumented declaration.

### duplicateTemplatePart

This action is used to duplicate a template part.

_Type_

- `Action< TemplatePart >`

### exportPattern

Undocumented declaration.
Expand Down Expand Up @@ -70,6 +91,10 @@ This field is used to display the post password.

Undocumented declaration.

### PostType

Undocumented declaration.

### renamePost

Undocumented declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import type { Action } from '@wordpress/dataviews';
/**
* Internal dependencies
*/
import { TEMPLATE_PART_POST_TYPE } from '../../store/constants';
import { CreateTemplatePartModalContents } from '../../components/create-template-part-modal';
import { getItemTitle } from './utils';
import type { Post, TemplatePart } from '../types';
import { CreateTemplatePartModalContents } from '../components/create-template-part-modal';
import { getItemTitle } from './utils';

/**
* This action is used to duplicate a template part.
*/
const duplicateTemplatePart: Action< TemplatePart > = {
id: 'duplicate-template-part',
label: _x( 'Duplicate', 'action label' ),
isEligible: ( item ) => item.type === TEMPLATE_PART_POST_TYPE,
isEligible: ( item ) => item.type === 'wp_template_part',
modalHeader: _x( 'Duplicate template part', 'action label' ),
RenderModal: ( { items, closeModal } ) => {
const [ item ] = items;
Expand Down Expand Up @@ -61,7 +63,7 @@ const duplicateTemplatePart: Action< TemplatePart > = {
onCreate={ onTemplatePartSuccess }
onError={ closeModal }
confirmLabel={ _x( 'Duplicate', 'action label' ) }
closeModal={ closeModal }
closeModal={ closeModal ?? ( () => {} ) }
/>
);
},
Expand Down
1 change: 1 addition & 0 deletions packages/fields/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { default as permanentlyDeletePost } from './permanently-delete-post';
export { default as restorePost } from './restore-post';
export { default as trashPost } from './trash-post';
export { default as deletePost } from './delete-post';
export { default as duplicateTemplatePart } from './duplicate-template-part';
9 changes: 3 additions & 6 deletions packages/fields/src/actions/rename-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import {
isTemplateRemovable,
isTemplate,
isTemplatePart,
TEMPLATE_ORIGINS,
TEMPLATE_PART_POST_TYPE,
TEMPLATE_POST_TYPE,
} from './utils';
import type { CoreDataError, PostWithPermissions } from '../types';

Expand All @@ -45,8 +42,8 @@ const renamePost: Action< PostWithPermissions > = {
// Templates, template parts and patterns have special checks for renaming.
if (
! [
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
'wp_template',
'wp_template_part',
...Object.values( PATTERN_TYPES ),
].includes( post.type )
) {
Expand All @@ -64,7 +61,7 @@ const renamePost: Action< PostWithPermissions > = {

if ( isTemplatePart( post ) ) {
return (
post.source === TEMPLATE_ORIGINS.custom &&
post.source === 'custom' &&
! post?.has_theme_file &&
post.permissions?.update
);
Expand Down
Loading

1 comment on commit 5900cf6

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 5900cf6.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12137052342
📝 Reported issues:

Please sign in to comment.