'use client' import { useConfig, useTranslation } from '@payloadcms/ui' import React from 'react' import { getRelationshipGroupKey } from './getRelationshipGroupKey.js' import { getRelationshipGroups } from './getRelationshipGroups.js' import './index.css' const baseClass = 'import-preview-relationship' type Props = { fieldPath: string /** `field.relationTo` — an array when the field is polymorphic. */ relationTo: string | string[] value: unknown } /** * Renders a relationship or upload value for the import preview table, stacking * one row per target collection. */ export const RelationshipCell: React.FC = ({ fieldPath, relationTo, value }) => { const { config } = useConfig() const { i18n } = useTranslation() const groups = getRelationshipGroups({ collections: config.collections, dateFormat: config.admin.dateFormat, i18n, relationTo, value, }) // The column heading already names a monomorphic field, whose collection never varies. const shouldShowCollectionLabels = Array.isArray(relationTo) if (!groups.length) { return null } return (
{groups.map(({ slug, label, options, remaining }) => (
{/* A `label` element would be unassociated here — the cell holds no control */} {shouldShowCollectionLabels && label && ( {label} )}
{options.join(', ')} {remaining > 0 && ( {i18n.t('fields:itemsAndMore', { count: remaining, items: '' }).trim()} )}
))}
) }