Skip to content

Commit

Permalink
Change naming of bulkEditing to unique
Browse files Browse the repository at this point in the history
  • Loading branch information
louwie17 committed Dec 12, 2024
1 parent bb9b2a6 commit 6c629e6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
7 changes: 3 additions & 4 deletions packages/dataviews/src/dataforms-layouts/data-form-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} );
}

Expand Down Expand Up @@ -95,8 +95,7 @@ export function DataFormLayout< Item >( {
formField,
fieldDefinitions
) ) ||
( fieldDefinition &&
! fieldDefinition.supportsBulkEditing ) )
( fieldDefinition && fieldDefinition.unique ) )
) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/normalize-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
19 changes: 9 additions & 10 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type Field< Item > = {
*/
Edit?:
| ComponentType< DataFormControlProps< Item > >
| ComponentType< DataFormControlPropsWithoutBulkEditing< Item > >
| ComponentType< DataFormUniqueControlProps< Item > >
| string;

/**
Expand Down Expand Up @@ -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 > & {
Expand All @@ -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;
};

/**
Expand All @@ -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;
};
Expand Down Expand Up @@ -570,5 +570,4 @@ export interface FieldLayoutProps< Item > {
field: FormField;
onChange: ( value: any ) => void;
hideLabelFromVision?: boolean;
isBulkEditing?: boolean;
}
2 changes: 1 addition & 1 deletion packages/fields/src/fields/slug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const slugField: Field< BasePost > = {
label: __( 'Slug' ),
Edit: SlugEdit,
render: SlugView,
supportsBulkEditing: false,
unique: true,
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/fields/src/fields/slug/slug-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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 );
Expand Down

0 comments on commit 6c629e6

Please sign in to comment.