diff --git a/packages/dataviews/src/normalize-fields.ts b/packages/dataviews/src/normalize-fields.ts index 0c1e81518c9b4..64c86bd4d0f80 100644 --- a/packages/dataviews/src/normalize-fields.ts +++ b/packages/dataviews/src/normalize-fields.ts @@ -64,6 +64,12 @@ export function normalizeFields< Item >( ); }; + let supportsBulk = true; + // If custom Edit component is passed in we default to false for bulk edit support. + if ( typeof field.Edit === 'function' || field.supportsBulk ) { + supportsBulk = field.supportsBulk ?? false; + } + const render = field.render || ( field.elements ? renderFromElements : getValue ); @@ -76,7 +82,7 @@ export function normalizeFields< Item >( sort, isValid, Edit, - supportsBulk: field.supportsBulk ?? false, + supportsBulk, enableHiding: field.enableHiding ?? true, enableSorting: field.enableSorting ?? true, }; diff --git a/packages/edit-site/src/components/post-edit/index.js b/packages/edit-site/src/components/post-edit/index.js index 8e3deb99a9570..4d03d3e41e9fe 100644 --- a/packages/edit-site/src/components/post-edit/index.js +++ b/packages/edit-site/src/components/post-edit/index.js @@ -22,13 +22,26 @@ import { unlock } from '../../lock-unlock'; const { PostCardPanel, usePostFields } = unlock( editorPrivateApis ); -const fieldsWithBulkEditSupport = [ - 'title', - 'status', - 'date', - 'author', - 'comment_status', -]; +const DATAFORM_CONFIG = { + type: 'panel', + fields: [ + { + id: 'featured_media', + layout: 'regular', + }, + 'title', + { + id: 'status', + label: __( 'Status & Visibility' ), + children: [ 'status', 'password' ], + }, + 'author', + 'date', + 'slug', + 'parent', + 'comment_status', + ], +}; function PostEditForm( { postType, postId } ) { const ids = useMemo( () => postId.split( ',' ), [ postId ] ); @@ -75,35 +88,6 @@ function PostEditForm( { postType, postId } ) { [ _fields ] ); - const form = useMemo( - () => ( { - type: 'panel', - fields: [ - { - id: 'featured_media', - layout: 'regular', - }, - 'title', - { - id: 'status', - label: __( 'Status & Visibility' ), - children: [ 'status', 'password' ], - }, - 'author', - 'date', - 'slug', - 'parent', - 'comment_status', - ].filter( - ( field ) => - ids.length === 1 || - fieldsWithBulkEditSupport.includes( - typeof field === 'string' ? field : field.id - ) - ), - } ), - [ ids ] - ); const onChange = ( edits ) => { for ( const id of ids ) { if ( @@ -133,7 +117,7 @@ function PostEditForm( { postType, postId } ) { diff --git a/packages/fields/src/fields/author/index.tsx b/packages/fields/src/fields/author/index.tsx index 08bfa3ca8d87b..22f9409e05155 100644 --- a/packages/fields/src/fields/author/index.tsx +++ b/packages/fields/src/fields/author/index.tsx @@ -15,7 +15,6 @@ const authorField: Field< BasePostWithEmbeddedAuthor > = { id: 'author', type: 'integer', elements: [], - supportsBulk: true, render: AuthorView, sort: ( a, b, direction ) => { const nameA = a._embedded?.author?.[ 0 ]?.name || ''; diff --git a/packages/fields/src/fields/date/index.tsx b/packages/fields/src/fields/date/index.tsx index c9e1d28a6dba9..49bd0807de669 100644 --- a/packages/fields/src/fields/date/index.tsx +++ b/packages/fields/src/fields/date/index.tsx @@ -15,7 +15,6 @@ const dateField: Field< BasePost > = { type: 'datetime', label: __( 'Date' ), render: DateView, - supportsBulk: true, }; /** diff --git a/packages/fields/src/fields/status/index.tsx b/packages/fields/src/fields/status/index.tsx index 26e3ad22b6e98..374277bc7260e 100644 --- a/packages/fields/src/fields/status/index.tsx +++ b/packages/fields/src/fields/status/index.tsx @@ -20,7 +20,6 @@ const statusField: Field< BasePost > = { elements: STATUSES, render: StatusView, Edit: 'radio', - supportsBulk: true, enableSorting: false, filterBy: { operators: [ OPERATOR_IS_ANY ], diff --git a/packages/fields/src/fields/title/index.ts b/packages/fields/src/fields/title/index.ts index 33414ce172ea9..d8e6f25276d6b 100644 --- a/packages/fields/src/fields/title/index.ts +++ b/packages/fields/src/fields/title/index.ts @@ -19,7 +19,6 @@ const titleField: Field< BasePost > = { getValue: ( { item } ) => getItemTitle( item ), render: TitleView, enableHiding: false, - supportsBulk: true, }; export default titleField;