-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Fields] Migrate store and actions from editor package to fields package #65261
Changes from all commits
67ff043
a71e726
0141d8c
f21a974
7063ee8
644dab1
3616964
f7f1d4d
ae0efeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,22 +8,24 @@ import { doAction } from '@wordpress/hooks'; | |||||
/** | ||||||
* Internal dependencies | ||||||
*/ | ||||||
import deletePost from '../actions/delete-post'; | ||||||
import duplicatePattern from '../actions/duplicate-pattern'; | ||||||
import duplicateTemplatePart from '../actions/duplicate-template-part'; | ||||||
import exportPattern from '../actions/export-pattern'; | ||||||
import resetPost from '../actions/reset-post'; | ||||||
import trashPost from '../actions/trash-post'; | ||||||
import permanentlyDeletePost from '../actions/permanently-delete-post'; | ||||||
import renamePost from '../actions/rename-post'; | ||||||
import reorderPage from '../actions/reorder-page'; | ||||||
import restorePost from '../actions/restore-post'; | ||||||
import type { PostType } from '../types'; | ||||||
import { store as editorStore } from '../../store'; | ||||||
import { unlock } from '../../lock-unlock'; | ||||||
import duplicatePost from '../actions/duplicate-post'; | ||||||
import viewPostRevisions from '../actions/view-post-revisions'; | ||||||
import viewPost from '../actions/view-post'; | ||||||
import { | ||||||
viewPost, | ||||||
viewPostRevisions, | ||||||
duplicatePost, | ||||||
duplicatePattern, | ||||||
reorderPage, | ||||||
exportPattern, | ||||||
permanentlyDeletePost, | ||||||
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. If we're going to export actions and fields from the same package, maybe we should consider suffixing these with 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. Yeah, my idea is to have a structure like this Action. gutenberg/packages/fields/src/actions/base-post/duplicate-post.tsx Lines 30 to 31 in 3616964
For instance, the 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. I'm a bit confused about why this exports actions. How you all envision the 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. I think that the |
||||||
} from '@wordpress/fields'; | ||||||
import deletePost from '../actions/delete-post'; | ||||||
|
||||||
export function registerEntityAction< Item >( | ||||||
kind: string, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,53 @@ npm install @wordpress/fields --save | |
|
||
<!-- START TOKEN(Autogenerated API docs) --> | ||
|
||
Nothing to document. | ||
### duplicatePattern | ||
|
||
Undocumented declaration. | ||
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. Would be cool to add some placeholder JS Docs for these to avoid the "Undocumented declaration". We can definitely do that in a separate PR though. 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. After wrapped up the migration, I will:
|
||
|
||
### duplicatePost | ||
|
||
Undocumented declaration. | ||
|
||
### duplicatePostNative | ||
|
||
Undocumented declaration. | ||
|
||
### exportPattern | ||
|
||
Undocumented declaration. | ||
|
||
### exportPatternNative | ||
|
||
Undocumented declaration. | ||
|
||
### orderField | ||
|
||
Undocumented declaration. | ||
|
||
### permanentlyDeletePost | ||
|
||
Undocumented declaration. | ||
|
||
### reorderPage | ||
|
||
Undocumented declaration. | ||
|
||
### reorderPageNative | ||
|
||
Undocumented declaration. | ||
|
||
### titleField | ||
|
||
Undocumented declaration. | ||
|
||
### viewPost | ||
|
||
Undocumented declaration. | ||
|
||
### viewPostRevisions | ||
|
||
Undocumented declaration. | ||
|
||
<!-- END TOKEN(Autogenerated API docs) --> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { default as viewPost } from './view-post'; | ||
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. Do we need the "base-post" folder? 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. I don't have a strong opinion, but I explained why I structured it in this way in the PR description! Happy to revisit it! 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. I like to start flat personally in general but I don't mind if you prefer it this way. |
||
export { default as reorderPage } from './reorder-page'; | ||
export { default as reorderPageNative } from './reorder-page.native'; | ||
export { default as duplicatePost } from './duplicate-post'; | ||
export { default as duplicatePostNative } from './duplicate-post.native'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as viewPostRevisions } from './view-post-revisions'; | ||
export { default as permanentlyDeletePost } from './permanently-delete-post'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './base-post'; | ||
export * from './common'; | ||
export * from './pattern'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as duplicatePattern } from './duplicate-pattern'; | ||
export { default as exportPattern } from './export-pattern'; | ||
export { default as exportPatternNative } from './export-pattern.native'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Post, TemplatePart, Template } from '../types'; | ||
|
||
export const TEMPLATE_POST_TYPE = 'wp_template'; | ||
export const TEMPLATE_PART_POST_TYPE = 'wp_template_part'; | ||
export const TEMPLATE_ORIGINS = { | ||
custom: 'custom', | ||
theme: 'theme', | ||
plugin: 'plugin', | ||
}; | ||
|
||
export function isTemplate( post: Post ): post is Template { | ||
return post.type === TEMPLATE_POST_TYPE; | ||
} | ||
|
||
export function isTemplatePart( post: Post ): post is TemplatePart { | ||
return post.type === TEMPLATE_PART_POST_TYPE; | ||
} | ||
|
||
export function isTemplateOrTemplatePart( | ||
p: Post | ||
): p is Template | TemplatePart { | ||
return p.type === TEMPLATE_POST_TYPE || p.type === TEMPLATE_PART_POST_TYPE; | ||
} | ||
|
||
export function getItemTitle( item: Post ) { | ||
if ( typeof item.title === 'string' ) { | ||
return decodeEntities( item.title ); | ||
} | ||
if ( 'rendered' in item.title ) { | ||
return decodeEntities( item.title.rendered ); | ||
} | ||
if ( 'raw' in item.title ) { | ||
return decodeEntities( item.title.raw ); | ||
} | ||
return ''; | ||
} | ||
|
||
/** | ||
* Check if a template is removable. | ||
* | ||
* @param template The template entity to check. | ||
* @return Whether the template is removable. | ||
*/ | ||
export function isTemplateRemovable( template: Template | TemplatePart ) { | ||
if ( ! template ) { | ||
return false; | ||
} | ||
// In patterns list page we map the templates parts to a different object | ||
// than the one returned from the endpoint. This is why we need to check for | ||
// two props whether is custom or has a theme file. | ||
return ( | ||
[ template.source, template.source ].includes( | ||
TEMPLATE_ORIGINS.custom | ||
) && | ||
! Boolean( template.type === 'wp_template' && template?.plugin ) && | ||
! template.has_theme_file | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as titleField } from './title'; | ||
export { default as orderField } from './order'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import type { Field } from '@wordpress/dataviews'; | ||
import { __ } from '@wordpress/i18n'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
|
||
const orderField: Field< BasePost > = { | ||
type: 'integer', | ||
id: 'menu_order', | ||
label: __( 'Order' ), | ||
description: __( 'Determines the order of pages.' ), | ||
}; | ||
|
||
export default orderField; |
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.
The deleted code has been migrated to the
@wordpress/fields
package