diff --git a/packages/payload/src/admin/elements/Cell.ts b/packages/payload/src/admin/elements/Cell.ts index bc181361d..7b124c38c 100644 --- a/packages/payload/src/admin/elements/Cell.ts +++ b/packages/payload/src/admin/elements/Cell.ts @@ -1,6 +1,5 @@ import type { I18nClient } from '@payloadcms/translations' -import type { ClientCollectionConfig } from '../../collections/config/client.js' import type { SanitizedCollectionConfig } from '../../collections/config/types.js' import type { ArrayFieldClient, @@ -71,24 +70,25 @@ export type DefaultCellComponentProps< ? { x: number; y: number } : any : TCellData - readonly className?: string - readonly collectionConfig: ClientCollectionConfig - readonly columnIndex?: number - readonly customCellProps?: Record - readonly field: TField - readonly link?: boolean - readonly onClick?: (args: { + className?: string + collectionSlug: SanitizedCollectionConfig['slug'] + columnIndex?: number + customCellProps?: Record + field: TField + link?: boolean + onClick?: (args: { cellData: unknown collectionSlug: SanitizedCollectionConfig['slug'] rowData: RowData }) => void - readonly rowData: RowData + rowData: RowData } export type DefaultServerCellComponentProps< TField extends ClientField = ClientField, TCellData = any, > = { + collectionConfig: SanitizedCollectionConfig field: Field i18n: I18nClient payload: Payload diff --git a/packages/richtext-lexical/src/types.ts b/packages/richtext-lexical/src/types.ts index e859d389b..1775e1811 100644 --- a/packages/richtext-lexical/src/types.ts +++ b/packages/richtext-lexical/src/types.ts @@ -1,7 +1,7 @@ import type { EditorConfig as LexicalEditorConfig, SerializedEditorState } from 'lexical' import type { ClientField, - DefaultCellComponentProps, + DefaultServerCellComponentProps, LabelFunction, RichTextAdapter, RichTextFieldClient, @@ -116,7 +116,7 @@ export type LexicalRichTextFieldProps = { } & Pick & RichTextFieldClientProps -export type LexicalRichTextCellProps = DefaultCellComponentProps< +export type LexicalRichTextCellProps = DefaultServerCellComponentProps< RichTextFieldClient, SerializedEditorState > diff --git a/packages/richtext-slate/src/cell/rscEntry.tsx b/packages/richtext-slate/src/cell/rscEntry.tsx index 0d31a8349..26e52614d 100644 --- a/packages/richtext-slate/src/cell/rscEntry.tsx +++ b/packages/richtext-slate/src/cell/rscEntry.tsx @@ -1,4 +1,4 @@ -import type { DefaultCellComponentProps, Payload } from 'payload' +import type { DefaultServerCellComponentProps, Payload } from 'payload' import { getTranslation, type I18nClient } from '@payloadcms/translations' import { formatAdminURL } from '@payloadcms/ui/shared' @@ -11,7 +11,7 @@ export const RscEntrySlateCell: React.FC< { i18n: I18nClient payload: Payload - } & DefaultCellComponentProps + } & DefaultServerCellComponentProps > = (props) => { const { cellData, diff --git a/packages/ui/src/elements/RelationshipTable/cells/DrawerLink/index.tsx b/packages/ui/src/elements/RelationshipTable/cells/DrawerLink/index.tsx index 6b4914b66..8219f994c 100644 --- a/packages/ui/src/elements/RelationshipTable/cells/DrawerLink/index.tsx +++ b/packages/ui/src/elements/RelationshipTable/cells/DrawerLink/index.tsx @@ -20,7 +20,7 @@ export const DrawerLink: React.FC<{ const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({ id: cellProps?.rowData.id, - collectionSlug: cellProps?.collectionConfig.slug, + collectionSlug: cellProps?.collectionSlug, }) const onDrawerSave = useCallback( diff --git a/packages/ui/src/elements/Table/DefaultCell/fields/Code/index.tsx b/packages/ui/src/elements/Table/DefaultCell/fields/Code/index.tsx index 9804bea57..4165439a4 100644 --- a/packages/ui/src/elements/Table/DefaultCell/fields/Code/index.tsx +++ b/packages/ui/src/elements/Table/DefaultCell/fields/Code/index.tsx @@ -1,11 +1,12 @@ 'use client' -import type { CodeFieldClient, DefaultCellComponentProps } from 'payload' +import type { ClientCollectionConfig, CodeFieldClient, DefaultCellComponentProps } from 'payload' import React from 'react' import './index.scss' export interface CodeCellProps extends DefaultCellComponentProps { + readonly collectionConfig: ClientCollectionConfig readonly nowrap?: boolean } diff --git a/packages/ui/src/elements/Table/DefaultCell/fields/File/index.tsx b/packages/ui/src/elements/Table/DefaultCell/fields/File/index.tsx index e2bfbb353..e95585951 100644 --- a/packages/ui/src/elements/Table/DefaultCell/fields/File/index.tsx +++ b/packages/ui/src/elements/Table/DefaultCell/fields/File/index.tsx @@ -1,5 +1,10 @@ 'use client' -import type { DefaultCellComponentProps, TextFieldClient, UploadFieldClient } from 'payload' +import type { + ClientCollectionConfig, + DefaultCellComponentProps, + TextFieldClient, + UploadFieldClient, +} from 'payload' import React from 'react' @@ -9,7 +14,9 @@ import './index.scss' const baseClass = 'file' export interface FileCellProps - extends DefaultCellComponentProps {} + extends DefaultCellComponentProps { + readonly collectionConfig: ClientCollectionConfig +} export const FileCell: React.FC = ({ cellData: filename, diff --git a/packages/ui/src/elements/Table/DefaultCell/fields/Relationship/index.tsx b/packages/ui/src/elements/Table/DefaultCell/fields/Relationship/index.tsx index 1bb5ab778..36efaa975 100644 --- a/packages/ui/src/elements/Table/DefaultCell/fields/Relationship/index.tsx +++ b/packages/ui/src/elements/Table/DefaultCell/fields/Relationship/index.tsx @@ -119,6 +119,7 @@ export const RelationshipCell: React.FC = ({ = (props) => { const { cellData, className: classNameFromProps, - collectionConfig, + collectionSlug, field, field: { admin }, link, @@ -31,8 +31,11 @@ export const DefaultCell: React.FC = (props) => { config: { routes: { admin: adminRoute }, }, + getEntityConfig, } = useConfig() + const collectionConfig = getEntityConfig({ collectionSlug }) as ClientCollectionConfig + const classNameFromConfigContext = admin && 'className' in admin ? admin.className : undefined const className = @@ -83,6 +86,7 @@ export const DefaultCell: React.FC = (props) => { { field, } - const serverProps: Pick< + const customLabelServerProps: Pick< ServerComponentProps, 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload' > = { @@ -187,7 +186,7 @@ export const buildColumnState = (args: Args): Column[] => { clientProps, Component: CustomLabelToRender, importMap: payload.importMap, - serverProps, + serverProps: customLabelServerProps, }) : undefined @@ -208,7 +207,7 @@ export const buildColumnState = (args: Args): Column[] => { const baseCellClientProps: DefaultCellComponentProps = { cellData: undefined, - collectionConfig: deepCopyObjectSimple(clientCollectionConfig), + collectionSlug: clientCollectionConfig.slug, customCellProps, field, rowData: undefined, @@ -231,6 +230,21 @@ export const buildColumnState = (args: Args): Column[] => { rowData: doc, } + const cellServerProps: DefaultServerCellComponentProps = { + cellData: cellClientProps.cellData, + className: baseCellClientProps.className, + collectionConfig, + collectionSlug: collectionConfig.slug, + columnIndex: baseCellClientProps.columnIndex, + customCellProps: baseCellClientProps.customCellProps, + field: _field, + i18n, + link: cellClientProps.link, + onClick: baseCellClientProps.onClick, + payload, + rowData: doc, + } + let CustomCell = null if (_field?.type === 'richText') { @@ -254,21 +268,21 @@ export const buildColumnState = (args: Args): Column[] => { clientProps: cellClientProps, Component: _field.editor.CellComponent, importMap: payload.importMap, - serverProps, + serverProps: cellServerProps, }) } else { - CustomCell = - _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell - ? RenderServerComponent({ - clientProps: cellClientProps, - Component: - _field?.admin && - 'components' in _field.admin && - _field.admin.components?.Cell, - importMap: payload.importMap, - serverProps, - }) - : undefined + const CustomCellComponent = _field?.admin?.components?.Cell + + if (CustomCellComponent) { + CustomCell = RenderServerComponent({ + clientProps: cellClientProps, + Component: CustomCellComponent, + importMap: payload.importMap, + serverProps: cellServerProps, + }) + } else { + CustomCell = undefined + } } return (