[BUG] Handle optimistic cache deletion operation (#9914)
# Introduction This PR is highly related to previous optimistic cache refactor: https://github.com/twentyhq/twenty/pull/9881 Here we've added some logic within the `triggerUpdateRelationsOptimisticEffect` which will now run if given recordInput `deletedAt` field is defined. If deletion, we will iterate over all the fields searching for `RELATION` for which deletion might implies necessity to detach the relation ## Known troubleshooting ( also on main )  We might have to refactor the `prefillRecord` to spread and overrides`inputValue` over defaultOne as inputValue could be a partial one for more info please a look to # Conclusion Any suggestions are welcomed ! fixes https://github.com/twentyhq/twenty/issues/9580 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -179,4 +179,28 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
`"Should never provide relation mutation through anything else than the fieldId e.g companyId"`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if recordInput contains both the relationFieldId and relationField even if null', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = generatedMockObjectMetadataItems.find(
|
||||
(item) => item.nameSingular === 'person',
|
||||
);
|
||||
if (!personObjectMetadataItem) {
|
||||
throw new Error('Person object metadata item not found');
|
||||
}
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
objectMetadataItems: generatedMockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
recordInput: {
|
||||
companyId: '123',
|
||||
company: null,
|
||||
},
|
||||
cache,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Should never provide relation mutation through anything else than the fieldId e.g companyId"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -91,7 +91,7 @@ export const computeOptimisticRecordFromInput = ({
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isDefined(recordInputFieldValue)) {
|
||||
if (!isUndefined(recordInputFieldValue)) {
|
||||
throw new Error(
|
||||
'Should never provide relation mutation through anything else than the fieldId e.g companyId',
|
||||
);
|
||||
|
||||
@ -34,8 +34,10 @@ export const sanitizeRecordInput = ({
|
||||
(field) => field.name === relationIdFieldName,
|
||||
);
|
||||
|
||||
const relationIdFieldValue = recordInput[relationIdFieldName];
|
||||
|
||||
return relationIdFieldMetadataItem
|
||||
? [relationIdFieldName, fieldValue?.id ?? null]
|
||||
? [relationIdFieldName, relationIdFieldValue ?? null]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user