Skip to content

Commit

Permalink
Add WithBulkEditing type
Browse files Browse the repository at this point in the history
  • Loading branch information
louwie17 committed Dec 10, 2024
1 parent 90dc201 commit 9ff0ba0
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/dataviews/src/dataform-controls/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';
import type { DataFormControlProps, WithBulkEditing } from '../types';

export default function DateTime< Item >( {
field,
onChange,
hideLabelFromVision,
value,
}: DataFormControlProps< Item > ) {
}: DataFormControlProps< Item > & WithBulkEditing< Item > ) {
const { id, label } = field;

const onChangeControl = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions packages/dataviews/src/dataform-controls/integer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';
import type { DataFormControlProps, WithBulkEditing } from '../types';

export default function Integer< Item >( {
field,
onChange,
hideLabelFromVision,
value,
}: DataFormControlProps< Item > ) {
}: DataFormControlProps< Item > & WithBulkEditing< Item > ) {
const { id, label, description } = field;
const onChangeControl = useCallback(
( newValue: string | undefined ) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/dataviews/src/dataform-controls/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';
import type { DataFormControlProps, WithBulkEditing } from '../types';

export default function Radio< Item >( {
field,
onChange,
hideLabelFromVision,
value,
}: DataFormControlProps< Item > ) {
}: DataFormControlProps< Item > & WithBulkEditing< Item > ) {
const { id, label } = field;

const onChangeControl = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions packages/dataviews/src/dataform-controls/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';
import type { DataFormControlProps, WithBulkEditing } from '../types';

export default function Select< Item >( {
field,
onChange,
hideLabelFromVision,
value,
}: DataFormControlProps< Item > ) {
}: DataFormControlProps< Item > & WithBulkEditing< Item > ) {
const { id, label } = field;
const onChangeControl = useCallback(
( newValue: any ) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/dataviews/src/dataform-controls/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';
import type { DataFormControlProps, WithBulkEditing } from '../types';

export default function Text< Item >( {
field,
onChange,
hideLabelFromVision,
value,
}: DataFormControlProps< Item > ) {
}: DataFormControlProps< Item > & WithBulkEditing< Item > ) {
const { id, label, placeholder } = field;

const onChangeControl = useCallback(
Expand Down
17 changes: 8 additions & 9 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type FieldTypeDefinition< Item > = {
/**
* A dataview field for a specific property of a data type.
*/
export type Field< Item, SupportsBulkEditing extends boolean = true > = {
export type Field< Item > = {
/**
* Type of the fields.
*/
Expand Down Expand Up @@ -111,9 +111,7 @@ export type Field< Item, SupportsBulkEditing extends boolean = true > = {
/**
* Callback used to render an edit control for the field.
*/
Edit?:
| ComponentType< DataFormControlProps< Item, SupportsBulkEditing > >
| string;
Edit?: ComponentType< DataFormControlProps< Item > > | string;

/**
* Callback used to sort the field.
Expand Down Expand Up @@ -186,17 +184,18 @@ export type Fields< Item > = Field< Item >[];

export type Data< Item > = Item[];

export type DataFormControlProps<
Item,
SupportsBulkEditing extends boolean = true,
> = {
data: SupportsBulkEditing extends true ? Item | Item[] : Item;
export type DataFormControlProps< Item > = {
data: Item;
field: NormalizedField< Item >;
onChange: ( value: Record< string, any > ) => void;
hideLabelFromVision?: boolean;
value: any;
};

export type WithBulkEditing< Item > = {
data: Item | Item[];
};

export type DataViewRenderFieldProps< Item > = {
item: Item;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/parent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { BasePost } from '../../types';
import { ParentEdit } from './parent-edit';
import { ParentView } from './parent-view';

const parentField: Field< BasePost, false > = {
const parentField: Field< BasePost > = {
id: 'parent',
type: 'text',
label: __( 'Parent' ),
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/parent/parent-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export const ParentEdit = ( {
data,
field,
onChange,
}: DataFormControlProps< BasePost, false > ) => {
}: DataFormControlProps< BasePost > ) => {
const { id } = field;

const homeUrl = useSelect( ( select ) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/fields/src/fields/password/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
__experimentalVStack as VStack,
TextControl,
} from '@wordpress/components';
import type { DataFormControlProps } from '@wordpress/dataviews';
import type {
DataFormControlProps,
WithBulkEditing,
} from '@wordpress/dataviews';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

Expand All @@ -15,7 +18,10 @@ import { __ } from '@wordpress/i18n';
*/
import type { BasePost } from '../../types';

function PasswordEdit( { onChange, value }: DataFormControlProps< BasePost > ) {
function PasswordEdit( {
onChange,
value,
}: DataFormControlProps< BasePost > & WithBulkEditing< BasePost > ) {
const [ showPassword, setShowPassword ] = useState( !! value );

const handleTogglePassword = ( newValue: boolean ) => {
Expand Down
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 @@ -11,7 +11,7 @@ import type { BasePost } from '../../types';
import SlugEdit from './slug-edit';
import SlugView from './slug-view';

const slugField: Field< BasePost, false > = {
const slugField: Field< BasePost > = {
id: 'slug',
type: 'text',
label: __( 'Slug' ),
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/slug/slug-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SlugEdit = ( {
field,
onChange,
data,
}: DataFormControlProps< BasePost, false > ) => {
}: DataFormControlProps< BasePost > ) => {
const { id } = field;

const slug = field.getValue( { item: data } ) || getSlug( data );
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { __ } from '@wordpress/i18n';
import type { BasePost } from '../../types';
import { TemplateEdit } from './template-edit';

const templateField: Field< BasePost, false > = {
const templateField: Field< BasePost > = {
id: 'template',
type: 'text',
label: __( 'Template' ),
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/template/template-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const TemplateEdit = ( {
data,
field,
onChange,
}: DataFormControlProps< BasePost, false > ) => {
}: DataFormControlProps< BasePost > ) => {
const { id } = field;
const postType = data.type;
const postId =
Expand Down

0 comments on commit 9ff0ba0

Please sign in to comment.