import type { ControlTypes, FinalAttributeRecord, PartialSchema, } from "@hatchifyjs/core" import type { FinalSchemas, GetSchemaNames, Record, } from "@hatchifyjs/rest-client" import type { DefaultDisplayComponentsTypes } from "../../../components/index.js" export function getDefaultDataRender< const TSchemas extends globalThis.Record, const TSchemaName extends GetSchemaNames, >({ finalSchemas, schemaName, control, field, isRelationship, isAdditional, defaultDisplayComponents, }: { finalSchemas: FinalSchemas schemaName: TSchemaName control: FinalAttributeRecord[string]["control"] field: string isRelationship: boolean isAdditional: boolean defaultDisplayComponents: DefaultDisplayComponentsTypes }): ({ record }: { record: Record }) => React.ReactNode { const type: ControlTypes = control?.type || null const { String, Number, Boolean, Relationship, RelationshipList, Date } = defaultDisplayComponents const defaultRender = ({ record }: { record: Record }) => { const value = record[field] if (isRelationship && value) { value.label = value?.__label || value?.id return Array.isArray(value) ? ( ) : ( ) } if (isAdditional || value == null || !type) { return } if (type === "Dateonly" || type === "Date") { return } if (type === "enum") { return } if (type === "String") { const { maxDisplayLength } = control?.ui || {} const maxDisplayLengthExceeded = maxDisplayLength && value.length > maxDisplayLength if (!maxDisplayLengthExceeded) { return } const truncatedValue = `${value.substr(0, maxDisplayLength)}\u2026` return ( ) } if (type === "Boolean") { return } if (type === "Number") { return } // fallback return } return defaultRender }