The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(front): duplicate junction chip after Add New in relation picker (#23185)
neo77397d2b52a71a1
diff --git a/packages/twenty-front/src/modules/object-record/record-field-list/record-detail-section/relation/components/RecordDetailRelationSectionDropdownToMany.tsx b/packages/twenty-front/src/modules/object-record/record-field-list/record-detail-section/relation/components/RecordDetailRelationSectionDropdownToMany.tsxindex a6538736f42..95949e047bf 100644--- a/packages/twenty-front/src/modules/object-record/record-field-list/record-detail-section/relation/components/RecordDetailRelationSectionDropdownToMany.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field-list/record-detail-section/relation/components/RecordDetailRelationSectionDropdownToMany.tsx@@ -24,7 +24,6 @@ import { multipleRecordPickerPickableMorphItemsComponentState } from '@/object-rimport { multipleRecordPickerSearchFilterComponentState } from '@/object-record/record-picker/multiple-record-picker/states/multipleRecordPickerSearchFilterComponentState';import { multipleRecordPickerSearchableObjectMetadataItemsComponentState } from '@/object-record/record-picker/multiple-record-picker/states/multipleRecordPickerSearchableObjectMetadataItemsComponentState';import { getRecordFieldCardRelationPickerDropdownId } from '@/object-record/record-show/utils/getRecordFieldCardRelationPickerDropdownId';-import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';import { type ObjectRecord } from '@/object-record/types/ObjectRecord';import { buildRecordLabelPayload } from '@/object-record/utils/buildRecordLabelPayload';@@ -308,33 +307,15 @@ export const RecordDetailRelationSectionDropdownToMany = ({await createTargetRecord(targetPayload);- const newJunctionId = v4();- const createdJunction = await createJunctionRecord({- id: newJunctionId,+ // The junction is already attached to the source record's field by+ // useCreateOneRecord's post-optimistic effect; appending it here as+ // well would render the same target twice until a reload+ await createJunctionRecord({+ id: v4(),[sourceJoinColumnName]: recordId,[targetJoinColumnName]: newTargetId,});- if (isDefined(createdJunction)) {- store.set(- recordStoreFamilyState.atomFamily(recordId),- (currentRecord: ObjectRecord | null | undefined) => {- if (!isDefined(currentRecord)) {- return currentRecord;- }- const currentFieldValue = currentRecord[fieldName];- const updatedJunctionRecords = Array.isArray(currentFieldValue)- ? [...currentFieldValue, createdJunction]- : [createdJunction];-- return {- ...currentRecord,- [fieldName]: updatedJunctionRecords,- } as ObjectRecord;- },- );- }-updatePickerState(newTargetId, junctionTargetObjectMetadata.id);return;}diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/RelationOneToManyFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/RelationOneToManyFieldInput.tsxindex 3d6d103a31e..13c6ea1658b 100644--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/RelationOneToManyFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/RelationOneToManyFieldInput.tsx@@ -28,8 +28,6 @@ import { hasJunctionConfig } from '@/object-record/record-field/ui/utils/junctioimport { MultipleRecordPicker } from '@/object-record/record-picker/multiple-record-picker/components/MultipleRecordPicker';import { useMultipleRecordPickerPerformSearch } from '@/object-record/record-picker/multiple-record-picker/hooks/useMultipleRecordPickerPerformSearch';import { multipleRecordPickerPickableMorphItemsComponentState } from '@/object-record/record-picker/multiple-record-picker/states/multipleRecordPickerPickableMorphItemsComponentState';-import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';-import { type ObjectRecord } from '@/object-record/types/ObjectRecord';import { buildRecordLabelPayload } from '@/object-record/utils/buildRecordLabelPayload';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';@@ -238,33 +236,15 @@ export const RelationOneToManyFieldInput = () => {await createTargetRecord(targetPayload);- const newJunctionId = v4();- const createdJunction = await createJunctionRecord({- id: newJunctionId,+ // The junction is already attached to the source record's field by+ // useCreateOneRecord's post-optimistic effect; appending it here as+ // well would render the same target twice until a reload+ await createJunctionRecord({+ id: v4(),[sourceJoinColumnName]: recordId,[targetJoinColumnName]: newTargetId,});- if (isDefined(createdJunction)) {- store.set(- recordStoreFamilyState.atomFamily(recordId),- (currentRecord: ObjectRecord | null | undefined) => {- if (!isDefined(currentRecord)) {- return currentRecord;- }- const currentFieldValue = currentRecord[fieldName];- const updatedJunctionRecords = Array.isArray(currentFieldValue)- ? [...currentFieldValue, createdJunction]- : [createdJunction];-- return {- ...currentRecord,- [fieldName]: updatedJunctionRecords,- } as ObjectRecord;- },- );- }-updatePickerState(newTargetId, junctionTargetObjectMetadata.id, [junctionTargetObjectMetadata,]);