Skip to content

Commit

Permalink
QuickEdit: Add Parent field (WordPress#66527)
Browse files Browse the repository at this point in the history
* Data Views: Add Parent field

* add comment

* improve documentation

* fix preview

* use number type

* enable sorting

* move logic in the useMemo function

* consolidate data.parent in one variable

Co-authored-by: gigitux <[email protected]>
Co-authored-by: oandregal <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent 49a9318 commit e6bdfd5
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function PostEditForm( { postType, postId } ) {
'author',
'date',
'slug',
'parent',
'comment_status',
],
};
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/post-fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import clsx from 'clsx';
*/
import { __, sprintf } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import { featuredImageField, slugField } from '@wordpress/fields';
import { featuredImageField, slugField, parentField } from '@wordpress/fields';
import {
createInterpolateElement,
useMemo,
Expand Down Expand Up @@ -321,6 +321,7 @@ function usePostFields( viewType ) {
},
},
slugField,
parentField,
{
id: 'comment_status',
label: __( 'Discussion' ),
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Undocumented declaration.

Undocumented declaration.

### parentField

This field is used to display the post parent.

### permanentlyDeletePost

Undocumented declaration.
Expand Down
3 changes: 2 additions & 1 deletion packages/fields/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"@wordpress/url": "*",
"@wordpress/warning": "*",
"change-case": "4.1.2",
"client-zip": "^2.4.5"
"client-zip": "^2.4.5",
"remove-accents": "^0.5.0"
},
"peerDependencies": {
"react": "^18.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/fields/src/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as slugField } from './slug';
export { default as titleField } from './title';
export { default as orderField } from './order';
export { default as featuredImageField } from './featured-image';
export { default as parentField } from './parent';
27 changes: 27 additions & 0 deletions packages/fields/src/fields/parent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* WordPress dependencies
*/
import type { Field } from '@wordpress/dataviews';

/**
* Internal dependencies
*/
import type { BasePost } from '../../types';
import { __ } from '@wordpress/i18n';
import { ParentEdit } from './parent-edit';
import { ParentView } from './parent-view';

const parentField: Field< BasePost > = {
id: 'parent',
type: 'text',
label: __( 'Parent' ),
getValue: ( { item } ) => item.parent,
Edit: ParentEdit,
render: ParentView,
enableSorting: true,
};

/**
* This field is used to display the post parent.
*/
export default parentField;
Loading

0 comments on commit e6bdfd5

Please sign in to comment.