-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Optimistically compute
position
only for objectMetadataItem
…
… that has the field (#10510) # Introduction In this PR #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`.
- Loading branch information
Showing
11 changed files
with
210 additions
and
115 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...eckObjectMetadataItemHasFieldCreatedBy.ts → ...ls/hasObjectMetadataItemFieldCreatedBy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ages/twenty-front/src/modules/object-metadata/utils/hasObjectMetadataItemPositionField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
); |
4 changes: 0 additions & 4 deletions
4
packages/twenty-front/src/modules/object-metadata/utils/hasPositionField.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...nty-front/src/modules/object-record/utils/computeOptimisticCreateRecordBaseRecordInput.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type EachTestingContext<T> = { | ||
title: string; | ||
context: T; | ||
}; |
Oops, something went wrong.