feat: add Relation field form (#2572)
* feat: add useCreateOneRelationMetadata and useRelationMetadata Closes #2423 * feat: add Relation field form Closes #2003 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings';
|
||||
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
|
||||
|
||||
export const useRelationFieldPreview = ({
|
||||
relationObjectMetadataId,
|
||||
skipDefaultValue,
|
||||
}: {
|
||||
relationObjectMetadataId?: string;
|
||||
skipDefaultValue: boolean;
|
||||
}) => {
|
||||
const { findObjectMetadataItemById } = useObjectMetadataItemForSettings();
|
||||
|
||||
const relationObjectMetadataItem = relationObjectMetadataId
|
||||
? findObjectMetadataItemById(relationObjectMetadataId)
|
||||
: undefined;
|
||||
|
||||
const { objects: relationObjects } = useFindManyObjectRecords({
|
||||
objectNamePlural: relationObjectMetadataItem?.namePlural,
|
||||
skip: skipDefaultValue || !relationObjectMetadataItem,
|
||||
});
|
||||
|
||||
return {
|
||||
defaultValue: relationObjects?.[0],
|
||||
entityChipDisplayMapper: (fieldValue?: { id: string }) => ({
|
||||
name: fieldValue?.id || relationObjectMetadataItem?.labelSingular || '',
|
||||
avatarType: 'squared' as const,
|
||||
}),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user