-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix RelationToOneSection assignment bug #14975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR fixes a critical bug in the RelationToOneSection assignment functionality that was introduced during a previous refactoring of SingleRecordPicker to support morph use cases. The bug occurred in the `RecordDetailRelationSectionDropdownToOne` component where the `onSubmit` callback was receiving an incorrect data structure.The issue was that the persistence layer expects a FieldRelationToOneValue
which should be an ObjectRecord
with an id
property (or null), but the code was passing just the recordId
string directly. This mismatch caused the relation assignment to fail when users tried to select records in ManyToOne relation dropdowns.
The fix changes line 87 in the component to wrap the recordId
in an object with an id
property: onSubmit?.({ newValue: { id: selectedMorphItem.recordId } })
. This ensures the data structure aligns with what the usePersistField
hook expects for relation persistence, allowing the updateOneRecord
mutation to properly set the foreign key relationship.
This change is part of Twenty's object-record module, specifically within the record field list components that handle relation management in the record detail view. The fix ensures that the relation picker dropdown properly communicates with the persistence layer when users assign related records.
Important Files Changed
Changed Files
Filename | Score | Overview |
---|---|---|
packages/twenty-front/src/modules/object-record/record-field-list/record-detail-section/relation/components/RecordDetailRelationSectionDropdownToOne.tsx | 4/5 | Fixed data structure passed to onSubmit callback from string to object with id property |
Confidence score: 4/5
- This PR addresses a critical bug with a targeted fix that should restore proper functionality to ManyToOne relation assignment
- Score reflects the focused nature of the fix and clear understanding of the data structure mismatch that caused the bug
- Pay close attention to the single modified file to ensure the data structure change properly aligns with the persistence layer expectations
Sequence Diagram
sequenceDiagram
participant User
participant RecordDetailRelationSectionDropdownToOne
participant FieldContext
participant FieldInputEventContext
participant useObjectMetadataItem
participant recordStoreFamilySelector
participant SingleRecordPicker
participant useCloseDropdown
participant useAddNewRecordAndOpenRightDrawer
participant useSingleRecordPickerOpen
User->>RecordDetailRelationSectionDropdownToOne: "Click pencil icon to edit relation"
RecordDetailRelationSectionDropdownToOne->>FieldContext: "Get recordId and fieldDefinition"
FieldContext-->>RecordDetailRelationSectionDropdownToOne: "Return context data"
RecordDetailRelationSectionDropdownToOne->>useObjectMetadataItem: "Get relation object metadata"
useObjectMetadataItem-->>RecordDetailRelationSectionDropdownToOne: "Return relationObjectMetadataItem"
RecordDetailRelationSectionDropdownToOne->>recordStoreFamilySelector: "Get current field value"
recordStoreFamilySelector-->>RecordDetailRelationSectionDropdownToOne: "Return fieldValue"
RecordDetailRelationSectionDropdownToOne->>useSingleRecordPickerOpen: "Open single record picker"
useSingleRecordPickerOpen-->>SingleRecordPicker: "Display picker with current selection"
User->>SingleRecordPicker: "Select new related record"
SingleRecordPicker->>RecordDetailRelationSectionDropdownToOne: "Call handleRelationPickerEntitySelected"
RecordDetailRelationSectionDropdownToOne->>useCloseDropdown: "Close dropdown"
RecordDetailRelationSectionDropdownToOne->>FieldInputEventContext: "Submit new value via onSubmit"
FieldInputEventContext-->>RecordDetailRelationSectionDropdownToOne: "Process field update"
alt User wants to create new record
User->>SingleRecordPicker: "Click create new option"
SingleRecordPicker->>RecordDetailRelationSectionDropdownToOne: "Call handleCreateNew"
RecordDetailRelationSectionDropdownToOne->>useAddNewRecordAndOpenRightDrawer: "Create and open new record"
useAddNewRecordAndOpenRightDrawer-->>User: "Open right drawer with new record form"
end
1 file reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
return; | ||
|
||
onSubmit?.({ newValue: selectedMorphItem.recordId }); | ||
onSubmit?.({ newValue: { id: selectedMorphItem.recordId } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not possible to have it strongly typed?
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:52952 This environment will automatically shut down when the PR is closed or after 5 hours. |
While refactoring SingleRecordPicker to support morph use case, we forgot to QA RelationDetailSection for ManyToOne.