Skip to content

Commit

Permalink
DataViews: abandon the ItemRecord type (#64367)
Browse files Browse the repository at this point in the history
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored and getdave committed Aug 14, 2024
1 parent 54bd52e commit 1a82e7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
6 changes: 2 additions & 4 deletions packages/dataviews/src/normalize-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import getFieldTypeDefinition from './field-types';
import type { Field, NormalizedField, ItemRecord } from './types';
import type { Field, NormalizedField } from './types';

/**
* Apply default values and normalize the fields config.
Expand All @@ -17,9 +17,7 @@ export function normalizeFields< Item >(
const fieldTypeDefinition = getFieldTypeDefinition( field.type );

const getValue =
field.getValue ||
// @ts-ignore
( ( { item }: { item: ItemRecord } ) => item[ field.id ] );
field.getValue || ( ( { item } ) => ( item as any )[ field.id ] );

const sort =
field.sort ??
Expand Down
24 changes: 7 additions & 17 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export type Operator =
| 'isAll'
| 'isNotAll';

export type ItemRecord = Object;

export type FieldType = 'text' | 'integer';

export type ValidationContext = {
Expand Down Expand Up @@ -128,21 +126,13 @@ export type Field< Item > = {
* Filter config for the field.
*/
filterBy?: FilterByConfig | undefined;
} & ( Item extends ItemRecord
? {
/**
* Callback used to retrieve the value of the field from the item.
* Defaults to `item[ field.id ]`.
*/
getValue?: ( args: { item: Item } ) => any;
}
: {
/**
* Callback used to retrieve the value of the field from the item.
* Defaults to `item[ field.id ]`.
*/
getValue: ( args: { item: Item } ) => any;
} );

/**
* Callback used to retrieve the value of the field from the item.
* Defaults to `item[ field.id ]`.
*/
getValue?: ( args: { item: Item } ) => any;
};

export type NormalizedField< Item > = Field< Item > & {
label: string;
Expand Down

0 comments on commit 1a82e7a

Please sign in to comment.