Morph many to one picker (#14155)

This PR follows the multiSelect PR merged previously. It will enable
morph relation Many to One to be handled from the table, using a
singleSelect picker

Main point : I decided to change the singleSelect API to take an array
of **objectMetadataName** instead of only one to deal with both our
usecases.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Guillim
2025-10-07 17:25:11 +02:00
committed by GitHub
parent 9f9c2d85ca
commit f60817a1e1
138 changed files with 2116 additions and 1763 deletions
@@ -0,0 +1,34 @@
import { CustomError } from '@/utils/errors';
import { capitalize } from '@/utils/strings';
enum RelationType {
MANY_TO_ONE = 'MANY_TO_ONE',
ONE_TO_MANY = 'ONE_TO_MANY',
}
type ComputeMorphRelationFieldNameArgs = {
fieldName: string;
relationType: RelationType;
targetObjectMetadataNameSingular: string;
targetObjectMetadataNamePlural: string;
};
export const computeMorphRelationFieldName = ({
fieldName,
relationType,
targetObjectMetadataNameSingular: nameSingular,
targetObjectMetadataNamePlural: namePlural,
}: ComputeMorphRelationFieldNameArgs): string => {
if (relationType === RelationType.MANY_TO_ONE) {
return `${fieldName}${capitalize(nameSingular)}`;
}
if (relationType === RelationType.ONE_TO_MANY) {
return `${fieldName}${capitalize(namePlural)}`;
}
throw new CustomError(
`Invalid relation type (${relationType}) for field ${fieldName} on ${nameSingular}`,
'INVALID_RELATION_TYPE_FOR_COMPUTE_MORPH_RELATION_FIELD_NAME',
);
};