diff --git a/packages/dataviews/src/dataforms-layouts/data-form-layout.tsx b/packages/dataviews/src/dataforms-layouts/data-form-layout.tsx index f11b430805390..ac70becf5c5dc 100644 --- a/packages/dataviews/src/dataforms-layouts/data-form-layout.tsx +++ b/packages/dataviews/src/dataforms-layouts/data-form-layout.tsx @@ -26,9 +26,9 @@ function doesCombinedFieldSupportBulkEdits< Item >( return combinedField.children.some( ( child ) => { const fieldId = typeof child === 'string' ? child : child.id; - return fieldDefinitions.find( + return ! fieldDefinitions.find( ( fieldDefinition ) => fieldDefinition.id === fieldId - )?.supportsBulkEditing; + )?.unique; } ); } @@ -95,8 +95,7 @@ export function DataFormLayout< Item >( { formField, fieldDefinitions ) ) || - ( fieldDefinition && - ! fieldDefinition.supportsBulkEditing ) ) + ( fieldDefinition && fieldDefinition.unique ) ) ) { return null; } diff --git a/packages/dataviews/src/normalize-fields.ts b/packages/dataviews/src/normalize-fields.ts index cac965390a218..c9f0f7ea8ba83 100644 --- a/packages/dataviews/src/normalize-fields.ts +++ b/packages/dataviews/src/normalize-fields.ts @@ -76,7 +76,7 @@ export function normalizeFields< Item >( sort, isValid, Edit, - supportsBulkEditing: field.supportsBulkEditing ?? true, + unique: field.unique ?? false, enableHiding: field.enableHiding ?? true, enableSorting: field.enableSorting ?? true, }; diff --git a/packages/dataviews/src/types.ts b/packages/dataviews/src/types.ts index 358bf49d4cb7e..780fe71dc7c30 100644 --- a/packages/dataviews/src/types.ts +++ b/packages/dataviews/src/types.ts @@ -113,7 +113,7 @@ export type Field< Item > = { */ Edit?: | ComponentType< DataFormControlProps< Item > > - | ComponentType< DataFormControlPropsWithoutBulkEditing< Item > > + | ComponentType< DataFormUniqueControlProps< Item > > | string; /** @@ -163,9 +163,9 @@ export type Field< Item > = { getValue?: ( args: { item: Item } ) => any; /** - * Whether the field supports bulk editing. + * Whether the field supports editing multiple items. */ - supportsBulkEditing?: boolean; + unique?: boolean; }; export type NormalizedField< Item > = Field< Item > & { @@ -175,12 +175,12 @@ export type NormalizedField< Item > = Field< Item > & { render: ComponentType< DataViewRenderFieldProps< Item > >; Edit: | ComponentType< DataFormControlProps< Item > > - | ComponentType< DataFormControlPropsWithoutBulkEditing< Item > >; + | ComponentType< DataFormUniqueControlProps< Item > >; sort: ( a: Item, b: Item, direction: SortDirection ) => number; isValid: ( item: Item, context?: ValidationContext ) => boolean; enableHiding: boolean; enableSorting: boolean; - supportsBulkEditing: boolean; + unique: boolean; }; /** @@ -198,10 +198,10 @@ export type DataFormControlProps< Item, ValueType = any > = { value?: ValueType | symbol; }; -export type DataFormControlPropsWithoutBulkEditing< - Item, - ValueType = any, -> = Omit< DataFormControlProps< Item, ValueType >, 'data' | 'value' > & { +export type DataFormUniqueControlProps< Item, ValueType = any > = Omit< + DataFormControlProps< Item, ValueType >, + 'data' | 'value' +> & { data: Item; value?: ValueType; }; @@ -570,5 +570,4 @@ export interface FieldLayoutProps< Item > { field: FormField; onChange: ( value: any ) => void; hideLabelFromVision?: boolean; - isBulkEditing?: boolean; } diff --git a/packages/fields/src/fields/slug/index.ts b/packages/fields/src/fields/slug/index.ts index 3ac2dc14e306b..e457578971ef9 100644 --- a/packages/fields/src/fields/slug/index.ts +++ b/packages/fields/src/fields/slug/index.ts @@ -17,7 +17,7 @@ const slugField: Field< BasePost > = { label: __( 'Slug' ), Edit: SlugEdit, render: SlugView, - supportsBulkEditing: false, + unique: true, }; /** diff --git a/packages/fields/src/fields/slug/slug-edit.tsx b/packages/fields/src/fields/slug/slug-edit.tsx index 3b23d086cb223..e206a83b49adf 100644 --- a/packages/fields/src/fields/slug/slug-edit.tsx +++ b/packages/fields/src/fields/slug/slug-edit.tsx @@ -14,7 +14,7 @@ import { useDispatch } from '@wordpress/data'; import { useCallback, useEffect, useRef } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; import { safeDecodeURIComponent } from '@wordpress/url'; -import type { DataFormControlPropsWithoutBulkEditing } from '@wordpress/dataviews'; +import type { DataFormUniqueControlProps } from '@wordpress/dataviews'; import { __ } from '@wordpress/i18n'; /** @@ -27,7 +27,7 @@ const SlugEdit = ( { field, onChange, data, -}: DataFormControlPropsWithoutBulkEditing< BasePost > ) => { +}: DataFormUniqueControlProps< BasePost, string > ) => { const { id } = field; const slug = field.getValue( { item: data } ) || getSlug( data );