[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:
Paul Rastoin
2025-02-26 17:04:52 +01:00
committed by GitHub
parent e6355c7c49
commit ea0d3c605f
11 changed files with 215 additions and 120 deletions

View File

@ -1,7 +1,7 @@
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { FieldMetadataType } from 'twenty-shared';
export const checkObjectMetadataItemHasFieldCreatedBy = (
export const hasObjectMetadataItemFieldCreatedBy = (
objectMetadataItem: ObjectMetadataItem,
) =>
objectMetadataItem.fields.some(

View File

@ -0,0 +1,10 @@
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { FieldMetadataType } from 'twenty-shared';
export const hasObjectMetadataItemPositionField = (
objectMetadataItem: ObjectMetadataItem,
) =>
!objectMetadataItem.isRemote &&
objectMetadataItem.fields.some(
(field) => field.type === FieldMetadataType.POSITION,
);

View File

@ -1,4 +0,0 @@
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
export const hasPositionField = (objectMetadataItem: ObjectMetadataItem) =>
!objectMetadataItem.isRemote;