import { CellValue, ColumnType, ITypeOptions } from '../../types'; export const transformCellValueToReferenceArray = < OT extends ColumnType = ColumnType >({ originCellValue, originTypeOptions, targetTypeOptions, }: { originCellValue: CellValue; originTypeOptions: ITypeOptions; targetTypeOptions: Pick< ITypeOptions, 'foreignTableId' >; }) => { if ( originTypeOptions.type === ColumnType.RECORD_REFERENCE && targetTypeOptions.foreignTableId === (originTypeOptions as ITypeOptions) .foreignTableId ) { return originCellValue as CellValue; } // here, we _could_ convert the originCellValue into an array of strings and // then make a "stub" record reference for each one with the string value as // its visible name and no id. This would be cool because it makes // transforming to REC_REF appear optimistic, however there's a big problem - // we don't necessarily know what the primary column of the foreign table is. // If it's a DATETIME column, we can't create foreign rows with any old name, // they have to be valid date strings. If it's a FORMULA column, we can't // create foreign rows at all! // Until such a time as we have a reasonable way to validate the optimistic // reference against the foreign primary column, we will return null instead // and allow this to be a "persistent-only" operation. return null; };