-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] Optimistically compute position
only for objectMetadataItem
that has the field
#10510
Conversation
objectMetadataItem
that has the fieldposition
only for objectMetadataItem
that has the field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR fixes a regression in optimistic cache handling for record creation by correctly identifying objects that have position fields.
- Added new utility
hasObjectMetadataItemPositionField
in/packages/twenty-front/src/modules/object-metadata/utils/hasObjectMetadataItemPositionField.ts
to check if an object actually has a position field - Removed incorrect
hasPositionField.ts
which assumed all non-remote objects had position fields - Created new utility
computeOptimisticCreateRecordBaseRecordInput
to conditionally add position and createdBy fields only when they exist - Updated multiple components to use the new utilities, ensuring position fields are only computed for objects that actually have them
- Renamed
checkObjectMetadataItemHasFieldCreatedBy
tohasObjectMetadataItemFieldCreatedBy
for naming consistency
8 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
...twenty-front/src/modules/object-record/utils/computeOptimisticCreateRecordBaseRecordInput.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with @lucasbordeau refactored failing test using jest each pattern and created a standard regarding it and applied to an other test also using it.each
packages/twenty-front/src/modules/object-metadata/utils/hasObjectMetadataItemPositionField.ts
Show resolved
Hide resolved
} | ||
|
||
if (hasObjectMetadataItemPositionField(objectMetadataItem)) { | ||
baseRecordInput.position = Number.NEGATIVE_INFINITY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really use this NEGATIVE_INFINITY ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed this might seems a bit radical but calculating the next index would quite complex for a very small plus value regarding this solution here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this isn't sent to the api and will override on api response
…10519) Following this discussion #10510 (comment) with @ijreilly
Introduction
In this PR #10493 introduced a regression on optimistic cache for record creation, by expecting a
position
fieldMetadataItem
on everyObjectMetadataItem
which is a wrong assertionSome
Tasks
andApiKeys
do not have oneFix
Dynamically compute optimistic record input position depending on current
ObjectMetadataItem
Refactor
Refactored a failing test following jest each pattern to avoid error prone duplicated env tests. Created a "standard' and applied it to an other test also using
it.each
.