chore: improve custom server cell types (#9188)

### What?
Exposes DefaultServerCellComponentProps type for custom server cell
components.

### Why?
So users can type their custom server cell components properly.
This commit is contained in:
Jarrod Flesch
2024-11-13 17:03:03 -05:00
committed by GitHub
parent 4509c38f4c
commit 81099cbb04
3 changed files with 27 additions and 13 deletions

View File

@@ -1,6 +1,10 @@
import type { I18nClient } from '@payloadcms/translations'
import type { ClientCollectionConfig } from '../../collections/config/client.js'
import type { SanitizedCollectionConfig } from '../../collections/config/types.js'
import type { ClientField } from '../../fields/config/client.js'
import type { Field } from '../../fields/config/types.js'
import type { Payload } from '../../types/index.js'
export type RowData = Record<string, any>
@@ -19,3 +23,12 @@ export type DefaultCellComponentProps<TCellData = any, TField extends ClientFiel
}) => void
readonly rowData: RowData
}
export type DefaultServerCellComponentProps<
TCellData = any,
TField extends ClientField = ClientField,
> = {
field: Field
i18n: I18nClient
payload: Payload
} & Omit<DefaultCellComponentProps<TCellData, TField>, 'field'>

View File

@@ -16,7 +16,7 @@ import type {
Row,
} from './forms/Form.js'
export type { DefaultCellComponentProps } from './elements/Cell.js'
export type { DefaultCellComponentProps, DefaultServerCellComponentProps } from './elements/Cell.js'
export type { ConditionalDateProps } from './elements/DatePicker.js'
export type { DayPickerProps, SharedProps, TimePickerProps } from './elements/DatePicker.js'
export type { NavGroupPreferences, NavPreferences } from './elements/Nav.js'

View File

@@ -1,16 +1,17 @@
import type { I18nClient } from '@payloadcms/translations'
import {
type ClientCollectionConfig,
type DefaultCellComponentProps,
type Field,
MissingEditorProp,
type PaginatedDocs,
type Payload,
type PayloadComponent,
type SanitizedCollectionConfig,
type StaticLabel,
import type {
ClientCollectionConfig,
DefaultCellComponentProps,
DefaultServerCellComponentProps,
Field,
PaginatedDocs,
Payload,
PayloadComponent,
SanitizedCollectionConfig,
StaticLabel,
} from 'payload'
import { MissingEditorProp } from 'payload'
import { deepCopyObjectSimple, fieldIsPresentationalOnly } from 'payload/shared'
import React from 'react'
@@ -177,7 +178,7 @@ export const buildColumnState = (args: Args): Column[] => {
rowData: undefined,
}
const serverProps = {
const serverProps: Pick<DefaultServerCellComponentProps, 'field' | 'i18n' | 'payload'> = {
field: _field,
i18n,
payload,