From aa424c6680230c64acb17ccd7ca0d4cbb87b5ee9 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Thu, 15 May 2025 14:28:13 +0200 Subject: [PATCH] Make workflow custom fields editable (#12063) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/twentyhq/twenty/issues/11989 Capture d’écran 2025-05-15 à 14 05 15 `isCustom` was not properly set everywhere because it was not mandatory in `isFieldValueReadOnly`. Removing the default value and adding it to missing places --- .../components/ActivityRichTextEditor.tsx | 1 + ...ormatFieldMetadataItemAsFieldDefinition.ts | 1 + .../components/RecordBoardCardBody.tsx | 1 + .../__tests__/isFieldValueReadOnly.test.ts | 20 +++++++++++++++++++ .../utils/isFieldValueReadOnly.ts | 4 ++-- .../__tests__/useExportFetchRecords.test.ts | 1 + .../record-show/components/FieldsCard.tsx | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx b/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx index 8f598891a..ba0a61928 100644 --- a/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx +++ b/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx @@ -70,6 +70,7 @@ export const ActivityRichTextEditor = ({ const isReadOnly = isFieldValueReadOnly({ objectNameSingular: activityObjectNameSingular, isRecordReadOnly, + isCustom: objectMetadataItemActivity.isCustom, }); const { deleteManyRecords: deleteAttachments } = useDeleteManyRecords({ diff --git a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition.ts b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition.ts index 8ba9ebe23..f0afffe0c 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition.ts @@ -39,6 +39,7 @@ export const formatFieldMetadataItemAsFieldDefinition = ({ options: field.options, settings: field.settings, isNullable: field.isNullable, + isCustom: field.isCustom ?? false, }; return { diff --git a/packages/twenty-front/src/modules/object-record/record-board/record-board-card/components/RecordBoardCardBody.tsx b/packages/twenty-front/src/modules/object-record/record-board/record-board-card/components/RecordBoardCardBody.tsx index 1fd3ad044..b951bbd83 100644 --- a/packages/twenty-front/src/modules/object-record/record-board/record-board-card/components/RecordBoardCardBody.tsx +++ b/packages/twenty-front/src/modules/object-record/record-board/record-board-card/components/RecordBoardCardBody.tsx @@ -51,6 +51,7 @@ export const RecordBoardCardBody = ({ fieldName: fieldDefinition.metadata.fieldName, fieldType: fieldDefinition.type, isRecordReadOnly, + isCustom: fieldDefinition.metadata.isCustom, }), fieldDefinition: { disableTooltip: false, diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueReadOnly.test.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueReadOnly.test.ts index 67dcd1243..f17112e71 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueReadOnly.test.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueReadOnly.test.ts @@ -45,6 +45,26 @@ describe('isFieldValueReadOnly', () => { expect(result).toBe(false); }); + it('should return false if object is a workflow object and field is custom', () => { + const result = isFieldValueReadOnly({ + objectNameSingular: CoreObjectNameSingular.Workflow, + fieldName: 'test', + isCustom: true, + }); + + expect(result).toBe(false); + }); + + it('should return false if object is a workflow sub object and field is custom', () => { + const result = isFieldValueReadOnly({ + objectNameSingular: CoreObjectNameSingular.WorkflowVersion, + fieldName: 'test', + isCustom: true, + }); + + expect(result).toBe(false); + }); + describe('when checking field types', () => { it('should return true if fieldType is RICH_TEXT', () => { const result = isFieldValueReadOnly({ diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueReadOnly.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueReadOnly.ts index 048d00335..9c542dc65 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueReadOnly.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueReadOnly.ts @@ -19,8 +19,8 @@ export const isFieldValueReadOnly = ({ objectNameSingular, fieldName, fieldType, + isCustom, isRecordReadOnly = false, - isCustom = false, }: isFieldValueReadOnlyParams) => { if (isRecordReadOnly) { return true; @@ -35,7 +35,7 @@ export const isFieldValueReadOnly = ({ return false; } - if (isWorkflowSubObjectMetadata(objectNameSingular)) { + if (isWorkflowSubObjectMetadata(objectNameSingular) && !isCustom) { return true; } diff --git a/packages/twenty-front/src/modules/object-record/record-index/export/hooks/__tests__/useExportFetchRecords.test.ts b/packages/twenty-front/src/modules/object-record/record-index/export/hooks/__tests__/useExportFetchRecords.test.ts index ecbe9735d..c41732125 100644 --- a/packages/twenty-front/src/modules/object-record/record-index/export/hooks/__tests__/useExportFetchRecords.test.ts +++ b/packages/twenty-front/src/modules/object-record/record-index/export/hooks/__tests__/useExportFetchRecords.test.ts @@ -223,6 +223,7 @@ describe('useRecordData', () => { labelWidth: undefined, metadata: { fieldName: 'updatedAt', + isCustom: false, isNullable: false, objectMetadataNameSingular: 'person', options: null, diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/FieldsCard.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/FieldsCard.tsx index 08894a990..7d7183efa 100644 --- a/packages/twenty-front/src/modules/object-record/record-show/components/FieldsCard.tsx +++ b/packages/twenty-front/src/modules/object-record/record-show/components/FieldsCard.tsx @@ -122,6 +122,7 @@ export const FieldsCard = ({ objectNameSingular, fieldName: fieldMetadataItem.name, fieldType: fieldMetadataItem.type, + isCustom: fieldMetadataItem.isCustom ?? false, isRecordReadOnly, }), }} @@ -164,6 +165,7 @@ export const FieldsCard = ({ objectNameSingular, fieldName: fieldMetadataItem.name, fieldType: fieldMetadataItem.type, + isCustom: fieldMetadataItem.isCustom ?? false, isRecordReadOnly, }), }}