Skip to content

Commit

Permalink
Default bulk support to true, unless custom Edit is used
Browse files Browse the repository at this point in the history
  • Loading branch information
louwie17 committed Nov 27, 2024
1 parent 9680521 commit 7fb76cf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 42 deletions.
8 changes: 7 additions & 1 deletion packages/dataviews/src/normalize-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -76,7 +82,7 @@ export function normalizeFields< Item >(
sort,
isValid,
Edit,
supportsBulk: field.supportsBulk ?? false,
supportsBulk,
enableHiding: field.enableHiding ?? true,
enableSorting: field.enableSorting ?? true,
};
Expand Down
58 changes: 21 additions & 37 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -133,7 +117,7 @@ function PostEditForm( { postType, postId } ) {
<DataForm
data={ ids.length === 1 ? record : records }
fields={ fields }
form={ form }
form={ DATAFORM_CONFIG }
onChange={ onChange }
/>
</VStack>
Expand Down
1 change: 0 additions & 1 deletion packages/fields/src/fields/author/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand Down
1 change: 0 additions & 1 deletion packages/fields/src/fields/date/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const dateField: Field< BasePost > = {
type: 'datetime',
label: __( 'Date' ),
render: DateView,
supportsBulk: true,
};

/**
Expand Down
1 change: 0 additions & 1 deletion packages/fields/src/fields/status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const statusField: Field< BasePost > = {
elements: STATUSES,
render: StatusView,
Edit: 'radio',
supportsBulk: true,
enableSorting: false,
filterBy: {
operators: [ OPERATOR_IS_ANY ],
Expand Down
1 change: 0 additions & 1 deletion packages/fields/src/fields/title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const titleField: Field< BasePost > = {
getValue: ( { item } ) => getItemTitle( item ),
render: TitleView,
enableHiding: false,
supportsBulk: true,
};

export default titleField;

0 comments on commit 7fb76cf

Please sign in to comment.