[FIX] Optimistically compute position only for objectMetadataItem that has the field (#10510)
# Introduction In this PR https://github.com/twentyhq/twenty/pull/10493 introduced a regression on optimistic cache for record creation, by expecting a `position` `fieldMetadataItem` on every `ObjectMetadataItem` which is a wrong assertion Some `Tasks` and `ApiKeys` do not have one ## Fix Dynamically compute optimistic record input position depending on current `ObjectMetadataItem` ## Refactor Refactored a failing test following [jest each](https://jestjs.io/docs/api#describeeachtablename-fn-timeout) pattern to avoid error prone duplicated env tests. Created a "standard' and applied it to an other test also using `it.each`.
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { hasObjectMetadataItemFieldCreatedBy } from '@/object-metadata/utils/hasObjectMetadataItemFieldCreatedBy';
|
||||
import { hasObjectMetadataItemPositionField } from '@/object-metadata/utils/hasObjectMetadataItemPositionField';
|
||||
import { FieldActorForInputValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
|
||||
export const computeOptimisticCreateRecordBaseRecordInput = (
|
||||
objectMetadataItem: ObjectMetadataItem,
|
||||
) => {
|
||||
const baseRecordInput: Partial<ObjectRecord> = {};
|
||||
|
||||
if (hasObjectMetadataItemFieldCreatedBy(objectMetadataItem)) {
|
||||
baseRecordInput.createdBy = {
|
||||
source: 'MANUAL',
|
||||
context: {},
|
||||
} satisfies FieldActorForInputValue;
|
||||
}
|
||||
|
||||
if (hasObjectMetadataItemPositionField(objectMetadataItem)) {
|
||||
baseRecordInput.position = Number.NEGATIVE_INFINITY;
|
||||
}
|
||||
|
||||
return baseRecordInput;
|
||||
};
|
||||
Reference in New Issue
Block a user