From dac525340d01858b162ec977ff9a4c31699e4142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tha=C3=AFs=20Guigon?= Date: Fri, 15 Mar 2024 15:17:52 +0100 Subject: [PATCH] refactor: merge FieldType and FieldMetadataType --- .../hooks/useCreateOneFieldMetadataItem.ts | 19 ++---------- .../hooks/useFieldMetadataItem.ts | 3 +- ...ormatFieldMetadataItemAsFieldDefinition.ts | 4 +-- .../object-metadata/utils/parseFieldType.ts | 14 --------- .../utils/shouldFieldBeQueried.ts | 12 ++++--- .../__mocks__/fieldDefinitions.ts | 11 ++++--- .../__stories__/ChipFieldDisplay.stories.tsx | 3 +- .../__stories__/DateFieldDisplay.stories.tsx | 3 +- .../__stories__/EmailFieldDisplay.stories.tsx | 3 +- .../NumberFieldDisplay.stories.tsx | 3 +- .../__stories__/PhoneFieldDisplay.stories.tsx | 3 +- .../__stories__/TextFieldDisplay.stories.tsx | 3 +- .../__stories__/BooleanFieldInput.stories.tsx | 3 +- .../__stories__/DateFieldInput.stories.tsx | 3 +- .../__stories__/EmailFieldInput.stories.tsx | 3 +- .../__stories__/NumberFieldInput.stories.tsx | 3 +- .../__stories__/PhoneFieldInput.stories.tsx | 3 +- .../RelationFieldInput.stories.tsx | 3 +- .../__stories__/TextFieldInput.stories.tsx | 3 +- .../record-field/types/FieldDefinition.ts | 5 +-- .../record-field/types/FieldType.ts | 21 ------------- .../types/guards/assertFieldMetadata.ts | 5 +-- .../components/RecordShowContainer.tsx | 6 ++-- .../record-table-cell/hooks/__mocks__/cell.ts | 3 +- .../SettingsDataModelFieldPreview.tsx | 3 +- .../fields/preview/hooks/useFieldPreview.ts | 3 +- .../SignInBackgroundMockColumnDefinitions.ts | 31 ++++++++++--------- 27 files changed, 72 insertions(+), 107 deletions(-) delete mode 100644 packages/twenty-front/src/modules/object-metadata/utils/parseFieldType.ts delete mode 100644 packages/twenty-front/src/modules/object-record/record-field/types/FieldType.ts diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts index e6a0dd894812..d272404c7df0 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts @@ -1,11 +1,10 @@ import { ApolloClient, useMutation } from '@apollo/client'; import { getOperationName } from '@apollo/client/utilities'; -import { FieldType } from '@/object-record/record-field/types/FieldType'; import { + CreateFieldInput, CreateOneFieldMetadataItemMutation, CreateOneFieldMetadataItemMutationVariables, - FieldMetadataType, } from '~/generated-metadata/graphql'; import { CREATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations'; @@ -13,13 +12,6 @@ import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { useApolloMetadataClient } from './useApolloMetadataClient'; -type CreateOneFieldMetadataItemArgs = Omit< - CreateOneFieldMetadataItemMutationVariables['input']['field'], - 'type' -> & { - type: FieldType; -}; - export const useCreateOneFieldMetadataItem = () => { const apolloMetadataClient = useApolloMetadataClient(); @@ -30,16 +22,11 @@ export const useCreateOneFieldMetadataItem = () => { client: apolloMetadataClient ?? ({} as ApolloClient), }); - const createOneFieldMetadataItem = async ( - input: CreateOneFieldMetadataItemArgs, - ) => { + const createOneFieldMetadataItem = async (input: CreateFieldInput) => { return await mutate({ variables: { input: { - field: { - ...input, - type: input.type as FieldMetadataType, // Todo improve typing once we have aligned backend and frontend - }, + field: input, }, }, awaitRefetchQueries: true, diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useFieldMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useFieldMetadataItem.ts index d2606ad926b5..7c27696a4fa7 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useFieldMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useFieldMetadataItem.ts @@ -1,6 +1,5 @@ import { v4 } from 'uuid'; -import { FieldType } from '@/object-record/record-field/types/FieldType'; import { Field } from '~/generated/graphql'; import { FieldMetadataType } from '~/generated-metadata/graphql'; @@ -29,7 +28,7 @@ export const useFieldMetadataItem = () => { ...formatFieldMetadataItemInput(input), defaultValue: input.defaultValue, objectMetadataId: input.objectMetadataId, - type: input.type as FieldType, + type: input.type, }); const editMetadataField = ( 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 3679055c4c11..7b6df02d1561 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemAsFieldDefinition.ts @@ -3,8 +3,6 @@ import { parseFieldRelationType } from '@/object-metadata/utils/parseFieldRelati import { FieldMetadataItem } from '../types/FieldMetadataItem'; -import { parseFieldType } from './parseFieldType'; - export type FieldMetadataItemAsFieldDefinitionProps = { field: FieldMetadataItem; objectMetadataItem: ObjectMetadataItem; @@ -31,7 +29,7 @@ export const formatFieldMetadataItemAsFieldDefinition = ({ label: field.label, showLabel, labelWidth, - type: parseFieldType(field.type), + type: field.type, metadata: { fieldName: field.name, placeHolder: field.label, diff --git a/packages/twenty-front/src/modules/object-metadata/utils/parseFieldType.ts b/packages/twenty-front/src/modules/object-metadata/utils/parseFieldType.ts deleted file mode 100644 index 84ac0e1a99ad..000000000000 --- a/packages/twenty-front/src/modules/object-metadata/utils/parseFieldType.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { FieldType } from '@/object-record/record-field/types/FieldType'; -import { FieldMetadataType } from '~/generated-metadata/graphql'; - -export const parseFieldType = (fieldType: FieldMetadataType): FieldType => { - if (fieldType === FieldMetadataType.Link) { - return 'LINK'; - } - - if (fieldType === FieldMetadataType.Currency) { - return 'CURRENCY'; - } - - return fieldType as FieldType; -}; diff --git a/packages/twenty-front/src/modules/object-metadata/utils/shouldFieldBeQueried.ts b/packages/twenty-front/src/modules/object-metadata/utils/shouldFieldBeQueried.ts index 7c041594365b..3e99775ebf6b 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/shouldFieldBeQueried.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/shouldFieldBeQueried.ts @@ -1,6 +1,6 @@ import { isUndefined } from '@sniptt/guards'; -import { FieldType } from '@/object-record/record-field/types/FieldType'; +import { FieldMetadataType } from '~/generated-metadata/graphql'; import { FieldMetadataItem } from '../types/FieldMetadataItem'; @@ -13,18 +13,20 @@ export const shouldFieldBeQueried = ({ depth?: number; eagerLoadedRelations?: Record; }): any => { - const fieldType = field.type as FieldType; - if (!isUndefined(depth) && depth < 0) { return false; } - if (!isUndefined(depth) && depth < 1 && fieldType === 'RELATION') { + if ( + !isUndefined(depth) && + depth < 1 && + field.type === FieldMetadataType.Relation + ) { return false; } if ( - fieldType === 'RELATION' && + field.type === FieldMetadataType.Relation && !isUndefined(eagerLoadedRelations) && (isUndefined(eagerLoadedRelations[field.name]) || !eagerLoadedRelations[field.name]) diff --git a/packages/twenty-front/src/modules/object-record/record-field/__mocks__/fieldDefinitions.ts b/packages/twenty-front/src/modules/object-record/record-field/__mocks__/fieldDefinitions.ts index 8b842656a63e..4a85b26f246f 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/__mocks__/fieldDefinitions.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/__mocks__/fieldDefinitions.ts @@ -7,6 +7,7 @@ import { FieldSelectMetadata, FieldTextMetadata, } from '@/object-record/record-field/types/FieldMetadata'; +import { FieldMetadataType } from '~/generated-metadata/graphql'; import { mockedCompaniesMetadata, mockedCustomMetadata, @@ -34,7 +35,7 @@ export const textfieldDefinition: FieldDefinition = { fieldMetadataId, label: 'User Name', iconName: 'User', - type: 'TEXT', + type: FieldMetadataType.Text, metadata: { placeHolder: 'John Doe', fieldName: 'userName' }, }; @@ -52,7 +53,7 @@ export const selectFieldDefinition: FieldDefinition = { fieldMetadataId, label: 'Account Owner', iconName: 'iconName', - type: 'SELECT', + type: FieldMetadataType.Select, metadata: { fieldName: 'accountOwner', options: [{ label: 'Elon Musk', color: 'blue', value: 'userId' }], @@ -63,7 +64,7 @@ export const fullNameFieldDefinition: FieldDefinition = { fieldMetadataId, label: 'Display Name', iconName: 'profile', - type: 'FULL_NAME', + type: FieldMetadataType.FullName, metadata: { fieldName: 'displayName', placeHolder: 'Mr Miagi', @@ -74,7 +75,7 @@ export const linkFieldDefinition: FieldDefinition = { fieldMetadataId, label: 'LinkedIn URL', iconName: 'url', - type: 'LINK', + type: FieldMetadataType.Link, metadata: { fieldName: 'linkedInURL', placeHolder: 'https://linkedin.com/user', @@ -93,7 +94,7 @@ export const ratingfieldDefinition: FieldDefinition = { fieldMetadataId, label: 'Rating', iconName: 'iconName', - type: 'RATING', + type: FieldMetadataType.Rating, metadata: { fieldName: 'rating', }, diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx index 7b963b45c9a7..f1eaf2aa5203 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx @@ -5,6 +5,7 @@ import { useSetRecoilState } from 'recoil'; import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; import { ChipFieldDisplay } from '@/object-record/record-field/meta-types/display/components/ChipFieldDisplay'; import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator'; @@ -37,7 +38,7 @@ const meta: Meta = { fieldDefinition: { fieldMetadataId: 'full name', label: 'Henry Cavill', - type: 'FULL_NAME', + type: FieldMetadataType.FullName, iconName: 'IconCalendarEvent', metadata: { fieldName: 'full name', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/DateFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/DateFieldDisplay.stories.tsx index 3e2ae7bfeff3..5e59fa27dd4e 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/DateFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/DateFieldDisplay.stories.tsx @@ -1,6 +1,7 @@ import { useEffect } from 'react'; import { Meta, StoryObj } from '@storybook/react'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { FieldContext } from '../../../../contexts/FieldContext'; @@ -30,7 +31,7 @@ const meta: Meta = { fieldDefinition: { fieldMetadataId: 'date', label: 'Date', - type: 'DATE_TIME', + type: FieldMetadataType.DateTime, iconName: 'IconCalendarEvent', metadata: { fieldName: 'Date', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/EmailFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/EmailFieldDisplay.stories.tsx index 902eefa4b32f..cdb48e180a6f 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/EmailFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/EmailFieldDisplay.stories.tsx @@ -3,6 +3,7 @@ import { Meta, StoryObj } from '@storybook/react'; import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; import { useEmailField } from '@/object-record/record-field/meta-types/hooks/useEmailField'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator'; @@ -30,7 +31,7 @@ const meta: Meta = { fieldDefinition: { fieldMetadataId: 'email', label: 'Email', - type: 'EMAIL', + type: FieldMetadataType.Email, iconName: 'IconLink', metadata: { fieldName: 'Email', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/NumberFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/NumberFieldDisplay.stories.tsx index a7f0304a97ce..3c3d8e229830 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/NumberFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/NumberFieldDisplay.stories.tsx @@ -1,6 +1,7 @@ import { useEffect } from 'react'; import { Meta, StoryObj } from '@storybook/react'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { FieldContext } from '../../../../contexts/FieldContext'; @@ -28,7 +29,7 @@ const meta: Meta = { fieldDefinition: { fieldMetadataId: 'number', label: 'Number', - type: 'NUMBER', + type: FieldMetadataType.Number, iconName: 'Icon123', metadata: { fieldName: 'Number', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/PhoneFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/PhoneFieldDisplay.stories.tsx index 1425b23afd02..9e9c85f8d340 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/PhoneFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/PhoneFieldDisplay.stories.tsx @@ -3,6 +3,7 @@ import { Meta, StoryObj } from '@storybook/react'; import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; import { usePhoneField } from '@/object-record/record-field/meta-types/hooks/usePhoneField'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator'; @@ -30,7 +31,7 @@ const meta: Meta = { fieldDefinition: { fieldMetadataId: 'phone', label: 'Phone', - type: 'TEXT', + type: FieldMetadataType.Text, iconName: 'IconPhone', metadata: { fieldName: 'phone', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/TextFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/TextFieldDisplay.stories.tsx index 76328ea7316e..e8ae80758e68 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/TextFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/TextFieldDisplay.stories.tsx @@ -1,6 +1,7 @@ import { useEffect } from 'react'; import { Meta, StoryObj } from '@storybook/react'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { FieldContext } from '../../../../contexts/FieldContext'; @@ -28,7 +29,7 @@ const meta: Meta = { fieldDefinition: { fieldMetadataId: 'text', label: 'Text', - type: 'TEXT', + type: FieldMetadataType.Text, iconName: 'IconLink', metadata: { fieldName: 'Text', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx index 7e556614b5f8..53b026113ebe 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx @@ -4,6 +4,7 @@ import { expect, fn, userEvent, within } from '@storybook/test'; import { useSetRecoilState } from 'recoil'; import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; +import { FieldMetadataType } from '~/generated/graphql'; import { FieldContextProvider } from '../../../__stories__/FieldContextProvider'; import { @@ -43,7 +44,7 @@ const BooleanFieldInputWithContext = ({ fieldMetadataId: 'boolean', label: 'Boolean', iconName: 'Icon123', - type: 'BOOLEAN', + type: FieldMetadataType.Boolean, metadata: { fieldName: 'Boolean', }, diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/DateFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/DateFieldInput.stories.tsx index cfefb9efeb8d..7b0fd4dcabae 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/DateFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/DateFieldInput.stories.tsx @@ -3,6 +3,7 @@ import { Meta, StoryObj } from '@storybook/react'; import { expect, fn, userEvent, within } from '@storybook/test'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; +import { FieldMetadataType } from '~/generated/graphql'; import { FieldContextProvider } from '../../../__stories__/FieldContextProvider'; import { useDateTimeField } from '../../../hooks/useDateTimeField'; @@ -44,7 +45,7 @@ const DateFieldInputWithContext = ({ fieldDefinition={{ fieldMetadataId: 'date', label: 'Date', - type: 'DATE_TIME', + type: FieldMetadataType.DateTime, iconName: 'IconCalendarEvent', metadata: { fieldName: 'Date', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/EmailFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/EmailFieldInput.stories.tsx index be7c3277fb9a..f3b65cec3d10 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/EmailFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/EmailFieldInput.stories.tsx @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react'; import { expect, fn, userEvent, waitFor, within } from '@storybook/test'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; +import { FieldMetadataType } from '~/generated/graphql'; import { FieldContextProvider } from '../../../__stories__/FieldContextProvider'; import { useEmailField } from '../../../hooks/useEmailField'; @@ -44,7 +45,7 @@ const EmailFieldInputWithContext = ({ fieldDefinition={{ fieldMetadataId: 'email', label: 'Email', - type: 'EMAIL', + type: FieldMetadataType.Email, iconName: 'IconLink', metadata: { fieldName: 'email', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx index eabb3314506e..cc4626de3cb3 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react'; import { expect, fn, userEvent, waitFor, within } from '@storybook/test'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; +import { FieldMetadataType } from '~/generated/graphql'; import { FieldContextProvider } from '../../../__stories__/FieldContextProvider'; import { useNumberField } from '../../../hooks/useNumberField'; @@ -45,7 +46,7 @@ const NumberFieldInputWithContext = ({ fieldMetadataId: 'number', label: 'Number', iconName: 'Icon123', - type: 'NUMBER', + type: FieldMetadataType.Number, metadata: { fieldName: 'number', placeHolder: 'Enter number', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/PhoneFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/PhoneFieldInput.stories.tsx index 7de9b0ff02c7..c38b58a2d687 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/PhoneFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/PhoneFieldInput.stories.tsx @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react'; import { expect, fn, userEvent, waitFor, within } from '@storybook/test'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; +import { FieldMetadataType } from '~/generated/graphql'; import { FieldContextProvider } from '../../../__stories__/FieldContextProvider'; import { usePhoneField } from '../../../hooks/usePhoneField'; @@ -44,7 +45,7 @@ const PhoneFieldInputWithContext = ({ fieldDefinition={{ fieldMetadataId: 'phone', label: 'Phone', - type: 'TEXT', + type: FieldMetadataType.Text, iconName: 'IconPhone', metadata: { fieldName: 'phone', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RelationFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RelationFieldInput.stories.tsx index 3cbe87a498aa..e3ad58656935 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RelationFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/RelationFieldInput.stories.tsx @@ -14,6 +14,7 @@ import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMembe import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; +import { FieldMetadataType } from '~/generated/graphql'; import { ComponentWithRecoilScopeDecorator } from '~/testing/decorators/ComponentWithRecoilScopeDecorator'; import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator'; import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator'; @@ -65,7 +66,7 @@ const RelationFieldInputWithContext = ({ fieldDefinition={{ fieldMetadataId: 'relation', label: 'Relation', - type: 'RELATION', + type: FieldMetadataType.Relation, iconName: 'IconLink', metadata: { fieldName: 'Relation', diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/TextFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/TextFieldInput.stories.tsx index 91c9dc8e6eb8..6dc17f40de08 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/TextFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/TextFieldInput.stories.tsx @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react'; import { expect, fn, userEvent, waitFor, within } from '@storybook/test'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; +import { FieldMetadataType } from '~/generated/graphql'; import { FieldContextProvider } from '../../../__stories__/FieldContextProvider'; import { useTextField } from '../../../hooks/useTextField'; @@ -44,7 +45,7 @@ const TextFieldInputWithContext = ({ fieldDefinition={{ fieldMetadataId: 'text', label: 'Text', - type: 'TEXT', + type: FieldMetadataType.Text, iconName: 'IconTag', metadata: { fieldName: 'Text', diff --git a/packages/twenty-front/src/modules/object-record/record-field/types/FieldDefinition.ts b/packages/twenty-front/src/modules/object-record/record-field/types/FieldDefinition.ts index a6611458e265..3b0f98e7fad8 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/types/FieldDefinition.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/types/FieldDefinition.ts @@ -1,5 +1,6 @@ +import { FieldMetadataType } from '~/generated-metadata/graphql'; + import { FieldMetadata } from './FieldMetadata'; -import { FieldType } from './FieldType'; export type FieldDefinitionRelationType = | 'FROM_MANY_OBJECTS' @@ -14,7 +15,7 @@ export type FieldDefinition = { disableTooltip?: boolean; labelWidth?: number; iconName: string; - type: FieldType; + type: FieldMetadataType; metadata: T; infoTooltipContent?: string; }; diff --git a/packages/twenty-front/src/modules/object-record/record-field/types/FieldType.ts b/packages/twenty-front/src/modules/object-record/record-field/types/FieldType.ts deleted file mode 100644 index d59a6bb84d67..000000000000 --- a/packages/twenty-front/src/modules/object-record/record-field/types/FieldType.ts +++ /dev/null @@ -1,21 +0,0 @@ -export type FieldType = - | 'BOOLEAN' - | 'CHIP' - | 'CURRENCY' - | 'DATE_TIME' - | 'DOUBLE_TEXT_CHIP' - | 'DOUBLE_TEXT' - | 'EMAIL' - | 'FULL_NAME' - | 'LINK' - | 'NUMBER' - | 'PHONE' - | 'RATING' - | 'RELATION' - | 'SELECT' - | 'TEXT' - | 'URL' - | 'UUID' - | 'MULTI_SELECT' - | 'NUMERIC' - | 'RAW_JSON'; diff --git a/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts b/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts index 0cf44a152c3e..24cb92e911b2 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts @@ -1,3 +1,5 @@ +import { FieldMetadataType } from '~/generated-metadata/graphql'; + import { FieldDefinition } from '../FieldDefinition'; import { FieldBooleanMetadata, @@ -16,10 +18,9 @@ import { FieldTextMetadata, FieldUuidMetadata, } from '../FieldMetadata'; -import { FieldType } from '../FieldType'; type AssertFieldMetadataFunction = < - E extends FieldType, + E extends FieldMetadataType, T extends E extends 'BOOLEAN' ? FieldBooleanMetadata : E extends 'CURRENCY' diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx index 08e60c481252..4b33988e7562 100644 --- a/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx +++ b/packages/twenty-front/src/modules/object-record/record-show/components/RecordShowContainer.tsx @@ -3,7 +3,6 @@ import { useRecoilState, useRecoilValue } from 'recoil'; import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; import { formatFieldMetadataItemAsColumnDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsColumnDefinition'; import { isObjectMetadataAvailableForRelation } from '@/object-metadata/utils/isObjectMetadataAvailableForRelation'; -import { parseFieldType } from '@/object-metadata/utils/parseFieldType'; import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord'; import { FieldContext, @@ -147,10 +146,9 @@ export const RecordShowContainer = ({ objectRecordId + labelIdentifierFieldMetadata?.id, isLabelIdentifier: false, fieldDefinition: { - type: parseFieldType( + type: labelIdentifierFieldMetadata?.type || - FieldMetadataType.Text, - ), + FieldMetadataType.Text, iconName: '', fieldMetadataId: labelIdentifierFieldMetadata?.id ?? '', label: labelIdentifierFieldMetadata?.label || '', diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/__mocks__/cell.ts b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/__mocks__/cell.ts index af1402fbabb4..1f8ddd25b16b 100644 --- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/__mocks__/cell.ts +++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/__mocks__/cell.ts @@ -1,5 +1,6 @@ import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition'; +import { FieldMetadataType } from '~/generated-metadata/graphql'; export const recordTableRow = { rowIndex: 2, @@ -19,7 +20,7 @@ export const recordTableCell: { fieldMetadataId: 'fieldMetadataId', label: 'label', iconName: 'iconName', - type: 'TEXT', + type: FieldMetadataType.Text, metadata: { placeHolder: 'placeHolder', fieldName: 'fieldName', diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx index 099ed694ef4f..429e9c9b94eb 100644 --- a/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx +++ b/packages/twenty-front/src/modules/settings/data-model/fields/preview/components/SettingsDataModelFieldPreview.tsx @@ -3,7 +3,6 @@ import styled from '@emotion/styled'; import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; -import { parseFieldType } from '@/object-metadata/utils/parseFieldType'; import { FieldDisplay } from '@/object-record/record-field/components/FieldDisplay'; import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; import { BooleanFieldInput } from '@/object-record/record-field/meta-types/input/components/BooleanFieldInput'; @@ -96,7 +95,7 @@ export const SettingsDataModelFieldPreview = ({ entityId, isLabelIdentifier, fieldDefinition: { - type: parseFieldType(fieldMetadataItem.type), + type: fieldMetadataItem.type, iconName: 'FieldIcon', fieldMetadataId: fieldMetadataItem.id || '', label: fieldMetadataItem.label, diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/preview/hooks/useFieldPreview.ts b/packages/twenty-front/src/modules/settings/data-model/fields/preview/hooks/useFieldPreview.ts index e42bc0061a60..e5ce19c71bd6 100644 --- a/packages/twenty-front/src/modules/settings/data-model/fields/preview/hooks/useFieldPreview.ts +++ b/packages/twenty-front/src/modules/settings/data-model/fields/preview/hooks/useFieldPreview.ts @@ -2,7 +2,6 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSi import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; import { isLabelIdentifierField } from '@/object-metadata/utils/isLabelIdentifierField'; -import { parseFieldType } from '@/object-metadata/utils/parseFieldType'; import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords'; import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty'; import { SettingsObjectFieldSelectFormValues } from '@/settings/data-model/components/SettingsObjectFieldSelectForm'; @@ -59,7 +58,7 @@ export const useFieldPreview = ({ const isValueFromFirstRecord = firstRecord && !isFieldValueEmpty({ - fieldDefinition: { type: parseFieldType(fieldMetadataItem.type) }, + fieldDefinition: { type: fieldMetadataItem.type }, fieldValue: fieldPreviewValueFromFirstRecord, }); diff --git a/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockColumnDefinitions.ts b/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockColumnDefinitions.ts index 990ed52b1a91..eb8f914a0f94 100644 --- a/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockColumnDefinitions.ts +++ b/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockColumnDefinitions.ts @@ -1,6 +1,7 @@ import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition'; import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns'; +import { FieldMetadataType } from '~/generated-metadata/graphql'; export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( [ @@ -9,7 +10,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-5e4e-4007-a630-8a2617914889', label: 'Domain Name', size: 100, - type: 'TEXT', + type: FieldMetadataType.Text, metadata: { fieldName: 'domainName', placeHolder: 'Domain Name', @@ -25,7 +26,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-7fbd-41ad-b64d-25a15ff62f04', label: 'Employees', size: 100, - type: 'NUMBER', + type: FieldMetadataType.Number, metadata: { fieldName: 'employees', placeHolder: 'Employees', @@ -41,7 +42,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-6d30-4111-9f40-b4301906fd3c', label: 'Name', size: 100, - type: 'TEXT', + type: FieldMetadataType.Text, metadata: { fieldName: 'name', placeHolder: 'Name', @@ -57,7 +58,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-e7c8-4771-8cc4-ce0e8c36a3c0', label: 'Favorites', size: 100, - type: 'RELATION', + type: FieldMetadataType.Relation, metadata: { fieldName: 'favorites', placeHolder: 'Favorites', @@ -74,7 +75,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-ad10-4117-a039-3f04b7a5f939', label: 'Address', size: 100, - type: 'TEXT', + type: FieldMetadataType.Text, metadata: { fieldName: 'address', placeHolder: 'Address', @@ -90,7 +91,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-0739-495d-8e70-c0807f6b2268', label: 'Account Owner', size: 100, - type: 'RELATION', + type: FieldMetadataType.Relation, metadata: { fieldName: 'accountOwner', placeHolder: 'Account Owner', @@ -107,7 +108,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-68b4-4c8e-af19-738eba2a42a5', label: 'People', size: 100, - type: 'RELATION', + type: FieldMetadataType.Relation, metadata: { fieldName: 'people', placeHolder: 'People', @@ -124,7 +125,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-61af-4ffd-b79b-baed6db8ad11', label: 'Attachments', size: 100, - type: 'RELATION', + type: FieldMetadataType.Relation, metadata: { fieldName: 'attachments', placeHolder: 'Attachments', @@ -141,7 +142,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-4dc2-47c9-bb15-6e6f19ba9e46', label: 'Creation date', size: 100, - type: 'DATE_TIME', + type: FieldMetadataType.DateTime, metadata: { fieldName: 'createdAt', placeHolder: 'Creation date', @@ -157,7 +158,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-9e9f-4235-98b2-c76f3e2d281e', label: 'ICP', size: 100, - type: 'BOOLEAN', + type: FieldMetadataType.Boolean, metadata: { fieldName: 'idealCustomerProfile', placeHolder: 'ICP', @@ -173,7 +174,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-a61d-4b78-b998-3fd88b4f73a1', label: 'Linkedin', size: 100, - type: 'LINK', + type: FieldMetadataType.Link, metadata: { fieldName: 'linkedinLink', placeHolder: 'Linkedin', @@ -189,7 +190,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-e3fc-46ff-b552-3e757843f06e', label: 'Opportunities', size: 100, - type: 'RELATION', + type: FieldMetadataType.Relation, metadata: { fieldName: 'opportunities', placeHolder: 'Opportunities', @@ -206,7 +207,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-46e3-479a-b8f4-77137c74daa6', label: 'X', size: 100, - type: 'LINK', + type: FieldMetadataType.Link, metadata: { fieldName: 'xLink', placeHolder: 'X', @@ -222,7 +223,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-4a2e-4b41-8562-279963e8947e', label: 'Activities', size: 100, - type: 'RELATION', + type: FieldMetadataType.Relation, metadata: { fieldName: 'activityTargets', placeHolder: 'Activities', @@ -239,7 +240,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = ( fieldMetadataId: '20202020-4a5a-466f-92d9-c3870d9502a9', label: 'ARR', size: 100, - type: 'CURRENCY', + type: FieldMetadataType.Currency, metadata: { fieldName: 'annualRecurringRevenue', placeHolder: 'ARR',