Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews: make field.type required #67127

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions packages/dataviews/src/components/dataviews/stories/fixtures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,23 @@ export const themeData: Theme[] = [
];

export const themeFields: Field< Theme >[] = [
{ id: 'slug', label: 'Slug' },
{ id: 'name', label: 'Name' },
{ id: 'slug', type: 'text', label: 'Slug' },
{ id: 'name', type: 'text', label: 'Name' },
{
id: 'description',
type: 'text',
label: 'Description',
render: ( { item } ) => (
<span className="theme-field-description">
{ item.description }
</span>
),
},
{ id: 'requires', label: 'Requires at least' },
{ id: 'tested', label: 'Tested up to' },
{ id: 'requires', type: 'text', label: 'Requires at least' },
{ id: 'tested', type: 'text', label: 'Tested up to' },
{
id: 'tags',
label: 'Tags',
type: 'text',
render: ( { item } ) => item.tags.join( ', ' ),
},
];
Expand Down Expand Up @@ -616,8 +617,9 @@ export const actions: Action< SpaceObject >[] = [

export const fields: Field< SpaceObject >[] = [
{
label: 'Image',
id: 'image',
type: 'text', // TODO: add media/image type
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that media is the only basic type missing. We already have a couple of cases in our codebase where this could be used (featured media, preview).

Currently, the type only provides sort, isValid and Edit functions, but nothing stops us from providing more (and we should). For example, type: media fields could provide enableSorting: false by default.

label: 'Image',
header: (
<HStack spacing={ 1 } justify="start">
<Icon icon={ image } />
Expand All @@ -632,8 +634,9 @@ export const fields: Field< SpaceObject >[] = [
enableSorting: false,
},
{
label: 'Title',
id: 'title',
type: 'text',
label: 'Title',
enableHiding: false,
enableGlobalSearch: true,
render: ( { item } ) => {
Expand All @@ -642,12 +645,13 @@ export const fields: Field< SpaceObject >[] = [
},
{
id: 'date',
label: 'Date',
type: 'datetime',
label: 'Date',
},
{
label: 'Type',
id: 'type',
type: 'text',
label: 'Type',
enableHiding: false,
elements: [
{ value: 'Not a planet', label: 'Not a planet' },
Expand All @@ -657,20 +661,22 @@ export const fields: Field< SpaceObject >[] = [
],
},
{
label: 'Satellites',
id: 'satellites',
type: 'integer',
label: 'Satellites',
enableSorting: true,
},
{
label: 'Description',
id: 'description',
type: 'text',
label: 'Description',
enableSorting: false,
enableGlobalSearch: true,
},
{
label: 'Categories',
id: 'categories',
type: 'text',
label: 'Categories',
header: (
<HStack spacing={ 1 } justify="start">
<Icon icon={ category } />
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export type Field< Item > = {
/**
* Type of the fields.
*/
type?: FieldType;
type: FieldType;

/**
* The unique identifier of the field.
Expand Down
12 changes: 8 additions & 4 deletions packages/edit-site/src/components/page-patterns/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ function PreviewField( { item } ) {
}

export const previewField = {
label: __( 'Preview' ),
id: 'preview',
type: 'text', // TODO: add media/image type
label: __( 'Preview' ),
render: PreviewField,
enableSorting: false,
};
Expand Down Expand Up @@ -155,8 +156,9 @@ function TitleField( { item } ) {
}

export const titleField = {
label: __( 'Title' ),
id: 'title',
type: 'text',
label: __( 'Title' ),
getValue: ( { item } ) => item.title?.raw || item.title,
render: TitleField,
enableHiding: false,
Expand All @@ -178,8 +180,9 @@ const SYNC_FILTERS = [
];

export const patternStatusField = {
label: __( 'Sync status' ),
id: 'sync-status',
type: 'text',
label: __( 'Sync status' ),
render: ( { item } ) => {
const syncStatus =
'wp_pattern_sync_status' in item
Expand Down Expand Up @@ -236,8 +239,9 @@ function AuthorField( { item } ) {
}

export const templatePartAuthorField = {
label: __( 'Author' ),
id: 'author',
type: 'text',
label: __( 'Author' ),
getValue: ( { item } ) => item.author_text,
render: AuthorField,
filterBy: {
Expand Down
12 changes: 8 additions & 4 deletions packages/edit-site/src/components/page-templates/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ function PreviewField( { item } ) {
}

export const previewField = {
label: __( 'Preview' ),
id: 'preview',
type: 'text', // TODO: add media/image type
label: __( 'Preview' ),
render: PreviewField,
enableSorting: false,
};
Expand All @@ -95,17 +96,19 @@ function TitleField( { item } ) {
}

export const titleField = {
label: __( 'Template' ),
id: 'title',
type: 'text',
label: __( 'Template' ),
getValue: ( { item } ) => item.title?.rendered,
render: TitleField,
enableHiding: false,
enableGlobalSearch: true,
};

export const descriptionField = {
label: __( 'Description' ),
id: 'description',
type: 'text',
label: __( 'Description' ),
render: ( { item } ) => {
return (
item.description && (
Expand Down Expand Up @@ -149,8 +152,9 @@ function AuthorField( { item } ) {
}

export const authorField = {
label: __( 'Author' ),
id: 'author',
type: 'text',
label: __( 'Author' ),
getValue: ( { item } ) => item.author_text,
render: AuthorField,
};
Loading