Open ijreilly opened 2 weeks ago
To add the 'create new entry' functionality to the 'from many' relation pickers, follow these steps:
/packages/twenty-front/src/modules/object-record/relation-picker/components/MultipleObjectRecordSelect.tsx
:import { useAddNewRecordAndOpenRightDrawer } from '@/object-record/relation-picker/hooks/useAddNewRecordAndOpenRightDrawer';
import { IconForbid } from 'twenty-ui';
MultipleObjectRecordSelect
component:const { createNewRecordAndOpenRightDrawer } = useAddNewRecordAndOpenRightDrawer({
relationObjectMetadataNameSingular: fieldDefinition.metadata.relationObjectMetadataNameSingular,
relationObjectMetadataItem,
relationFieldMetadataItem,
entityId,
});
<SingleEntitySelect
EmptyIcon={IconForbid}
emptyLabel={'No ' + fieldDefinition.label}
onCancel={onCancel}
onCreate={createNewRecordAndOpenRightDrawer}
onEntitySelected={handleEntitySelected}
width={width}
relationObjectNameSingular={fieldDefinition.metadata.relationObjectMetadataNameSingular}
relationPickerScopeId={relationPickerScopeId}
selectedRelationRecordIds={recordId ? [recordId] : []}
excludedRelationRecordIds={excludeRecordIds}
/>
This will enable the 'create new entry' functionality in the 'from many' relation pickers similar to the 'to one' relation pickers.
/packages/twenty-front/src/modules/object-record/relation-picker/components/RelationPicker.tsx /packages/twenty-front/src/modules/object-record/relation-picker/components/MultipleObjectRecordSelect.tsx /packages/twenty-front/src/modules/object-record/relation-picker/hooks/useAddNewRecordAndOpenRightDrawer.ts /packages/twenty-front/src/modules/object-record/relation-picker/hooks/useRelationPicker.ts /packages/twenty-front/src/modules/object-record/relation-picker/components /packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationSection.tsx /packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/RelationManyFieldInput.tsx
The below behaviour is available on the "to one" relation picker:![Image](https://github.com/twentyhq/twenty/assets/51697796/e12941cf-8ef3-4cf1-ad5a-9ecc5b4c28d2)
Let's add the same behaviour on the recently introduced "from many" relation pickers!