diff --git a/packages/twenty-front/src/modules/object-metadata/utils/isObjectMetadataReadOnly.ts b/packages/twenty-front/src/modules/object-metadata/utils/isObjectMetadataReadOnly.ts new file mode 100644 index 0000000000000..c6455e009c9d7 --- /dev/null +++ b/packages/twenty-front/src/modules/object-metadata/utils/isObjectMetadataReadOnly.ts @@ -0,0 +1,8 @@ +import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; +import { isWorkflowSubObjectMetadata } from '@/object-metadata/utils/isWorkflowSubObjectMetadata'; + +export const isObjectMetadataReadOnly = ( + objectMetadataItem: Pick, +) => + objectMetadataItem.isRemote || + isWorkflowSubObjectMetadata(objectMetadataItem.nameSingular); diff --git a/packages/twenty-front/src/modules/object-metadata/utils/isReadOnlyObject.ts b/packages/twenty-front/src/modules/object-metadata/utils/isReadOnlyObject.ts deleted file mode 100644 index 6d57e85f384bd..0000000000000 --- a/packages/twenty-front/src/modules/object-metadata/utils/isReadOnlyObject.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; -import { isWorkflowSubObject } from '@/object-metadata/utils/isWorkflowSubObject'; - -export const isReadOnlyObject = ( - objectMetadataItem: Pick, -) => - objectMetadataItem.isRemote || - isWorkflowSubObject(objectMetadataItem.nameSingular); diff --git a/packages/twenty-front/src/modules/object-metadata/utils/isWorkflowSubObject.ts b/packages/twenty-front/src/modules/object-metadata/utils/isWorkflowSubObjectMetadata.ts similarity index 72% rename from packages/twenty-front/src/modules/object-metadata/utils/isWorkflowSubObject.ts rename to packages/twenty-front/src/modules/object-metadata/utils/isWorkflowSubObjectMetadata.ts index a02d78f3e6351..1ad6c0cbb2900 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/isWorkflowSubObject.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/isWorkflowSubObjectMetadata.ts @@ -1,5 +1,7 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; -export const isWorkflowSubObject = (objectMetadataNameSingular?: string) => +export const isWorkflowSubObjectMetadata = ( + objectMetadataNameSingular?: string, +) => objectMetadataNameSingular === CoreObjectNameSingular.WorkflowVersion || objectMetadataNameSingular === CoreObjectNameSingular.WorkflowRun; diff --git a/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx b/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx index bee66b1a8d230..c76c109561ace 100644 --- a/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx +++ b/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx @@ -5,7 +5,7 @@ import { IconFileExport, IconHeart, IconHeartOff, IconTrash } from 'twenty-ui'; import { useFavorites } from '@/favorites/hooks/useFavorites'; import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; -import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject'; +import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly'; import { DELETE_MAX_COUNT } from '@/object-record/constants/DeleteMaxCount'; import { useDeleteTableData } from '@/object-record/record-index/options/hooks/useDeleteTableData'; import { @@ -91,7 +91,7 @@ export const useRecordActionBar = ({ filename: `${objectMetadataItem.nameSingular}.csv`, }); - const isReadOnly = isReadOnlyObject(objectMetadataItem); + const isReadOnly = isObjectMetadataReadOnly(objectMetadataItem); const numberOfSelectedRecords = totalNumberOfRecordsSelected ?? selectedRecordIds.length; diff --git a/packages/twenty-front/src/modules/object-record/record-field/hooks/useIsFieldReadOnly.ts b/packages/twenty-front/src/modules/object-record/record-field/hooks/useIsFieldReadOnly.ts index ba8dedd7c0a06..48bb034244eac 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/hooks/useIsFieldReadOnly.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/hooks/useIsFieldReadOnly.ts @@ -2,8 +2,8 @@ import { useContext } from 'react'; import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor'; import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText'; -import { isFieldReadonlyFromObjectMetadataName } from '@/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName'; import { FieldContext } from '../contexts/FieldContext'; +import { isFieldMetadataReadOnly } from '../utils/isFieldMetadataReadOnly'; export const useIsFieldReadOnly = () => { const { fieldDefinition } = useContext(FieldContext); @@ -11,13 +11,8 @@ export const useIsFieldReadOnly = () => { const { metadata } = fieldDefinition; return ( - metadata.fieldName === 'noteTargets' || - metadata.fieldName === 'taskTargets' || isFieldActor(fieldDefinition) || isFieldRichText(fieldDefinition) || - isFieldReadonlyFromObjectMetadataName( - metadata.fieldName, - metadata.objectMetadataNameSingular, - ) + isFieldMetadataReadOnly(metadata) ); }; diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldMetadataReadOnly.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldMetadataReadOnly.ts new file mode 100644 index 0000000000000..a24ed100352da --- /dev/null +++ b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldMetadataReadOnly.ts @@ -0,0 +1,19 @@ +import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; +import { isWorkflowSubObjectMetadata } from '@/object-metadata/utils/isWorkflowSubObjectMetadata'; +import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; + +export const isFieldMetadataReadOnly = (fieldMetadata: FieldMetadata) => { + if ( + fieldMetadata.fieldName === 'noteTargets' || + fieldMetadata.fieldName === 'taskTargets' + ) { + return true; + } + + return ( + isWorkflowSubObjectMetadata(fieldMetadata.objectMetadataNameSingular) || + (fieldMetadata.objectMetadataNameSingular === + CoreObjectNameSingular.Workflow && + fieldMetadata.fieldName !== 'name') + ); +}; diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName.ts deleted file mode 100644 index ca208cbccf708..0000000000000 --- a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; -import { isWorkflowSubObject } from '@/object-metadata/utils/isWorkflowSubObject'; - -export const isFieldReadonlyFromObjectMetadataName = ( - fieldName: string, - objectMetadataNameSingular?: string, -) => { - if (!objectMetadataNameSingular) { - return false; - } - - return ( - isWorkflowSubObject(objectMetadataNameSingular) || - (objectMetadataNameSingular === CoreObjectNameSingular.Workflow && - fieldName !== 'name') - ); -}; diff --git a/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexPageHeader.tsx b/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexPageHeader.tsx index bb0f3cf011682..f167ad13f19d9 100644 --- a/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexPageHeader.tsx +++ b/packages/twenty-front/src/modules/object-record/record-index/components/RecordIndexPageHeader.tsx @@ -2,7 +2,7 @@ import { useRecoilValue } from 'recoil'; import { useIcons } from 'twenty-ui'; import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; -import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject'; +import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly'; import { RecordIndexPageKanbanAddButton } from '@/object-record/record-index/components/RecordIndexPageKanbanAddButton'; import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext'; import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState'; @@ -32,7 +32,7 @@ export const RecordIndexPageHeader = () => { const recordIndexViewType = useRecoilValue(recordIndexViewTypeState); const shouldDisplayAddButton = objectMetadataItem - ? !isReadOnlyObject(objectMetadataItem) + ? !isObjectMetadataReadOnly(objectMetadataItem) : false; const isTable = recordIndexViewType === ViewType.Table; diff --git a/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationRecordsListItem.tsx b/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationRecordsListItem.tsx index 8ced0500d7e96..eefeb35408782 100644 --- a/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationRecordsListItem.tsx +++ b/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationRecordsListItem.tsx @@ -24,7 +24,7 @@ import { } from '@/object-record/record-field/contexts/FieldContext'; import { usePersistField } from '@/object-record/record-field/hooks/usePersistField'; import { FieldRelationMetadata } from '@/object-record/record-field/types/FieldMetadata'; -import { isFieldReadonlyFromObjectMetadataName } from '@/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName'; +import { isFieldMetadataReadOnly } from '@/object-record/record-field/utils/isFieldMetadataReadOnly'; import { RecordInlineCell } from '@/object-record/record-inline-cell/components/RecordInlineCell'; import { PropertyBox } from '@/object-record/record-inline-cell/property-box/components/PropertyBox'; import { InlineCellHotkeyScope } from '@/object-record/record-inline-cell/types/InlineCellHotkeyScope'; @@ -181,10 +181,7 @@ export const RecordDetailRelationRecordsListItem = ({ [isExpanded], ); - const canEdit = !isFieldReadonlyFromObjectMetadataName( - fieldDefinition.metadata.fieldName, - fieldDefinition.metadata.objectMetadataNameSingular, - ); + const canEdit = !isFieldMetadataReadOnly(fieldDefinition.metadata); return ( <> diff --git a/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationSection.tsx b/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationSection.tsx index f9e57f5e43256..81e0c37c76e73 100644 --- a/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationSection.tsx +++ b/packages/twenty-front/src/modules/object-record/record-show/record-detail-section/components/RecordDetailRelationSection.tsx @@ -12,7 +12,7 @@ import { usePersistField } from '@/object-record/record-field/hooks/usePersistFi import { RelationFromManyFieldInputMultiRecordsEffect } from '@/object-record/record-field/meta-types/input/components/RelationFromManyFieldInputMultiRecordsEffect'; import { useUpdateRelationFromManyFieldInput } from '@/object-record/record-field/meta-types/input/hooks/useUpdateRelationFromManyFieldInput'; import { FieldRelationMetadata } from '@/object-record/record-field/types/FieldMetadata'; -import { isFieldReadonlyFromObjectMetadataName } from '@/object-record/record-field/utils/isFieldReadonlyFromObjectMetadataName'; +import { isFieldMetadataReadOnly } from '@/object-record/record-field/utils/isFieldMetadataReadOnly'; import { RecordDetailRelationRecordsList } from '@/object-record/record-show/record-detail-section/components/RecordDetailRelationRecordsList'; import { RecordDetailSection } from '@/object-record/record-show/record-detail-section/components/RecordDetailSection'; import { RecordDetailSectionHeader } from '@/object-record/record-show/record-detail-section/components/RecordDetailSectionHeader'; @@ -159,10 +159,7 @@ export const RecordDetailRelationSection = ({ recordId, }); - const canEdit = !isFieldReadonlyFromObjectMetadataName( - fieldDefinition.metadata.fieldName, - fieldDefinition.metadata.objectMetadataNameSingular, - ); + const canEdit = !isFieldMetadataReadOnly(fieldDefinition.metadata); if (loading) return null; diff --git a/packages/twenty-front/src/modules/object-record/record-table/empty-state/components/RecordTableEmptyStateDisplay.tsx b/packages/twenty-front/src/modules/object-record/record-table/empty-state/components/RecordTableEmptyStateDisplay.tsx index 1dcb489a79ea7..c5f120a6de630 100644 --- a/packages/twenty-front/src/modules/object-record/record-table/empty-state/components/RecordTableEmptyStateDisplay.tsx +++ b/packages/twenty-front/src/modules/object-record/record-table/empty-state/components/RecordTableEmptyStateDisplay.tsx @@ -8,7 +8,7 @@ import { AnimatedPlaceholderEmptyTitle, } from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled'; -import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject'; +import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly'; import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext'; import { Button } from '@/ui/input/button/components/Button'; import { useContext } from 'react'; @@ -32,7 +32,7 @@ export const RecordTableEmptyStateDisplay = ({ title, }: RecordTableEmptyStateDisplayProps) => { const { objectMetadataItem } = useContext(RecordTableContext); - const isReadOnly = isReadOnlyObject(objectMetadataItem); + const isReadOnly = isObjectMetadataReadOnly(objectMetadataItem); return ( diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableHeaderCell.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableHeaderCell.tsx index e5d9661790943..ff3fc98580ee3 100644 --- a/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableHeaderCell.tsx +++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableHeaderCell.tsx @@ -4,7 +4,7 @@ import { useRecoilCallback, useRecoilState, useRecoilValue } from 'recoil'; import { IconPlus } from 'twenty-ui'; import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; -import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject'; +import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly'; import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates'; import { useCreateNewTableRecord } from '@/object-record/record-table/hooks/useCreateNewTableRecords'; @@ -198,7 +198,7 @@ export const RecordTableHeaderCell = ({ createNewTableRecord(); }; - const isReadOnly = isReadOnlyObject(objectMetadataItem); + const isReadOnly = isObjectMetadataReadOnly(objectMetadataItem); return (