Skip to content

The open alternative to Salesforce, designed for AI.

fix: prevent record title reset on focus for notes and tasks (#17439)

Richman0189c9c0a759536
diff --git a/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/components/CreateRelatedRecordAction.tsx b/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/components/CreateRelatedRecordAction.tsx
index 329da09050b..f0838abdb15 100644
--- a/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/components/CreateRelatedRecordAction.tsx
+++ b/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/components/CreateRelatedRecordAction.tsx
@@ -106,7 +106,7 @@ export const CreateRelatedRecordAction = ({
if (isDefined(labelIdentifierFieldMetadataItem)) {
openRecordTitleCell({
recordId: createdRecord.id,
- fieldName: labelIdentifierFieldMetadataItem.name,
+ fieldMetadataItemId: labelIdentifierFieldMetadataItem.id,
instanceId: getRecordFieldInputInstanceId({
recordId: createdRecord.id,
fieldName: labelIdentifierFieldMetadataItem.name,
diff --git a/packages/twenty-front/src/modules/object-record/record-table/hooks/useCreateNewIndexRecord.ts b/packages/twenty-front/src/modules/object-record/record-table/hooks/useCreateNewIndexRecord.ts
index 3a07f87b644..85ba975ffdf 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/hooks/useCreateNewIndexRecord.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/hooks/useCreateNewIndexRecord.ts
@@ -108,7 +108,7 @@ export const useCreateNewIndexRecord = ({
if (isDefined(labelIdentifierFieldMetadataItem)) {
openRecordTitleCell({
recordId,
- fieldName: labelIdentifierFieldMetadataItem.name,
+ fieldMetadataItemId: labelIdentifierFieldMetadataItem.id,
instanceId: getRecordFieldInputInstanceId({
recordId,
fieldName: labelIdentifierFieldMetadataItem.name,
diff --git a/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldDisplay.tsx b/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldDisplay.tsx
index a89a89e3c5c..2647b463ee0 100644
--- a/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldDisplay.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldDisplay.tsx
@@ -1,4 +1,3 @@
-import { t } from '@lingui/core/macro';
import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { useRecordTitleCell } from '@/object-record/record-title-cell/hooks/useRecordTitleCell';
@@ -6,6 +5,7 @@ import { type RecordTitleCellContainerType } from '@/object-record/record-title-
import { getRecordFieldInputInstanceId } from '@/object-record/utils/getRecordFieldInputId';
import { withTheme, type Theme } from '@emotion/react';
import styled from '@emotion/styled';
+import { t } from '@lingui/core/macro';
import { useContext } from 'react';
import { useRecoilValue } from 'recoil';
import { OverflowingTextWithTooltip } from 'twenty-ui/display';
@@ -51,7 +51,7 @@ export const RecordTitleCellSingleTextDisplayMode = ({
onClick={() => {
openRecordTitleCell({
recordId,
- fieldName: fieldDefinition.metadata.fieldName,
+ fieldMetadataItemId: fieldDefinition.fieldMetadataId,
instanceId: getRecordFieldInputInstanceId({
recordId,
fieldName: fieldDefinition.metadata.fieldName,
diff --git a/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldInput.tsx
index a7fd3ce3f8f..7327fd40012 100644
--- a/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleCellTextFieldInput.tsx
@@ -50,6 +50,7 @@ export const RecordTitleCellTextFieldInput = ({
});
const handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {
+ // Ensure draft value is set from field value if it's undefined or empty when focusing
if (isDefined(draftValue)) {
event.target.select();
}
diff --git a/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleFullNameFieldDisplay.tsx b/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleFullNameFieldDisplay.tsx
index 46ec8af1e8b..559eb0e7ab3 100644
--- a/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleFullNameFieldDisplay.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-title-cell/components/RecordTitleFullNameFieldDisplay.tsx
@@ -1,4 +1,3 @@
-import { t } from '@lingui/core/macro';
import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
import { useFullNameFieldDisplay } from '@/object-record/record-field/ui/meta-types/hooks/useFullNameFieldDisplay';
import { useRecordTitleCell } from '@/object-record/record-title-cell/hooks/useRecordTitleCell';
@@ -7,6 +6,7 @@ import { usePushFocusItemToFocusStack } from '@/ui/utilities/focus/hooks/usePush
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
import { withTheme, type Theme } from '@emotion/react';
import styled from '@emotion/styled';
+import { t } from '@lingui/core/macro';
import { isNonEmptyString } from '@sniptt/guards';
import { useContext } from 'react';
import { OverflowingTextWithTooltip } from 'twenty-ui/display';
@@ -73,7 +73,7 @@ export const RecordTitleFullNameFieldDisplay = ({
openRecordTitleCell({
recordId,
- fieldName: fieldDefinition.metadata.fieldName,
+ fieldMetadataItemId: fieldDefinition.fieldMetadataId,
instanceId: getRecordFieldInputInstanceId({
recordId,
fieldName: fieldDefinition.metadata.fieldName,
diff --git a/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx b/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx
index 95367ecb2e8..8e69a8a20b8 100644
--- a/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-title-cell/hooks/useRecordTitleCell.tsx
@@ -1,4 +1,4 @@
-import { useContextStoreObjectMetadataItem } from '@/context-store/hooks/useContextStoreObjectMetadataItem';
+import { useGetFieldMetadataItemByIdOrThrow } from '@/object-metadata/hooks/useGetFieldMetadataItemById';
import { formatFieldMetadataItemAsColumnDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsColumnDefinition';
import { useInitDraftValue } from '@/object-record/record-field/ui/hooks/useInitDraftValue';
import { RecordTitleCellComponentInstanceContext } from '@/object-record/record-title-cell/states/contexts/RecordTitleCellComponentInstanceContext';
@@ -13,7 +13,7 @@ import { isDefined } from 'twenty-shared/utils';
type OpenTitleCellFunctionParams = {
recordId: string;
- fieldName: string;
+ fieldMetadataItemId: string;
instanceId?: string;
};
@@ -29,7 +29,8 @@ export const useRecordTitleCell = () => {
const { removeFocusItemFromFocusStackById } =
useRemoveFocusItemFromFocusStackById();
- const { objectMetadataItem } = useContextStoreObjectMetadataItem();
+ const { getFieldMetadataItemByIdOrThrow } =
+ useGetFieldMetadataItemByIdOrThrow();
const closeRecordTitleCell = useRecoilCallback(
({ set }) =>
@@ -67,15 +68,9 @@ export const useRecordTitleCell = () => {
({ set }) =>
({
recordId,
- fieldName,
+ fieldMetadataItemId,
instanceId: instanceIdFromProps,
}: OpenTitleCellFunctionParams) => {
- if (!isDefined(objectMetadataItem)) {
- throw new Error(
- 'Cannot find object metadata item in openRecordTitleCell this should not happen.',
- );
- }
-
const computedInstanceId = instanceIdFromProps ?? instanceId;
if (!isDefined(computedInstanceId)) {
@@ -103,24 +98,14 @@ export const useRecordTitleCell = () => {
true,
);
- const fieldDefinitions = objectMetadataItem.fields.map(
- (fieldMetadataItem, index) =>
- formatFieldMetadataItemAsColumnDefinition({
- field: fieldMetadataItem,
- objectMetadataItem,
- position: index,
- }),
- );
+ const { fieldMetadataItem, objectMetadataItem } =
+ getFieldMetadataItemByIdOrThrow(fieldMetadataItemId);
- const fieldDefinition = fieldDefinitions.find(
- (field) => field.metadata.fieldName === fieldName,
- );
-
- if (!fieldDefinition) {
- throw new Error(
- `Cannot find field definition for field name ${fieldName}, this should not happen.`,
- );
- }
+ const fieldDefinition = formatFieldMetadataItemAsColumnDefinition({
+ field: fieldMetadataItem,
+ objectMetadataItem,
+ position: 0,
+ });
initFieldInputDraftValue({
recordId,
@@ -129,10 +114,10 @@ export const useRecordTitleCell = () => {
});
},
[
- objectMetadataItem,
instanceId,
pushFocusItemToFocusStack,
initFieldInputDraftValue,
+ getFieldMetadataItemByIdOrThrow,
],
);